@@ -2064,6 +2064,10 @@ namespace {
2064
2064
llvm::function_ref<Type(Expr *)> getType;
2065
2065
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
2066
2066
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;
2067
2071
2068
2072
SourceLoc requiredIsolationLoc;
2069
2073
@@ -2560,9 +2564,11 @@ namespace {
2560
2564
const DeclContext *dc,
2561
2565
llvm::function_ref<Type(Expr *)> getType = __Expr_getType,
2562
2566
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
2563
- getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation)
2567
+ getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation,
2568
+ bool checkIsolatedCapture = true )
2564
2569
: ctx(dc->getASTContext ()), getType(getType),
2565
- getClosureActorIsolation(getClosureActorIsolation) {
2570
+ getClosureActorIsolation(getClosureActorIsolation),
2571
+ checkIsolatedCapture(checkIsolatedCapture) {
2566
2572
contextStack.push_back (dc);
2567
2573
}
2568
2574
@@ -4167,9 +4173,16 @@ namespace {
4167
4173
}
4168
4174
4169
4175
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
+ }
4173
4186
4174
4187
return ActorIsolation::forNonisolated (/* unsafe=*/ false )
4175
4188
.withPreconcurrency (preconcurrency);
@@ -4299,7 +4312,8 @@ ActorIsolation swift::determineClosureActorIsolation(
4299
4312
llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
4300
4313
getClosureActorIsolation) {
4301
4314
ActorIsolationChecker checker (closure->getParent (), getType,
4302
- getClosureActorIsolation);
4315
+ getClosureActorIsolation,
4316
+ /* checkIsolatedCapture=*/ false );
4303
4317
return checker.determineClosureIsolation (closure);
4304
4318
}
4305
4319
0 commit comments