Skip to content

Commit a7e7a87

Browse files
authored
Merge pull request #60656 from DougGregor/open-existential-actors
2 parents 0c5bfc2 + 20be955 commit a7e7a87

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
@@ -843,6 +843,15 @@ SILValue SILGenFunction::emitLoadActorExecutor(SILLocation loc,
843843
else
844844
actorV = actor.borrow(*this, loc).getValue();
845845

846+
// Open an existential actor type.
847+
CanType actorType = actor.getType().getASTType();
848+
if (actorType->isExistentialType()) {
849+
actorType = OpenedArchetypeType::get(
850+
actorType, F.getGenericSignature())->getCanonicalType();
851+
SILType loweredActorType = getLoweredType(actorType);
852+
actorV = B.createOpenExistentialRef(loc, actorV, loweredActorType);
853+
}
854+
846855
// For now, we just want to emit a hop_to_executor directly to the
847856
// actor; LowerHopToActor will add the emission logic necessary later.
848857
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 $any Actor)
30+
@available(SwiftStdlib 5.1, *)
31+
public func testIsolatedExistential(_ a: isolated Actor) async {
32+
// CHECK: [[ACTOR_COPY:%.*]] = copy_value [[ACTOR]] : $any Actor
33+
// CHECK: [[ACTOR_BORROW:%.*]] = begin_borrow [[ACTOR_COPY]] : $any Actor
34+
// CHECK: [[ACTOR_OPENED:%.*]] = open_existential_ref [[ACTOR_BORROW]] : $any Actor to $@opened("{{.*}}", any Actor) Self
35+
// CHECK: hop_to_executor [[ACTOR_OPENED]] : $@opened("{{.*}}", any Actor) Self
36+
// CHECK: return
37+
}

0 commit comments

Comments
 (0)