Skip to content

Commit ce43f0d

Browse files
committed
Partially revert "[CodeComplete] Avoid distinguishing between closure types"
This regresses completion performance, bring back the distinction between the multi-statement and single-expression fallback cases. b147a17d755d833d8009ad5caa2f8a856692fdc6
1 parent 0a4c029 commit ce43f0d

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

include/swift/Sema/CompletionContextFinder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class CompletionContextFinder : public ASTWalker {
2828
enum class ContextKind {
2929
FallbackExpression,
3030
StringInterpolation,
31-
Closure,
31+
SingleStmtClosure,
32+
MultiStmtClosure,
3233
ErrorExpression
3334
};
3435

lib/Sema/CompletionContextFinder.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ CompletionContextFinder::CompletionContextFinder(
2727

2828
ASTWalker::PreWalkResult<Expr *>
2929
CompletionContextFinder::walkToExprPre(Expr *E) {
30-
if (auto *closure = dyn_cast<ClosureExpr>(E))
31-
Contexts.push_back({ContextKind::Closure, closure});
30+
if (auto *closure = dyn_cast<ClosureExpr>(E)) {
31+
// NOTE: We're querying hasSingleExpressionBody before the single-expression
32+
// body transform has happened, so this won't take e.g SingleValueStmtExprs
33+
// into account.
34+
Contexts.push_back({closure->hasSingleExpressionBody()
35+
? ContextKind::SingleStmtClosure
36+
: ContextKind::MultiStmtClosure,
37+
closure});
38+
}
3239

3340
if (isa<InterpolatedStringLiteralExpr>(E)) {
3441
Contexts.push_back({ContextKind::StringInterpolation, E});
@@ -116,12 +123,15 @@ CompletionContextFinder::getFallbackCompletionExpr() const {
116123
fallback = Fallback{context.E, fallbackDC, separatePrecheck};
117124
continue;
118125

119-
case ContextKind::Closure:
126+
case ContextKind::SingleStmtClosure:
120127
if (!fallback && context.E != InitialExpr)
121128
fallback = Fallback{context.E, fallbackDC, separatePrecheck};
122129
fallbackDC = cast<AbstractClosureExpr>(context.E);
123130
continue;
124131

132+
case ContextKind::MultiStmtClosure:
133+
fallbackDC = cast<AbstractClosureExpr>(context.E);
134+
LLVM_FALLTHROUGH;
125135
case ContextKind::ErrorExpression:;
126136
fallback = llvm::None;
127137
separatePrecheck = true;

0 commit comments

Comments
 (0)