From b603a5e9a04b2f38da496ff6f12c11239aee9225 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Thu, 23 Nov 2023 11:41:21 -0800 Subject: [PATCH] [Sema] Remove `LeaveClosureBodiesUnchecked` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This shouldn’t be needed anymore since we migrated code completion to be solver-based. rdar://91403086 --- include/swift/AST/Decl.h | 4 +-- include/swift/AST/TypeCheckRequests.h | 7 ++-- include/swift/AST/TypeCheckerTypeIDZone.def | 2 +- include/swift/Sema/ConstraintSystem.h | 18 ++++------ include/swift/Sema/IDETypeChecking.h | 3 +- lib/AST/Decl.cpp | 10 +++--- lib/IDE/PostfixCompletion.cpp | 3 +- lib/Sema/BuilderTransform.cpp | 3 +- lib/Sema/CSApply.cpp | 7 ++-- lib/Sema/CSSimplify.cpp | 3 +- lib/Sema/CSSyntacticElement.cpp | 6 ++-- lib/Sema/ConstraintSystem.cpp | 3 -- lib/Sema/PreCheckExpr.cpp | 39 ++++++--------------- lib/Sema/TypeCheckCodeCompletion.cpp | 14 ++------ lib/Sema/TypeCheckConstraints.cpp | 6 +--- lib/Sema/TypeCheckDeclPrimary.cpp | 17 +++------ lib/Sema/TypeCheckStmt.cpp | 14 ++------ lib/Sema/TypeCheckStorage.cpp | 11 ++---- lib/Sema/TypeChecker.cpp | 9 ++--- lib/Sema/TypeChecker.h | 11 ++---- 20 files changed, 51 insertions(+), 139 deletions(-) diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index f90c3912f80..f5526d8f118 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -2212,9 +2212,7 @@ public: } /// Returns the typechecked binding entry at the given index. - const PatternBindingEntry * - getCheckedPatternBindingEntry(unsigned i, - bool leaveClosureBodiesUnchecked = false) const; + const PatternBindingEntry *getCheckedPatternBindingEntry(unsigned i) const; /// Clean up walking the initializers for the pattern class InitIterator { diff --git a/include/swift/AST/TypeCheckRequests.h b/include/swift/AST/TypeCheckRequests.h index 44e149fcb74..1cbf15e66fa 100644 --- a/include/swift/AST/TypeCheckRequests.h +++ b/include/swift/AST/TypeCheckRequests.h @@ -2327,7 +2327,7 @@ public: class PatternBindingEntryRequest : public SimpleRequest { public: using SimpleRequest::SimpleRequest; @@ -2336,9 +2336,8 @@ private: friend SimpleRequest; // Evaluation. - const PatternBindingEntry *evaluate(Evaluator &evaluator, - PatternBindingDecl *PBD, unsigned i, - bool LeaveClosureBodiesUnchecked) const; + const PatternBindingEntry * + evaluate(Evaluator &evaluator, PatternBindingDecl *PBD, unsigned i) const; public: // Separate caching. diff --git a/include/swift/AST/TypeCheckerTypeIDZone.def b/include/swift/AST/TypeCheckerTypeIDZone.def index b3cc83ef6d0..5b50b973b5e 100644 --- a/include/swift/AST/TypeCheckerTypeIDZone.def +++ b/include/swift/AST/TypeCheckerTypeIDZone.def @@ -256,7 +256,7 @@ SWIFT_REQUEST(TypeChecker, OverriddenDeclsRequest, llvm::TinyPtrVector(ValueDecl *), SeparatelyCached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, PatternBindingEntryRequest, - const PatternBindingEntry *(PatternBindingDecl *, unsigned, bool), + const PatternBindingEntry *(PatternBindingDecl *, unsigned), SeparatelyCached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, PatternBindingCheckedAndContextualizedInitRequest, Expr *(PatternBindingDecl *, unsigned), diff --git a/include/swift/Sema/ConstraintSystem.h b/include/swift/Sema/ConstraintSystem.h index b6ddbf3eb8d..19325aa253a 100644 --- a/include/swift/Sema/ConstraintSystem.h +++ b/include/swift/Sema/ConstraintSystem.h @@ -1806,14 +1806,10 @@ enum class ConstraintSystemFlags { /// \c DebugConstraintSolverOnLines. DebugConstraints = 0x08, - /// Don't try to type check closure bodies, and leave them unchecked. This is - /// used for source tooling functionalities. - LeaveClosureBodyUnchecked = 0x10, - /// If set, we are solving specifically to determine the type of a /// CodeCompletionExpr, and should continue in the presence of errors wherever /// possible. - ForCodeCompletion = 0x20, + ForCodeCompletion = 0x10, /// Include Clang function types when checking equality for function types. /// @@ -1824,13 +1820,13 @@ enum class ConstraintSystemFlags { /// should be treated as semantically different, as they may have different /// calling conventions, say due to Clang attributes such as /// `__attribute__((ns_consumed))`. - UseClangFunctionTypes = 0x40, + UseClangFunctionTypes = 0x20, /// When set, ignore async/sync mismatches - IgnoreAsyncSyncMismatch = 0x80, + IgnoreAsyncSyncMismatch = 0x40, /// Disable macro expansions. - DisableMacroExpansions = 0x100, + DisableMacroExpansions = 0x80, }; /// Options that affect the constraint system as a whole. @@ -5210,8 +5206,7 @@ public: /// \param replaceInvalidRefsWithErrors Indicates whether it's allowed /// to replace any discovered invalid member references with `ErrorExpr`. static bool preCheckTarget(SyntacticElementTarget &target, - bool replaceInvalidRefsWithErrors, - bool leaveClosureBodiesUnchecked); + bool replaceInvalidRefsWithErrors); /// Pre-check the expression, validating any types that occur in the /// expression and folding sequence expressions. @@ -5219,8 +5214,7 @@ public: /// \param replaceInvalidRefsWithErrors Indicates whether it's allowed /// to replace any discovered invalid member references with `ErrorExpr`. static bool preCheckExpression(Expr *&expr, DeclContext *dc, - bool replaceInvalidRefsWithErrors, - bool leaveClosureBodiesUnchecked); + bool replaceInvalidRefsWithErrors); /// Solve the system of constraints generated from provided target. /// diff --git a/include/swift/Sema/IDETypeChecking.h b/include/swift/Sema/IDETypeChecking.h index 7fffd10b445..7e4fca43001 100644 --- a/include/swift/Sema/IDETypeChecking.h +++ b/include/swift/Sema/IDETypeChecking.h @@ -58,8 +58,7 @@ namespace swift { } /// Typecheck binding initializer at \p bindingIndex. - void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex, - bool leaveClosureBodiesUnchecked); + void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex); /// Check if T1 is convertible to T2. /// diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 0cd1fa94d7e..b22f4af9214 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2220,12 +2220,11 @@ bool PatternBindingDecl::hasStorage() const { return false; } -const PatternBindingEntry *PatternBindingDecl::getCheckedPatternBindingEntry( - unsigned i, bool leaveClosureBodiesUnchecked) const { +const PatternBindingEntry * +PatternBindingDecl::getCheckedPatternBindingEntry(unsigned i) const { return evaluateOrDefault( getASTContext().evaluator, - PatternBindingEntryRequest{const_cast(this), i, - leaveClosureBodiesUnchecked}, + PatternBindingEntryRequest{const_cast(this), i}, nullptr); } @@ -2428,8 +2427,7 @@ bool PatternBindingDecl::isComputingPatternBindingEntry( const VarDecl *vd) const { unsigned i = getPatternEntryIndexForVarDecl(vd); return getASTContext().evaluator.hasActiveRequest( - PatternBindingEntryRequest{const_cast(this), i, - /*LeaveClosureBodyUnchecked=*/false}); + PatternBindingEntryRequest{const_cast(this), i}); } bool PatternBindingDecl::isExplicitlyInitialized(unsigned i) const { diff --git a/lib/IDE/PostfixCompletion.cpp b/lib/IDE/PostfixCompletion.cpp index f4ee4bf52eb..1711d7ca114 100644 --- a/lib/IDE/PostfixCompletion.cpp +++ b/lib/IDE/PostfixCompletion.cpp @@ -328,8 +328,7 @@ getOperatorCompletionTypes(DeclContext *DC, Type LHSType, OperatorDecl *Op) { llvm_unreachable("unexpected operator kind"); } - CS.preCheckExpression(OpCallExpr, DC, /*replaceInvalidRefsWithErrors=*/true, - /*leaveClosureBodyUnchecked=*/false); + CS.preCheckExpression(OpCallExpr, DC, /*replaceInvalidRefsWithErrors=*/true); OpCallExpr = CS.generateConstraints(OpCallExpr, DC); CS.assignFixedType(CS.getType(&LHS)->getAs(), LHSType); diff --git a/lib/Sema/BuilderTransform.cpp b/lib/Sema/BuilderTransform.cpp index 1784bb08b4f..3979747b668 100644 --- a/lib/Sema/BuilderTransform.cpp +++ b/lib/Sema/BuilderTransform.cpp @@ -1310,8 +1310,7 @@ public: DiagnosticTransaction transaction(diagEngine); HasError |= ConstraintSystem::preCheckExpression( - E, DC, /*replaceInvalidRefsWithErrors=*/true, - /*leaveClosureBodiesUnchecked=*/false); + E, DC, /*replaceInvalidRefsWithErrors=*/true); HasError |= transaction.hasErrors(); diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 64462ed173d..a2c8939a502 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -8749,11 +8749,8 @@ namespace { return true; case SolutionApplicationToFunctionResult::Delay: { - if (!Rewriter.cs.Options - .contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked)) { - auto closure = cast(fn.getAbstractClosureExpr()); - ClosuresToTypeCheck.push_back(closure); - } + auto closure = cast(fn.getAbstractClosureExpr()); + ClosuresToTypeCheck.push_back(closure); return false; } } diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index f8e22a617f5..cc604181116 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -10514,8 +10514,7 @@ static bool inferEnumMemberThroughTildeEqualsOperator( DiagnosticTransaction diagnostics(ctx.Diags); { - if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true, - /*leaveClosureBodyUnchecked=*/false)) { + if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) { // Skip diagnostics if they are disabled, otherwise it would result in // duplicate diagnostics, since this operation is going to be repeated // in diagnostic mode. diff --git a/lib/Sema/CSSyntacticElement.cpp b/lib/Sema/CSSyntacticElement.cpp index f71f2a3910d..b33ae0a39ae 100644 --- a/lib/Sema/CSSyntacticElement.cpp +++ b/lib/Sema/CSSyntacticElement.cpp @@ -539,8 +539,7 @@ public: void visitExprPattern(ExprPattern *EP) { auto target = SyntacticElementTarget::forExprPattern(EP); - if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true, - /*leaveClosureBodyUnchecked=*/false)) { + if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) { hadError = true; return; } @@ -757,8 +756,7 @@ private: /*bindPatternVarsOneWay=*/false); if (ConstraintSystem::preCheckTarget( - target, /*replaceInvalidRefsWithErrors=*/true, - /*LeaveCLosureBodyUnchecked=*/false)) + target, /*replaceInvalidRefsWithErrors=*/true)) return llvm::None; return target; diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 6c79f35ddfe..97e5707a7f8 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -7407,9 +7407,6 @@ bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const { if (getAppliedResultBuilderTransform(closure)) return true; - if (Options.contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked)) - return false; - if (closure->hasEmptyBody()) return false; diff --git a/lib/Sema/PreCheckExpr.cpp b/lib/Sema/PreCheckExpr.cpp index 9f23b33598c..f48965fa259 100644 --- a/lib/Sema/PreCheckExpr.cpp +++ b/lib/Sema/PreCheckExpr.cpp @@ -939,8 +939,6 @@ namespace { /// implicit `ErrorExpr` in place of invalid references. bool UseErrorExprs; - bool LeaveClosureBodiesUnchecked; - /// A stack of expressions being walked, used to determine where to /// insert RebindSelfInConstructorExpr nodes. llvm::SmallVector ExprStack; @@ -1009,11 +1007,9 @@ namespace { public: PreCheckExpression(DeclContext *dc, Expr *parent, - bool replaceInvalidRefsWithErrors, - bool leaveClosureBodiesUnchecked) - : Ctx(dc->getASTContext()), DC(dc), - ParentExpr(parent), UseErrorExprs(replaceInvalidRefsWithErrors), - LeaveClosureBodiesUnchecked(leaveClosureBodiesUnchecked) {} + bool replaceInvalidRefsWithErrors) + : Ctx(dc->getASTContext()), DC(dc), ParentExpr(parent), + UseErrorExprs(replaceInvalidRefsWithErrors) {} ASTContext &getASTContext() const { return Ctx; } @@ -1394,9 +1390,7 @@ namespace { /// true when we want the body to be considered part of this larger expression. bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) { // If we have a single statement that can become an expression, turn it - // into an expression now. This needs to happen before we check - // LeaveClosureBodiesUnchecked, as the closure may become a single expression - // closure. + // into an expression now. auto *body = closure->getBody(); if (auto *S = body->getSingleActiveStatement()) { if (S->mayProduceSingleValue(Ctx)) { @@ -1408,12 +1402,6 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) { } } - // If we won't be checking the body of the closure, don't walk into it here. - if (!closure->hasSingleExpressionBody()) { - if (LeaveClosureBodiesUnchecked) - return false; - } - // Update the current DeclContext to be the closure we're about to // recurse into. assert((closure->getParent() == DC || @@ -2310,15 +2298,13 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) { } bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target, - bool replaceInvalidRefsWithErrors, - bool leaveClosureBodiesUnchecked) { + bool replaceInvalidRefsWithErrors) { auto *DC = target.getDeclContext(); bool hadErrors = false; if (auto *expr = target.getAsExpr()) { - hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors, - leaveClosureBodiesUnchecked); + hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors); // Even if the pre-check fails, expression still has to be re-set. target.setExpr(expr); } @@ -2330,13 +2316,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target, auto *whereExpr = stmt->getWhere(); hadErrors |= preCheckExpression(sequenceExpr, DC, - /*replaceInvalidRefsWithErrors=*/true, - /*leaveClosureBodiesUnchecked=*/false); + /*replaceInvalidRefsWithErrors=*/true); if (whereExpr) { hadErrors |= preCheckExpression(whereExpr, DC, - /*replaceInvalidRefsWithErrors=*/true, - /*leaveClosureBodiesUnchecked=*/false); + /*replaceInvalidRefsWithErrors=*/true); } // Update sequence and where expressions to pre-checked versions. @@ -2354,14 +2338,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target, /// Pre-check the expression, validating any types that occur in the /// expression and folding sequence expressions. bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc, - bool replaceInvalidRefsWithErrors, - bool leaveClosureBodiesUnchecked) { + bool replaceInvalidRefsWithErrors) { auto &ctx = dc->getASTContext(); FrontendStatsTracer StatsTracer(ctx.Stats, "precheck-expr", expr); - PreCheckExpression preCheck(dc, expr, - replaceInvalidRefsWithErrors, - leaveClosureBodiesUnchecked); + PreCheckExpression preCheck(dc, expr, replaceInvalidRefsWithErrors); // Perform the pre-check. if (auto result = expr->walk(preCheck)) { diff --git a/lib/Sema/TypeCheckCodeCompletion.cpp b/lib/Sema/TypeCheckCodeCompletion.cpp index 0c0f0277be4..09264922e77 100644 --- a/lib/Sema/TypeCheckCodeCompletion.cpp +++ b/lib/Sema/TypeCheckCodeCompletion.cpp @@ -77,9 +77,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc, ConstraintSystemOptions options; options |= ConstraintSystemFlags::SuppressDiagnostics; - if (!Context.CompletionCallback) { - options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked; - } // Construct a constraint system from this expression. ConstraintSystem cs(dc, options); @@ -223,8 +220,7 @@ bool TypeChecker::typeCheckForCodeCompletion( // expression and folding sequence expressions. auto failedPreCheck = ConstraintSystem::preCheckTarget(target, - /*replaceInvalidRefsWithErrors=*/true, - /*leaveClosureBodiesUnchecked=*/true); + /*replaceInvalidRefsWithErrors=*/true); if (failedPreCheck) return false; @@ -238,10 +234,7 @@ bool TypeChecker::typeCheckForCodeCompletion( options |= ConstraintSystemFlags::AllowFixes; options |= ConstraintSystemFlags::SuppressDiagnostics; options |= ConstraintSystemFlags::ForCodeCompletion; - if (!Context.CompletionCallback) { - options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked; - } - + ConstraintSystem cs(DC, options); llvm::SmallVector solutions; @@ -309,8 +302,7 @@ getTypeOfCompletionContextExpr(DeclContext *DC, CompletionTypeCheckKind kind, ConcreteDeclRef &referencedDecl) { if (constraints::ConstraintSystem::preCheckExpression( parsedExpr, DC, - /*replaceInvalidRefsWithErrors=*/true, - /*leaveClosureBodiesUnchecked=*/true)) + /*replaceInvalidRefsWithErrors=*/true)) return llvm::None; switch (kind) { diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index 14b539565b7..8546ba71b51 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -448,8 +448,7 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target, // First, pre-check the target, validating any types that occur in the // expression and folding sequence expressions. if (ConstraintSystem::preCheckTarget( - target, /*replaceInvalidRefsWithErrors=*/true, - options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))) { + target, /*replaceInvalidRefsWithErrors=*/true)) { return llvm::None; } @@ -468,9 +467,6 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target, if (DiagnosticSuppression::isEnabled(Context.Diags)) csOptions |= ConstraintSystemFlags::SuppressDiagnostics; - if (options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked)) - csOptions |= ConstraintSystemFlags::LeaveClosureBodyUnchecked; - if (options.contains(TypeCheckExprFlags::DisableMacroExpansions)) csOptions |= ConstraintSystemFlags::DisableMacroExpansions; diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index a4c54d098db..f41f3b69959 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -2056,12 +2056,7 @@ public: ASTContext &Ctx; SourceFile *SF; - bool LeaveClosureBodiesUnchecked; - - explicit DeclChecker(ASTContext &ctx, SourceFile *SF, - bool LeaveClosureBodiesUnchecked = false) - : Ctx(ctx), SF(SF), - LeaveClosureBodiesUnchecked(LeaveClosureBodiesUnchecked) {} + explicit DeclChecker(ASTContext &ctx, SourceFile *SF) : Ctx(ctx), SF(SF) {} ASTContext &getASTContext() const { return Ctx; } void addDelayedFunction(AbstractFunctionDecl *AFD) { @@ -2513,8 +2508,7 @@ public: for (auto i : range(PBD->getNumPatternEntries())) { const auto *entry = PBD->isFullyValidated(i) ? &PBD->getPatternList()[i] - : PBD->getCheckedPatternBindingEntry( - i, LeaveClosureBodiesUnchecked); + : PBD->getCheckedPatternBindingEntry(i); assert(entry && "No pattern binding entry?"); const auto *Pat = PBD->getPattern(i); @@ -2640,9 +2634,6 @@ public: if (!PBD->isInitializerChecked(i)) { TypeCheckExprOptions options; - if (LeaveClosureBodiesUnchecked) - options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked; - TypeChecker::typeCheckPatternBinding(PBD, i, /*patternType=*/Type(), options); } @@ -4113,9 +4104,9 @@ public: }; } // end anonymous namespace -void TypeChecker::typeCheckDecl(Decl *D, bool LeaveClosureBodiesUnchecked) { +void TypeChecker::typeCheckDecl(Decl *D) { auto *SF = D->getDeclContext()->getParentSourceFile(); - DeclChecker(D->getASTContext(), SF, LeaveClosureBodiesUnchecked).visit(D); + DeclChecker(D->getASTContext(), SF).visit(D); } void TypeChecker::checkParameterList(ParameterList *params, diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp index 5a4241cfbe6..43a65d7b9e5 100644 --- a/lib/Sema/TypeCheckStmt.cpp +++ b/lib/Sema/TypeCheckStmt.cpp @@ -1090,12 +1090,6 @@ public: Expr *E = RS->getResult(); TypeCheckExprOptions options = {}; - if (LeaveBraceStmtBodyUnchecked) { - assert(DiagnosticSuppression::isEnabled(getASTContext().Diags) && - "Diagnosing and AllowUnresolvedTypeVariables don't seem to mix"); - options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked; - } - ContextualTypePurpose ctp = CTP_ReturnStmt; if (auto func = dyn_cast_or_null(TheFunc->getAbstractFunctionDecl())) { @@ -2047,9 +2041,6 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) { (!ctx.LangOpts.Playground && !ctx.LangOpts.DebuggerSupport); if (isDiscarded) options |= TypeCheckExprFlags::IsDiscarded; - if (LeaveBraceStmtBodyUnchecked) { - options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked; - } auto resultTy = TypeChecker::typeCheckExpression(E, DC, /*contextualInfo=*/{}, options); @@ -2087,7 +2078,7 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) { // Type check the declaration. if (auto *D = node.dyn_cast()) { - TypeChecker::typeCheckDecl(D, LeaveBraceStmtBodyUnchecked); + TypeChecker::typeCheckDecl(D); return; } @@ -2396,8 +2387,7 @@ bool TypeCheckASTNodeAtLocRequest::evaluate( [](VarDecl *VD) { (void)VD->getInterfaceType(); }); if (auto Init = PBD->getInit(i)) { if (!PBD->isInitializerChecked(i)) { - typeCheckPatternBinding(PBD, i, - /*LeaveClosureBodyUnchecked=*/false); + typeCheckPatternBinding(PBD, i); // Retrieve the accessor's body to trigger RecontextualizeClosures // This is important to get the correct USR of variables defined // in closures initializing lazy variables. diff --git a/lib/Sema/TypeCheckStorage.cpp b/lib/Sema/TypeCheckStorage.cpp index 841666e739b..64ae53d75da 100644 --- a/lib/Sema/TypeCheckStorage.cpp +++ b/lib/Sema/TypeCheckStorage.cpp @@ -397,8 +397,7 @@ MemberwiseInitPropertiesRequest::evaluate(Evaluator &evaluator, /// Validate the \c entryNumber'th entry in \c binding. const PatternBindingEntry *PatternBindingEntryRequest::evaluate( - Evaluator &eval, PatternBindingDecl *binding, unsigned entryNumber, - bool LeaveClosureBodiesUnchecked) const { + Evaluator &eval, PatternBindingDecl *binding, unsigned entryNumber) const { const auto &pbe = binding->getPatternList()[entryNumber]; auto &Context = binding->getASTContext(); @@ -513,12 +512,8 @@ const PatternBindingEntry *PatternBindingEntryRequest::evaluate( if (patternType->hasUnresolvedType() || patternType->hasPlaceholder() || patternType->hasUnboundGenericType()) { - TypeCheckExprOptions options; - if (LeaveClosureBodiesUnchecked) { - options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked; - } - if (TypeChecker::typeCheckPatternBinding(binding, entryNumber, patternType, - options)) { + if (TypeChecker::typeCheckPatternBinding(binding, entryNumber, + patternType)) { binding->setInvalid(); return &pbe; } diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index 03619859cb5..6e1972b8228 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -518,20 +518,15 @@ swift::handleSILGenericParams(GenericParamList *genericParams, } void swift::typeCheckPatternBinding(PatternBindingDecl *PBD, - unsigned bindingIndex, - bool leaveClosureBodiesUnchecked) { + unsigned bindingIndex) { assert(!PBD->isInitializerChecked(bindingIndex) && PBD->getInit(bindingIndex)); auto &Ctx = PBD->getASTContext(); DiagnosticSuppression suppression(Ctx.Diags); - TypeCheckExprOptions options; - if (leaveClosureBodiesUnchecked) - options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked; - TypeChecker::typeCheckPatternBinding(PBD, bindingIndex, - /*patternType=*/Type(), options); + /*patternType=*/Type()); } bool swift::typeCheckASTNodeAtLoc(TypeCheckASTNodeAtLocContext TypeCheckCtx, diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h index 5c288353363..cafe4ae628a 100644 --- a/lib/Sema/TypeChecker.h +++ b/lib/Sema/TypeChecker.h @@ -131,16 +131,11 @@ enum class TypeCheckExprFlags { /// not affect type checking itself. IsExprStmt = 0x02, - /// Don't try to type check closure expression bodies, and leave them - /// unchecked. This is used by source tooling functionalities such as code - /// completion. - LeaveClosureBodyUnchecked = 0x04, - /// Don't type check expressions for correct availability. - DisableExprAvailabilityChecking = 0x08, + DisableExprAvailabilityChecking = 0x04, /// Don't expand macros. - DisableMacroExpansions = 0x10, + DisableMacroExpansions = 0x08, }; using TypeCheckExprOptions = OptionSet; @@ -474,7 +469,7 @@ Type typeCheckParameterDefault(Expr *&defaultValue, DeclContext *DC, void typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD); -void typeCheckDecl(Decl *D, bool LeaveClosureBodiesUnchecked = false); +void typeCheckDecl(Decl *D); void addImplicitDynamicAttribute(Decl *D); void checkDeclAttributes(Decl *D);