Skip to content

Commit d1ccba7

Browse files
committed
Handle generic self types as the isolation parameters.
This PR builds on #73129 and fixes #73345. Co-authored with @hyp.
1 parent 59232e0 commit d1ccba7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,6 +4441,12 @@ TypeConverter::getLoweredLocalCaptures(SILDeclRef fn) {
44414441
if (auto *var = actorIsolation.getActorInstance()) {
44424442
assert(isa<ParamDecl>(var));
44434443
recordCapture(CapturedValue(var, 0, afd->getLoc()));
4444+
if (var->getInterfaceType()->hasTypeParameter()) {
4445+
// If the isolated parameter is of a generic (actor)
4446+
// type, we need to treat as if the local function is
4447+
// generic.
4448+
capturesGenericParams = true;
4449+
}
44444450
}
44454451
}
44464452
}

test/SILGen/local_function_isolation.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,17 @@ func f(isolation: isolated MyActor, ns: NotSendable) {
5353
}
5454

5555
func test() async {}
56+
57+
// A generic actor type, which causes the generic self parameter
58+
// (actor isolation parameter) to be added to captures of the
59+
// local/nested function.
60+
actor GenericActor<K> {
61+
var i: Int = 0
62+
private func outerFunc() {
63+
func accessSelf() -> Int {
64+
// CHECK-LABEL: sil private [ossa] @$s24local_function_isolation12GenericActorC9outerFunc33_7B9E2B75110B8600A136A469D51CAF2BLLyyF10accessSelfL_SiylF : $@convention(thin) <K> (@sil_isolated @guaranteed GenericActor<K>) -> Int {
65+
return 0
66+
}
67+
print(accessSelf())
68+
}
69+
}

0 commit comments

Comments
 (0)