Skip to content

Commit b603a5e

Browse files
committed
[Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based. rdar://91403086
1 parent 9b10ab3 commit b603a5e

20 files changed

+51
-139
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,9 +2212,7 @@ class PatternBindingDecl final : public Decl,
22122212
}
22132213

22142214
/// Returns the typechecked binding entry at the given index.
2215-
const PatternBindingEntry *
2216-
getCheckedPatternBindingEntry(unsigned i,
2217-
bool leaveClosureBodiesUnchecked = false) const;
2215+
const PatternBindingEntry *getCheckedPatternBindingEntry(unsigned i) const;
22182216

22192217
/// Clean up walking the initializers for the pattern
22202218
class InitIterator {

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,7 @@ class ResultTypeRequest
23272327
class PatternBindingEntryRequest
23282328
: public SimpleRequest<PatternBindingEntryRequest,
23292329
const PatternBindingEntry *(PatternBindingDecl *,
2330-
unsigned, bool),
2330+
unsigned),
23312331
RequestFlags::SeparatelyCached> {
23322332
public:
23332333
using SimpleRequest::SimpleRequest;
@@ -2336,9 +2336,8 @@ class PatternBindingEntryRequest
23362336
friend SimpleRequest;
23372337

23382338
// Evaluation.
2339-
const PatternBindingEntry *evaluate(Evaluator &evaluator,
2340-
PatternBindingDecl *PBD, unsigned i,
2341-
bool LeaveClosureBodiesUnchecked) const;
2339+
const PatternBindingEntry *
2340+
evaluate(Evaluator &evaluator, PatternBindingDecl *PBD, unsigned i) const;
23422341

23432342
public:
23442343
// Separate caching.

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ SWIFT_REQUEST(TypeChecker, OverriddenDeclsRequest,
256256
llvm::TinyPtrVector<ValueDecl *>(ValueDecl *), SeparatelyCached,
257257
NoLocationInfo)
258258
SWIFT_REQUEST(TypeChecker, PatternBindingEntryRequest,
259-
const PatternBindingEntry *(PatternBindingDecl *, unsigned, bool),
259+
const PatternBindingEntry *(PatternBindingDecl *, unsigned),
260260
SeparatelyCached, NoLocationInfo)
261261
SWIFT_REQUEST(TypeChecker, PatternBindingCheckedAndContextualizedInitRequest,
262262
Expr *(PatternBindingDecl *, unsigned),

include/swift/Sema/ConstraintSystem.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,14 +1806,10 @@ enum class ConstraintSystemFlags {
18061806
/// \c DebugConstraintSolverOnLines.
18071807
DebugConstraints = 0x08,
18081808

1809-
/// Don't try to type check closure bodies, and leave them unchecked. This is
1810-
/// used for source tooling functionalities.
1811-
LeaveClosureBodyUnchecked = 0x10,
1812-
18131809
/// If set, we are solving specifically to determine the type of a
18141810
/// CodeCompletionExpr, and should continue in the presence of errors wherever
18151811
/// possible.
1816-
ForCodeCompletion = 0x20,
1812+
ForCodeCompletion = 0x10,
18171813

18181814
/// Include Clang function types when checking equality for function types.
18191815
///
@@ -1824,13 +1820,13 @@ enum class ConstraintSystemFlags {
18241820
/// should be treated as semantically different, as they may have different
18251821
/// calling conventions, say due to Clang attributes such as
18261822
/// `__attribute__((ns_consumed))`.
1827-
UseClangFunctionTypes = 0x40,
1823+
UseClangFunctionTypes = 0x20,
18281824

18291825
/// When set, ignore async/sync mismatches
1830-
IgnoreAsyncSyncMismatch = 0x80,
1826+
IgnoreAsyncSyncMismatch = 0x40,
18311827

18321828
/// Disable macro expansions.
1833-
DisableMacroExpansions = 0x100,
1829+
DisableMacroExpansions = 0x80,
18341830
};
18351831

18361832
/// Options that affect the constraint system as a whole.
@@ -5210,17 +5206,15 @@ class ConstraintSystem {
52105206
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
52115207
/// to replace any discovered invalid member references with `ErrorExpr`.
52125208
static bool preCheckTarget(SyntacticElementTarget &target,
5213-
bool replaceInvalidRefsWithErrors,
5214-
bool leaveClosureBodiesUnchecked);
5209+
bool replaceInvalidRefsWithErrors);
52155210

52165211
/// Pre-check the expression, validating any types that occur in the
52175212
/// expression and folding sequence expressions.
52185213
///
52195214
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
52205215
/// to replace any discovered invalid member references with `ErrorExpr`.
52215216
static bool preCheckExpression(Expr *&expr, DeclContext *dc,
5222-
bool replaceInvalidRefsWithErrors,
5223-
bool leaveClosureBodiesUnchecked);
5217+
bool replaceInvalidRefsWithErrors);
52245218

52255219
/// Solve the system of constraints generated from provided target.
52265220
///

include/swift/Sema/IDETypeChecking.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ namespace swift {
5858
}
5959

6060
/// Typecheck binding initializer at \p bindingIndex.
61-
void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex,
62-
bool leaveClosureBodiesUnchecked);
61+
void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex);
6362

