diff --git a/include/swift/AST/ASTWalker.h b/include/swift/AST/ASTWalker.h index 954b254ab1877..f45f84681616c 100644 --- a/include/swift/AST/ASTWalker.h +++ b/include/swift/AST/ASTWalker.h @@ -25,7 +25,6 @@ class ModuleDecl; class Stmt; class Pattern; class TypeRepr; -class TypeLoc; class ParameterList; enum class AccessKind: unsigned char; @@ -177,19 +176,6 @@ class ASTWalker { /// returns failure. virtual bool walkToDeclPost(Decl *D) { return true; } - /// This method is called when first visiting a TypeLoc, before - /// walking into its TypeRepr children. If it returns false, the subtree is - /// skipped. - /// - /// \param TL The TypeLoc to check. - virtual bool walkToTypeLocPre(TypeLoc &TL) { return true; } - - /// This method is called after visiting the children of a TypeLoc. - /// If it returns false, the remaining traversal is terminated and returns - /// failure. - virtual bool walkToTypeLocPost(TypeLoc &TL) { return true; } - - /// This method is called when first visiting a TypeRepr, before /// walking into its children. If it returns false, the subtree is skipped. /// diff --git a/include/swift/AST/Pattern.h b/include/swift/AST/Pattern.h index 7ec1cc7332b8d..6424dd12a72f2 100644 --- a/include/swift/AST/Pattern.h +++ b/include/swift/AST/Pattern.h @@ -34,7 +34,6 @@ namespace swift { class Expr; enum class CheckedCastKind : unsigned; class TypeExpr; - class TypeLoc; /// PatternKind - The classification of different kinds of /// value-matching pattern. @@ -447,7 +446,6 @@ class TypedPattern : public Pattern { TypeRepr *getTypeRepr() const { return PatTypeRepr; } - TypeLoc getTypeLoc() const; SourceLoc getLoc() const; SourceRange getSourceRange() const; diff --git a/include/swift/IDE/Utils.h b/include/swift/IDE/Utils.h index 6fa05dececa47..f847b188f1b42 100644 --- a/include/swift/IDE/Utils.h +++ b/include/swift/IDE/Utils.h @@ -280,8 +280,6 @@ class NameMatcher: public ASTWalker { bool walkToDeclPost(Decl *D) override; std::pair walkToStmtPre(Stmt *S) override; Stmt* walkToStmtPost(Stmt *S) override; - bool walkToTypeLocPre(TypeLoc &TL) override; - bool walkToTypeLocPost(TypeLoc &TL) override; bool walkToTypeReprPre(TypeRepr *T) override; bool walkToTypeReprPost(TypeRepr *T) override; std::pair walkToPatternPre(Pattern *P) override; diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index 9963cfabd0e7b..196cfa3c95c78 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -1079,7 +1079,9 @@ void PrintAST::printTypedPattern(const TypedPattern *TP) { if (auto decl = named->getDecl()) isIUO = decl->isImplicitlyUnwrappedOptional(); - printTypeLocForImplicitlyUnwrappedOptional(TP->getTypeLoc(), isIUO); + const auto TyLoc = TypeLoc(TP->getTypeRepr(), + TP->hasType() ? TP->getType() : Type()); + printTypeLocForImplicitlyUnwrappedOptional(TyLoc, isIUO); } /// Determines if we are required to print the name of a property declaration, diff --git a/lib/AST/ASTScopeCreation.cpp b/lib/AST/ASTScopeCreation.cpp index 91959110482ed..9ff7082800c01 100644 --- a/lib/AST/ASTScopeCreation.cpp +++ b/lib/AST/ASTScopeCreation.cpp @@ -1781,7 +1781,6 @@ void ScopeCreator::forEachClosureIn( return {false, P}; } bool walkToDeclPre(Decl *D) override { return false; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } bool walkToParameterListPre(ParameterList *PL) override { return false; } }; diff --git a/lib/AST/ASTWalker.cpp b/lib/AST/ASTWalker.cpp index cbb28ba38cf30..f317cf51bd871 100644 --- a/lib/AST/ASTWalker.cpp +++ b/lib/AST/ASTWalker.cpp @@ -155,8 +155,9 @@ class Traversal : public ASTVisitorgetInherited()) { - if (doIt(Inherit)) - return true; + if (auto *const TyR = Inherit.getTypeRepr()) + if (doIt(TyR)) + return true; } if (visitTrailingRequirements(ED)) return true; @@ -258,9 +259,10 @@ class Traversal : public ASTVisitorgetInherited()) { - if (doIt(Inherit)) - return true; + for (const auto &Inherit: TPD->getInherited()) { + if (auto *const TyR = Inherit.getTypeRepr()) + if (doIt(TyR)) + return true; } if (const auto ATD = dyn_cast(TPD)) { @@ -282,9 +284,10 @@ class Traversal : public ASTVisitorgetInherited()) { - if (doIt(Inherit)) - return true; + for (const auto &Inherit : NTD->getInherited()) { + if (auto *const TyR = Inherit.getTypeRepr()) + if (doIt(Inherit.getTypeRepr())) + return true; } // Visit requirements @@ -355,8 +358,9 @@ class Traversal : public ASTVisitorgetIndices()); - if (doIt(SD->getElementTypeLoc())) - return true; + if (auto *const TyR = SD->getElementTypeLoc().getTypeRepr()) + if (doIt(TyR)) + return true; // Visit trailing requirements if (WalkGenerics && visitTrailingRequirements(SD)) @@ -388,10 +392,12 @@ class Traversal : public ASTVisitorgetParameters()); - if (auto *FD = dyn_cast(AFD)) + if (auto *FD = dyn_cast(AFD)) { if (!isa(FD)) - if (doIt(FD->getBodyResultTypeLoc())) - return true; + if (auto *const TyR = FD->getBodyResultTypeLoc().getTypeRepr()) + if (doIt(TyR)) + return true; + } // Visit trailing requirements if (WalkGenerics && visitTrailingRequirements(AFD)) @@ -1319,21 +1325,6 @@ class Traversal : public ASTVisitor callback) { } bool walkToDeclPre(Decl *D) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } }; this->walk(ChildWalker(callback, this)); @@ -453,7 +452,6 @@ void Expr::forEachChildExpr(llvm::function_ref callback) { } bool walkToDeclPre(Decl *D) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } }; this->walk(ChildWalker(callback)); diff --git a/lib/AST/Pattern.cpp b/lib/AST/Pattern.cpp index 1f7cc19a44471..2006c06e62e27 100644 --- a/lib/AST/Pattern.cpp +++ b/lib/AST/Pattern.cpp @@ -187,7 +187,6 @@ namespace { std::pair walkToStmtPre(Stmt *S) override { return { false, S }; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } bool walkToParameterListPre(ParameterList *PL) override { return false; } bool walkToDeclPre(Decl *D) override { return false; } @@ -407,15 +406,6 @@ TypedPattern::TypedPattern(Pattern *pattern, TypeRepr *tr) Bits.TypedPattern.IsPropagatedType = false; } -TypeLoc TypedPattern::getTypeLoc() const { - TypeLoc loc = TypeLoc(PatTypeRepr); - - if (hasType()) - loc.setType(getType()); - - return loc; -} - SourceLoc TypedPattern::getLoc() const { if (SubPattern->isImplicit() && PatTypeRepr) return PatTypeRepr->getSourceRange().Start; diff --git a/lib/IDE/ExprContextAnalysis.cpp b/lib/IDE/ExprContextAnalysis.cpp index 06f3d59a72284..acb2270a2bc70 100644 --- a/lib/IDE/ExprContextAnalysis.cpp +++ b/lib/IDE/ExprContextAnalysis.cpp @@ -177,7 +177,6 @@ class ExprFinder : public ASTWalker { return {isInterstingRange(S), S}; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } }; } // anonymous namespace diff --git a/lib/IDE/SwiftSourceDocInfo.cpp b/lib/IDE/SwiftSourceDocInfo.cpp index a08719d75af83..b372b1cba3e39 100644 --- a/lib/IDE/SwiftSourceDocInfo.cpp +++ b/lib/IDE/SwiftSourceDocInfo.cpp @@ -468,16 +468,6 @@ Expr *NameMatcher::walkToExprPost(Expr *E) { return E; } -bool NameMatcher::walkToTypeLocPre(TypeLoc &TL) { - if (isDone() || shouldSkip(TL.getSourceRange())) - return false; - return true; -} - -bool NameMatcher::walkToTypeLocPost(TypeLoc &TL) { - return !isDone(); -} - bool NameMatcher::walkToTypeReprPre(TypeRepr *T) { if (isDone() || shouldSkip(T->getSourceRange())) return false; diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 5efe06f3ef664..a58f435d8dc1f 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -2467,7 +2467,6 @@ struct FallthroughFinder : ASTWalker { } bool walkToDeclPre(Decl *d) override { return false; } - bool walkToTypeLocPre(TypeLoc &tl) override { return false; } bool walkToTypeReprPre(TypeRepr *t) override { return false; } static FallthroughStmt *findFallthrough(Stmt *s) { diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 0963b7f02663c..d0bd6d86f8d1b 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -158,7 +158,7 @@ namespace { } /// Ignore types. - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } + bool walkToTypeReprPre(TypeRepr *T) override { return false; } }; /// Given a collection of "linked" expressions, analyzes them for @@ -305,7 +305,7 @@ namespace { } /// Ignore types. - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } + bool walkToTypeReprPre(TypeRepr *T) override { return false; } }; /// For a given expression, given information that is global to the diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 134c7165aeaf0..f6bd1ff2e781c 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -4639,8 +4639,10 @@ SolutionApplicationTarget SolutionApplicationTarget::forInitialization( if (auto *typedPattern = dyn_cast(pattern)) { const Pattern *inner = typedPattern->getSemanticsProvidingPattern(); if (isa(inner) || isa(inner)) { - contextualType = typedPattern->getTypeLoc(); - if (!contextualType.getType()) + contextualType = TypeLoc(typedPattern->getTypeRepr()); + if (typedPattern->hasType()) + contextualType.setType(typedPattern->getType()); + else contextualType.setType(patternType); } } diff --git a/lib/Sema/TypeCheckAccess.cpp b/lib/Sema/TypeCheckAccess.cpp index 574358ebff137..a9feb8abb0deb 100644 --- a/lib/Sema/TypeCheckAccess.cpp +++ b/lib/Sema/TypeCheckAccess.cpp @@ -497,7 +497,8 @@ class AccessControlChecker : public AccessControlCheckerBase, if (!anyVar) return; - checkTypeAccess(TP->getTypeLoc(), anyVar, /*mayBeInferred*/true, + checkTypeAccess(TP->hasType() ? TP->getType() : Type(), + TP->getTypeRepr(), anyVar, /*mayBeInferred*/true, [&](AccessScope typeAccessScope, const TypeRepr *complainRepr, DowngradeToWarning downgradeToWarning) { @@ -1117,7 +1118,8 @@ class UsableFromInlineChecker : public AccessControlCheckerBase, return; checkTypeAccess( - TP->getTypeLoc(), + TP->hasType() ? TP->getType() : Type(), + TP->getTypeRepr(), fixedLayoutStructContext ? fixedLayoutStructContext : anyVar, /*mayBeInferred*/ true, [&](AccessScope typeAccessScope, const TypeRepr *complainRepr, @@ -1835,7 +1837,8 @@ class ExportabilityChecker : public DeclVisitor { if (shouldSkipChecking(anyVar)) return; - checkType(TP->getTypeLoc(), anyVar, getDiagnoser(anyVar)); + checkType(TP->hasType() ? TP->getType() : Type(), + TP->getTypeRepr(), anyVar, getDiagnoser(anyVar)); // Check the property wrapper types. for (auto attr : anyVar->getAttachedPropertyWrappers()) diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index a1fb7d85d4568..752a618a528f2 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -2023,7 +2023,6 @@ class FunctionSyntacticDiagnosticWalker : public ASTWalker { return {false, pattern}; } - bool walkToTypeLocPre(TypeLoc &typeLoc) override { return false; } bool walkToTypeReprPre(TypeRepr *typeRepr) override { return false; } bool walkToParameterListPre(ParameterList *params) override { return false; } }; @@ -4004,7 +4003,6 @@ void swift::forEachExprInConstraintSystem( } bool walkToDeclPre(Decl *D) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } }; expr->walk(ChildWalker(callback)); diff --git a/lib/Serialization/SerializeDoc.cpp b/lib/Serialization/SerializeDoc.cpp index 994961d7c3b6b..721a830c6a290 100644 --- a/lib/Serialization/SerializeDoc.cpp +++ b/lib/Serialization/SerializeDoc.cpp @@ -447,7 +447,6 @@ static void writeDeclCommentTable( return { false, E }; } - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } bool walkToParameterListPre(ParameterList *PL) override { return false; } }; @@ -685,7 +684,6 @@ struct BasicDeclLocsTableWriter : public ASTWalker { std::pair walkToStmtPre(Stmt *S) override { return { false, S };} std::pair walkToExprPre(Expr *E) override { return { false, E };} - bool walkToTypeLocPre(TypeLoc &TL) override { return false; } bool walkToTypeReprPre(TypeRepr *T) override { return false; } bool walkToParameterListPre(ParameterList *PL) override { return false; }