Skip to content

Commit e0377fb

Browse files
committed
SIL: Fix lowering of local functions with explicit isolated parameter
When the isolated parameter is the function's own parameter, it is not a capture. Fixes rdar://135607071.
1 parent b0b5b2a commit e0377fb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,10 @@ CaptureInfo CaptureInfoRequest::evaluate(Evaluator &evaluator,
762762
if (actorIsolation.getKind() == ActorIsolation::ActorInstance) {
763763
if (auto *var = actorIsolation.getActorInstance()) {
764764
assert(isa<ParamDecl>(var));
765-
finder.addCapture(CapturedValue(var, 0, AFD->getLoc()));
765+
// Don't capture anything if the isolation parameter is a parameter
766+
// of the local function.
767+
if (var->getDeclContext() != AFD)
768+
finder.addCapture(CapturedValue(var, 0, AFD->getLoc()));
766769
}
767770
}
768771
}

test/SILGen/local_function_isolation.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,15 @@ actor NestedAsyncInSyncActor {
8787
}
8888
_ = middle
8989
}
90+
}
91+
92+
// CHECK-LABEL: sil hidden [ossa] @$s24local_function_isolation13outerFunctionyyScA_pYaF : $@convention(thin) @async (@guaranteed any Actor) -> () {
93+
func outerFunction(_ a: any Actor) async {
94+
// CHECK-LABEL: sil private [ossa] @$s24local_function_isolation13outerFunctionyyScA_pYaF06middleE0L_yyScA_pYaF : $@convention(thin) @async (@guaranteed any Actor) -> () {
95+
func middleFunction(_ isolated: any Actor) async {
96+
// CHECK-LABEL: sil private [ossa] @$s24local_function_isolation13outerFunctionyyScA_pYaF06middleE0L_yyScA_pYaF05innerE0L_yyYaF : $@convention(thin) @async () -> () {
97+
func innerFunction() async {}
98+
}
99+
100+
await middleFunction(a)
90101
}

0 commit comments

Comments
 (0)