6463
/// Check if T1 is convertible to T2.
6564
///

lib/AST/Decl.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,12 +2220,11 @@ bool PatternBindingDecl::hasStorage() const {
22202220
return false;
22212221
}
22222222

2223-
const PatternBindingEntry *PatternBindingDecl::getCheckedPatternBindingEntry(
2224-
unsigned i, bool leaveClosureBodiesUnchecked) const {
2223+
const PatternBindingEntry *
2224+
PatternBindingDecl::getCheckedPatternBindingEntry(unsigned i) const {
22252225
return evaluateOrDefault(
22262226
getASTContext().evaluator,
2227-
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i,
2228-
leaveClosureBodiesUnchecked},
2227+
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i},
22292228
nullptr);
22302229
}
22312230

@@ -2428,8 +2427,7 @@ bool PatternBindingDecl::isComputingPatternBindingEntry(
24282427
const VarDecl *vd) const {
24292428
unsigned i = getPatternEntryIndexForVarDecl(vd);
24302429
return getASTContext().evaluator.hasActiveRequest(
2431-
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i,
2432-
/*LeaveClosureBodyUnchecked=*/false});
2430+
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i});
24332431
}
24342432

24352433
bool PatternBindingDecl::isExplicitlyInitialized(unsigned i) const {

lib/IDE/PostfixCompletion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ getOperatorCompletionTypes(DeclContext *DC, Type LHSType, OperatorDecl *Op) {
328328
llvm_unreachable("unexpected operator kind");
329329
}
330330

331-
CS.preCheckExpression(OpCallExpr, DC, /*replaceInvalidRefsWithErrors=*/true,
332-
/*leaveClosureBodyUnchecked=*/false);
331+
CS.preCheckExpression(OpCallExpr, DC, /*replaceInvalidRefsWithErrors=*/true);
333332
OpCallExpr = CS.generateConstraints(OpCallExpr, DC);
334333

335334
CS.assignFixedType(CS.getType(&LHS)->getAs<TypeVariableType>(), LHSType);

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,7 @@ class PreCheckResultBuilderApplication : public ASTWalker {
13101310
DiagnosticTransaction transaction(diagEngine);
13111311

13121312
HasError |= ConstraintSystem::preCheckExpression(
1313-
E, DC, /*replaceInvalidRefsWithErrors=*/true,
1314-
/*leaveClosureBodiesUnchecked=*/false);
1313+
E, DC, /*replaceInvalidRefsWithErrors=*/true);
13151314

13161315
HasError |= transaction.hasErrors();
13171316

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8749,11 +8749,8 @@ namespace {
87498749
return true;
87508750

87518751
case SolutionApplicationToFunctionResult::Delay: {
8752-
if (!Rewriter.cs.Options
8753-
.contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked)) {
8754-
auto closure = cast<ClosureExpr>(fn.getAbstractClosureExpr());
8755-
ClosuresToTypeCheck.push_back(closure);
8756-
}
8752+
auto closure = cast<ClosureExpr>(fn.getAbstractClosureExpr());
8753+
ClosuresToTypeCheck.push_back(closure);
87578754
return false;
87588755
}
87598756
}

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10514,8 +10514,7 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
1051410514

