Skip to content

Commit 36f8739

Browse files
committed
[Sema] Remove LeaveClosureBodyUnchecked
Since we migrated all of code completion to solver-based, we no longer need that option.
1 parent 6f99187 commit 36f8739

19 files changed

+47
-148
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ class ResultTypeRequest
22422242
class PatternBindingEntryRequest
22432243
: public SimpleRequest<PatternBindingEntryRequest,
22442244
const PatternBindingEntry *(PatternBindingDecl *,
2245-
unsigned, bool),
2245+
unsigned),
22462246
RequestFlags::SeparatelyCached> {
22472247
public:
22482248
using SimpleRequest::SimpleRequest;
@@ -2251,9 +2251,8 @@ class PatternBindingEntryRequest
22512251
friend SimpleRequest;
22522252

22532253
// Evaluation.
2254-
const PatternBindingEntry *evaluate(Evaluator &evaluator,
2255-
PatternBindingDecl *PBD, unsigned i,
2256-
bool LeaveClosureBodiesUnchecked) const;
2254+
const PatternBindingEntry *
2255+
evaluate(Evaluator &evaluator, PatternBindingDecl *PBD, unsigned i) const;
22572256

22582257
public:
22592258
// Separate caching.

include/swift/Sema/ConstraintSystem.h

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

1792-
/// Don't try to type check closure bodies, and leave them unchecked. This is
1793-
/// used for source tooling functionalities.
1794-
LeaveClosureBodyUnchecked = 0x10,
1795-
17961792
/// If set, we are solving specifically to determine the type of a
17971793
/// CodeCompletionExpr, and should continue in the presence of errors wherever
17981794
/// possible.
1799-
ForCodeCompletion = 0x20,
1795+
ForCodeCompletion = 0x10,
18001796

18011797
/// Include Clang function types when checking equality for function types.
18021798
///
@@ -1807,13 +1803,13 @@ enum class ConstraintSystemFlags {
18071803
/// should be treated as semantically different, as they may have different
18081804
/// calling conventions, say due to Clang attributes such as
18091805
/// `__attribute__((ns_consumed))`.
1810-
UseClangFunctionTypes = 0x40,
1806+
UseClangFunctionTypes = 0x20,
18111807

18121808
/// When set, ignore async/sync mismatches
1813-
IgnoreAsyncSyncMismatch = 0x80,
1809+
IgnoreAsyncSyncMismatch = 0x40,
18141810

18151811
/// Disable macro expansions.
1816-
DisableMacroExpansions = 0x100,
1812+
DisableMacroExpansions = 0x80,
18171813
};
18181814

18191815
/// Options that affect the constraint system as a whole.
@@ -5198,17 +5194,15 @@ class ConstraintSystem {
51985194
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
51995195
/// to replace any discovered invalid member references with `ErrorExpr`.
52005196
static bool preCheckTarget(SyntacticElementTarget &target,
5201-
bool replaceInvalidRefsWithErrors,
5202-
bool leaveClosureBodiesUnchecked);
5197+
bool replaceInvalidRefsWithErrors);
52035198

52045199
/// Pre-check the expression, validating any types that occur in the
52055200
/// expression and folding sequence expressions.
52065201
///
52075202
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
52085203
/// to replace any discovered invalid member references with `ErrorExpr`.
52095204
static bool preCheckExpression(Expr *&expr, DeclContext *dc,
5210-
bool replaceInvalidRefsWithErrors,
5211-
bool leaveClosureBodiesUnchecked);
5205+
bool replaceInvalidRefsWithErrors);
52125206

52135207
/// Solve the system of constraints generated from provided target.
52145208
///

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,7 @@ bool PatternBindingDecl::isComputingPatternBindingEntry(
22332233
const VarDecl *vd) const {
22342234
unsigned i = getPatternEntryIndexForVarDecl(vd);
22352235
return getASTContext().evaluator.hasActiveRequest(
2236-
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i,
2237-
/*LeaveClosureBodyUnchecked=*/false});
2236+
PatternBindingEntryRequest{const_cast<PatternBindingDecl *>(this), i});
22382237
}
22392238

22402239
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
@@ -10455,8 +10455,7 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
1045510455

1045610456
DiagnosticTransaction diagnostics(ctx.Diags);
1045710457
{
10458-
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true,
10459-
/*leaveClosureBodyUnchecked=*/false)) {
10458+
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) {
1046010459
// Skip diagnostics if they are disabled, otherwise it would result in
1046110460
// duplicate diagnostics, since this operation is going to be repeated
1046210461
// in diagnostic mode.

lib/Sema/CSSyntacticElement.cpp

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

529-
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true,
530-
/*leaveClosureBodyUnchecked=*/false)) {
529+
if (cs.preCheckTarget(target, /*replaceInvalidRefWithErrors=*/true)) {
531530
hadError = true;
532531
return;
533532
}
@@ -740,8 +739,7 @@ class SyntacticElementConstraintGenerator
740739
/*bindPatternVarsOneWay=*/false);
741740

742741
if (ConstraintSystem::preCheckTarget(
743-
target, /*replaceInvalidRefsWithErrors=*/true,
744-
/*LeaveCLosureBodyUnchecked=*/false))
742+
target, /*replaceInvalidRefsWithErrors=*/true))
745743
return llvm::None;
746744

