Skip to content

Commit a7256b1

Browse files
committed
[CodeCompletion] Don’t compute isolated parameter captures during code completion
Computing capture information requires a type checked AST, which we don’t have during code completion. To fix an assertion failure, don’t look for a captured `isolated` parameter while computing a closure’s actor isolation during code completion. rdar://126923558
1 parent c2a5028 commit a7256b1

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,10 @@ namespace {
20642064
llvm::function_ref<Type(Expr *)> getType;
20652065
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
20662066
getClosureActorIsolation;
2067+
/// Whether to check if the closure captures an `isolated` parameter.
2068+
/// This is needed as a workaround during code completion, which doesn't
2069+
/// have types applied to the AST and thus doesn't have captures computed.
2070+
bool checkIsolatedCapture;
20672071

20682072
SourceLoc requiredIsolationLoc;
20692073

@@ -2560,9 +2564,11 @@ namespace {
25602564
const DeclContext *dc,
25612565
llvm::function_ref<Type(Expr *)> getType = __Expr_getType,
25622566
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
2563-
getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation)
2567+
getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation,
2568+
bool checkIsolatedCapture = true)
25642569
: ctx(dc->getASTContext()), getType(getType),
2565-
getClosureActorIsolation(getClosureActorIsolation) {
2570+
getClosureActorIsolation(getClosureActorIsolation),
2571+
checkIsolatedCapture(checkIsolatedCapture) {
25662572
contextStack.push_back(dc);
25672573
}
25682574

@@ -4167,9 +4173,16 @@ namespace {
41674173
}
41684174

41694175
case ActorIsolation::ActorInstance: {
4170-
if (auto param = closure->getCaptureInfo().getIsolatedParamCapture())
4171-
return ActorIsolation::forActorInstanceCapture(param)
4172-
.withPreconcurrency(preconcurrency);
4176+
if (checkIsolatedCapture) {
4177+
if (auto param = closure->getCaptureInfo().getIsolatedParamCapture())
4178+
return ActorIsolation::forActorInstanceCapture(param)
4179+
.withPreconcurrency(preconcurrency);
4180+
} else {
4181+
// If we don't have capture information during code completion, assume
4182+
// that the closure captures the `isolated` parameter from the parent
4183+
// context.
4184+
return parentIsolation;
4185+
}
41734186

41744187
return ActorIsolation::forNonisolated(/*unsafe=*/false)
41754188
.withPreconcurrency(preconcurrency);
@@ -4299,7 +4312,8 @@ ActorIsolation swift::determineClosureActorIsolation(
42994312
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
43004313
getClosureActorIsolation) {
43014314
ActorIsolationChecker checker(closure->getParent(), getType,
4302-
getClosureActorIsolation);
4315+
getClosureActorIsolation,
4316+
/*checkIsolatedCapture=*/false);
43034317
return checker.determineClosureIsolation(closure);
43044318
}
43054319

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE -source-filename=%s
2+
3+
actor Foo {
4+
func bar() {}
5+
}
6+
7+
func test(foo: isolated Foo) {
8+
foo.#^COMPLETE^#
9+
}

0 commit comments

Comments
 (0)