1051510515
DiagnosticTransaction diagnostics(ctx.Diags);
1051610516
{
10517-
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true,
10518-
/*leaveClosureBodyUnchecked=*/false)) {
10517+
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) {
1051910518
// Skip diagnostics if they are disabled, otherwise it would result in
1052010519
// duplicate diagnostics, since this operation is going to be repeated
1052110520
// in diagnostic mode.

lib/Sema/CSSyntacticElement.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,7 @@ class SyntacticElementConstraintGenerator
539539
void visitExprPattern(ExprPattern *EP) {
540540
auto target = SyntacticElementTarget::forExprPattern(EP);
541541

542-
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true,
543-
/*leaveClosureBodyUnchecked=*/false)) {
542+
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) {
544543
hadError = true;
545544
return;
546545
}
@@ -757,8 +756,7 @@ class SyntacticElementConstraintGenerator
757756
/*bindPatternVarsOneWay=*/false);
758757

759758
if (ConstraintSystem::preCheckTarget(
760-
target, /*replaceInvalidRefsWithErrors=*/true,
761-
/*LeaveCLosureBodyUnchecked=*/false))
759+
target, /*replaceInvalidRefsWithErrors=*/true))
762760
return llvm::None;
763761

764762
return target;

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7407,9 +7407,6 @@ bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const {
74077407
if (getAppliedResultBuilderTransform(closure))
74087408
return true;
74097409

7410-
if (Options.contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked))
7411-
return false;
7412-
74137410
if (closure->hasEmptyBody())
74147411
return false;
74157412

lib/Sema/PreCheckExpr.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,6 @@ namespace {
939939
/// implicit `ErrorExpr` in place of invalid references.
940940
bool UseErrorExprs;
941941

942-
bool LeaveClosureBodiesUnchecked;
943-
944942
/// A stack of expressions being walked, used to determine where to
945943
/// insert RebindSelfInConstructorExpr nodes.
946944
llvm::SmallVector<Expr *, 8> ExprStack;
@@ -1009,11 +1007,9 @@ namespace {
10091007

10101008
public:
10111009
PreCheckExpression(DeclContext *dc, Expr *parent,
1012-
bool replaceInvalidRefsWithErrors,
1013-
bool leaveClosureBodiesUnchecked)
1014-
: Ctx(dc->getASTContext()), DC(dc),
1015-
ParentExpr(parent), UseErrorExprs(replaceInvalidRefsWithErrors),
1016-
LeaveClosureBodiesUnchecked(leaveClosureBodiesUnchecked) {}
1010+
bool replaceInvalidRefsWithErrors)
1011+
: Ctx(dc->getASTContext()), DC(dc), ParentExpr(parent),
1012+
UseErrorExprs(replaceInvalidRefsWithErrors) {}
10171013

10181014
ASTContext &getASTContext() const { return Ctx; }
10191015

@@ -1394,9 +1390,7 @@ namespace {
13941390
/// true when we want the body to be considered part of this larger expression.
13951391
bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
13961392
// If we have a single statement that can become an expression, turn it
1397-
// into an expression now. This needs to happen before we check
1398-
// LeaveClosureBodiesUnchecked, as the closure may become a single expression
1399-
// closure.
1393+
// into an expression now.
14001394
auto *body = closure->getBody();
14011395
if (auto *S = body->getSingleActiveStatement()) {
14021396
if (S->mayProduceSingleValue(Ctx)) {
@@ -1408,12 +1402,6 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
14081402
}
14091403
}
14101404

1411-
// If we won't be checking the body of the closure, don't walk into it here.
1412-
if (!closure->hasSingleExpressionBody()) {
1413-
if (LeaveClosureBodiesUnchecked)
1414-
return false;
1415-
}
1416-
14171405
// Update the current DeclContext to be the closure we're about to
14181406
// recurse into.
14191407
assert((closure->getParent() == DC ||
@@ -2310,15 +2298,13 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
23102298
}
23112299

23122300
bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
2313-
bool replaceInvalidRefsWithErrors,
2314-
bool leaveClosureBodiesUnchecked) {
2301+
bool replaceInvalidRefsWithErrors) {
23152302
auto *DC = target.getDeclContext();
23162303

23172304
bool hadErrors = false;
23182305

23192306
if (auto *expr = target.getAsExpr()) {
2320-
hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors,
2321-
leaveClosureBodiesUnchecked);
2307+
hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors);
23222308
// Even if the pre-check fails, expression still has to be re-set.
23232309
target.setExpr(expr);
23242310
}
@@ -2330,13 +2316,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
23302316
auto *whereExpr = stmt->getWhere();
23312317

23322318
hadErrors |= preCheckExpression(sequenceExpr, DC,
2333-
/*replaceInvalidRefsWithErrors=*/true,
2334-
/*leaveClosureBodiesUnchecked=*/false);
2319+
/*replaceInvalidRefsWithErrors=*/true);
23352320