747745
return target;

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7308,19 +7308,8 @@ bool ConstraintSystem::isArgumentGenericFunction(Type argType, Expr *argExpr) {
73087308
}
73097309

73107310
bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const {
7311-
if (getAppliedResultBuilderTransform(closure))
7312-
return true;
7313-
7314-
if (closure->hasSingleExpressionBody())
7315-
return true;
7316-
7317-
if (Options.contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked))
7318-
return false;
7319-
7320-
if (closure->hasEmptyBody())
7321-
return false;
7322-
7323-
return true;
7311+
return getAppliedResultBuilderTransform(closure) ||
7312+
closure->hasSingleExpressionBody() || !closure->hasEmptyBody();
73247313
}
73257314

73267315
TypeVarBindingProducer::TypeVarBindingProducer(BindingSet &bindings)

lib/Sema/PreCheckExpr.cpp

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

941-
bool LeaveClosureBodiesUnchecked;
942-
943941
/// A stack of expressions being walked, used to determine where to
944942
/// insert RebindSelfInConstructorExpr nodes.
945943
llvm::SmallVector<Expr *, 8> ExprStack;
@@ -1008,11 +1006,9 @@ namespace {
10081006

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

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

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

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

23042292
bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
2305-
bool replaceInvalidRefsWithErrors,
2306-
bool leaveClosureBodiesUnchecked) {
2293+
bool replaceInvalidRefsWithErrors) {
23072294
auto *DC = target.getDeclContext();
23082295

23092296
bool hadErrors = false;
23102297

23112298
if (auto *expr = target.getAsExpr()) {
2312-
hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors,
2313-
leaveClosureBodiesUnchecked);
2299+
hadErrors |= preCheckExpression(expr, DC, replaceInvalidRefsWithErrors);
23142300
// Even if the pre-check fails, expression still has to be re-set.
23152301
target.setExpr(expr);
23162302
}
@@ -2322,13 +2308,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
23222308
auto *whereExpr = stmt->getWhere();
23232309

23242310
hadErrors |= preCheckExpression(sequenceExpr, DC,
2325-
/*replaceInvalidRefsWithErrors=*/true,
2326-
/*leaveClosureBodiesUnchecked=*/false);
2311+
/*replaceInvalidRefsWithErrors=*/true);
23272312

23282313
if (whereExpr) {
23292314
hadErrors |= preCheckExpression(whereExpr, DC,
2330-
/*replaceInvalidRefsWithErrors=*/true,
2331-
/*leaveClosureBodiesUnchecked=*/false);
2315+
/*replaceInvalidRefsWithErrors=*/true);
23322316
}
23332317

23342318
// Update sequence and where expressions to pre-checked versions.
@@ -2346,14 +2330,11 @@ bool ConstraintSystem::preCheckTarget(SyntacticElementTarget &target,
23462330
/// Pre-check the expression, validating any types that occur in the
23472331
/// expression and folding sequence expressions.
23482332
bool ConstraintSystem::preCheckExpression(Expr *&expr, DeclContext *dc,
2349-
bool replaceInvalidRefsWithErrors,
2350-
bool leaveClosureBodiesUnchecked) {
2333+
bool replaceInvalidRefsWithErrors) {
23512334
auto &ctx = dc->getASTContext();
23522335
FrontendStatsTracer StatsTracer(ctx.Stats, "precheck-expr", expr);
23532336

2354-
PreCheckExpression preCheck(dc, expr,
2355-
replaceInvalidRefsWithErrors,
2356-
leaveClosureBodiesUnchecked);
2337+
PreCheckExpression preCheck(dc, expr, replaceInvalidRefsWithErrors);
23572338

23582339
// Perform the pre-check.
23592340
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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
443443

444444
// First, pre-check the target, validating any types that occur in the
445445
// expression and folding sequence expressions.
446-
if (ConstraintSystem::preCheckTarget(
447-
target, /*replaceInvalidRefsWithErrors=*/true,
448-
options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))) {
446+
if (ConstraintSystem::preCheckTarget(target,
447+
/*replaceInvalidRefsWithErrors=*/true)) {
449448
return llvm::None;
450449
}
451450

@@ -464,9 +463,6 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
464463
if (DiagnosticSuppression::isEnabled(Context.Diags))
465464
csOptions |= ConstraintSystemFlags::SuppressDiagnostics;
466465

467-
if (options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))
468-
csOptions |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
469-
470466
if (options.contains(TypeCheckExprFlags::DisableMacroExpansions))
471467
csOptions |= ConstraintSystemFlags::DisableMacroExpansions;
472468

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,9 +2625,7 @@ NamingPatternRequest::evaluate(Evaluator &evaluator, VarDecl *VD) const {
26252625
// the naming pattern as a side effect in this case, and TypeCheckStmt
26262626
// and TypeCheckPattern handle the others. But that's all really gross.
26272627
unsigned i = PBD->getPatternEntryIndexForVarDecl(VD);
2628-
(void)evaluateOrDefault(evaluator,
2629-
PatternBindingEntryRequest{
2630-
PBD, i, /*LeaveClosureBodiesUnchecked=*/false},
2628+
(void)evaluateOrDefault(evaluator, PatternBindingEntryRequest{PBD, i},
26312629
nullptr);
26322630
if (PBD->isInvalid()) {
26332631
VD->getParentPattern()->setType(ErrorType::get(Context));

0 commit comments

Comments
 (0)