Skip to content

Commit 636fc0f

Browse files
committed
Sema: Compute captures when contextualizing closures
1 parent 0bb323b commit 636fc0f

File tree

5 files changed

+3
-22
lines changed

5 files changed

+3
-22
lines changed

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,10 +4494,6 @@ namespace {
44944494
outerClosure->setType(outerClosureTy);
44954495
cs.cacheType(outerClosure);
44964496

4497-
// The inner closure at least will definitely have a capture.
4498-
cs.getTypeChecker().ClosuresWithUncomputedCaptures.push_back(outerClosure);
4499-
cs.getTypeChecker().ClosuresWithUncomputedCaptures.push_back(closure);
4500-
45014497
// let outerApply = "\( outerClosure )( \(E) )"
45024498
auto outerApply = CallExpr::createImplicit(ctx, outerClosure, {E}, {});
45034499
outerApply->setType(closureTy);
@@ -7268,12 +7264,6 @@ namespace {
72687264
ClosuresToTypeCheck.push_back(closure);
72697265
}
72707266

7271-
// Don't try to register captures if constraint system is used to
7272-
// produce diagnostics for one of the sub-expressions.
7273-
if (!cs.Options.contains(
7274-
ConstraintSystemFlags::SubExpressionDiagnostics))
7275-
cs.getTypeChecker().ClosuresWithUncomputedCaptures.push_back(closure);
7276-
72777267
return { false, closure };
72787268
}
72797269

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,6 @@ Expr *ConstraintSystem::buildAutoClosureExpr(Expr *expr,
34943494
expr, newClosureType, AutoClosureExpr::InvalidDiscriminator, DC);
34953495

34963496
closure->setParameterList(ParameterList::createEmpty(Context));
3497-
getTypeChecker().ClosuresWithUncomputedCaptures.push_back(closure);
34983497

34993498
Expr *result = closure;
35003499

lib/Sema/TypeCheckStmt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ namespace {
112112
ParentDC = CE;
113113
CE->getBody()->walk(*this);
114114
ParentDC = oldParentDC;
115+
116+
TypeChecker::computeCaptures(CE);
115117
return { false, E };
116118
}
117119

@@ -148,7 +150,7 @@ namespace {
148150
if (CE->hasSingleExpressionBody())
149151
CE->getBody()->walk(ContextualizeClosures(CE));
150152

151-
// In neither case do we need to continue the *current* walk.
153+
TypeChecker::computeCaptures(CE);
152154
return { false, E };
153155
}
154156

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,6 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
302302
}
303303
} while (currentFunctionIdx < TC.definedFunctions.size());
304304

305-
// Compute captures for functions and closures we visited.
306-
for (auto *closure : TC.ClosuresWithUncomputedCaptures) {
307-
TypeChecker::computeCaptures(closure);
308-
}
309-
TC.ClosuresWithUncomputedCaptures.clear();
310-
311305
for (AbstractFunctionDecl *FD : llvm::reverse(TC.definedFunctions)) {
312306
TypeChecker::computeCaptures(FD);
313307
}

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,6 @@ class TypeChecker final {
462462
/// The list of function definitions we've encountered.
463463
std::vector<AbstractFunctionDecl *> definedFunctions;
464464

465-
/// A list of closures for the most recently type-checked function, which we
466-
/// will need to compute captures for.
467-
std::vector<AbstractClosureExpr *> ClosuresWithUncomputedCaptures;
468-
469465
private:
470466
TypeChecker() = default;
471467
~TypeChecker() = default;

0 commit comments

Comments
 (0)