23362321
if (whereExpr) {
23372322
hadErrors |= preCheckExpression(whereExpr, DC,
2338-
/*replaceInvalidRefsWithErrors=*/true,
2339-
/*leaveClosureBodiesUnchecked=*/false);
2323+
/*replaceInvalidRefsWithErrors=*/true);
23402324
}
23412325

23422326
// Update sequence and where expressions to pre-checked versions.
@@ -2354,14 +2338,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
23542338
/// Pre-check the expression, validating any types that occur in the
23552339
/// expression and folding sequence expressions.
23562340
bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc,
2357-
bool replaceInvalidRefsWithErrors,
2358-
bool leaveClosureBodiesUnchecked) {
2341+
bool replaceInvalidRefsWithErrors) {
23592342
auto &ctx = dc->getASTContext();
23602343
FrontendStatsTracer StatsTracer(ctx.Stats, "precheck-expr", expr);
23612344

2362-
PreCheckExpression preCheck(dc, expr,
2363-
replaceInvalidRefsWithErrors,
2364-
leaveClosureBodiesUnchecked);
2345+
PreCheckExpression preCheck(dc, expr, replaceInvalidRefsWithErrors);
23652346

23662347
// Perform the pre-check.
23672348
if (auto result = expr->walk(preCheck)) {

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
7777

7878
ConstraintSystemOptions options;
7979
options |= ConstraintSystemFlags::SuppressDiagnostics;
80-
if (!Context.CompletionCallback) {
81-
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
82-
}
8380

8481
// Construct a constraint system from this expression.
8582
ConstraintSystem cs(dc, options);
@@ -223,8 +220,7 @@ bool TypeChecker::typeCheckForCodeCompletion(
223220
// expression and folding sequence expressions.
224221
auto failedPreCheck =
225222
ConstraintSystem::preCheckTarget(target,
226-
/*replaceInvalidRefsWithErrors=*/true,
227-
/*leaveClosureBodiesUnchecked=*/true);
223+
/*replaceInvalidRefsWithErrors=*/true);
228224

229225
if (failedPreCheck)
230226
return false;
@@ -238,10 +234,7 @@ bool TypeChecker::typeCheckForCodeCompletion(
238234
options |= ConstraintSystemFlags::AllowFixes;
239235
options |= ConstraintSystemFlags::SuppressDiagnostics;
240236
options |= ConstraintSystemFlags::ForCodeCompletion;
241-
if (!Context.CompletionCallback) {
242-
options |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
243-
}
244-
237+
245238
ConstraintSystem cs(DC, options);
246239

247240
llvm::SmallVector<Solution, 4> solutions;
@@ -309,8 +302,7 @@ getTypeOfCompletionContextExpr(DeclContext *DC, CompletionTypeCheckKind kind,
309302
ConcreteDeclRef &referencedDecl) {
310303
if (constraints::ConstraintSystem::preCheckExpression(
311304
parsedExpr, DC,
312-
/*replaceInvalidRefsWithErrors=*/true,
313-
/*leaveClosureBodiesUnchecked=*/true))
305+
/*replaceInvalidRefsWithErrors=*/true))
314306
return llvm::None;
315307

316308
switch (kind) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,7 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
448448
// First, pre-check the target, validating any types that occur in the
449449
// expression and folding sequence expressions.
450450
if (ConstraintSystem::preCheckTarget(
451-
target, /*replaceInvalidRefsWithErrors=*/true,
452-
options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))) {
451+
target, /*replaceInvalidRefsWithErrors=*/true)) {
453452
return llvm::None;
454453
}
455454

@@ -468,9 +467,6 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
468467
if (DiagnosticSuppression::isEnabled(Context.Diags))
469468
csOptions |= ConstraintSystemFlags::SuppressDiagnostics;
470469

471-
if (options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))
472-
csOptions |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
473-
474470
if (options.contains(TypeCheckExprFlags::DisableMacroExpansions))
475471
csOptions |= ConstraintSystemFlags::DisableMacroExpansions;
476472

0 commit comments

Comments
 (0)