Skip to content

Commit f3bf9fd

Browse files
committed
Open existential actors when retrieving their executors.
Fixes rdar://91448324.
1 parent 3a9211a commit f3bf9fd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ SILValue SILGenFunction::emitLoadActorExecutor(SILLocation loc,
768768
else
769769
actorV = actor.borrow(*this, loc).getValue();
770770

771+
// Open an existential actor type.
772+
CanType actorType = actor.getType().getASTType();
773+
if (actorType->isExistentialType()) {
774+
actorType = OpenedArchetypeType::get(
775+
actorType, F.getGenericSignature())->getCanonicalType();
776+
SILType loweredActorType = getLoweredType(actorType);
777+
actorV = B.createOpenExistentialRef(loc, actorV, loweredActorType);
778+
}
779+
771780
// For now, we just want to emit a hop_to_executor directly to the
772781
// actor; LowerHopToActor will add the emission logic necessary later.
773782
return actorV;

test/SILGen/isolated_parameters.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ public func takeClosureWithIsolatedParam(body: (isolated A) async -> Void) { }
2424
public func testClosureWithIsolatedParam() {
2525
takeClosureWithIsolatedParam { _ in }
2626
}
27+
28+
// CHECK-LABEL: sil{{.*}} [ossa] @$s4test0A19IsolatedExistentialyyScA_pYiYaF
29+
// CHECK: bb0([[ACTOR:%.*]] : @guaranteed $Actor)
30+
@available(SwiftStdlib 5.1, *)
31+
public func testIsolatedExistential(_ a: isolated Actor) async {
32+
// CHECK: [[ACTOR_COPY:%.*]] = copy_value [[ACTOR]] : $Actor
33+
// CHECK: [[ACTOR_BORROW:%.*]] = begin_borrow [[ACTOR_COPY]] : $Actor
34+
// CHECK: [[ACTOR_OPENED:%.*]] = open_existential_ref [[ACTOR_BORROW]] : $Actor to $@opened("{{.*}}") Actor
35+
// CHECK: hop_to_executor [[ACTOR_OPENED]] : $@opened("{{.*}}") Actor
36+
// CHECK: return
37+
}

0 commit comments

Comments
 (0)