Skip to content

Commit

Permalink
Open existential actors when retrieving their executors.
Browse files Browse the repository at this point in the history
Fixes rdar://91448324.
  • Loading branch information
DougGregor committed Aug 19, 2022
1 parent dc8cdcb commit 20be955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,15 @@ SILValue SILGenFunction::emitLoadActorExecutor(SILLocation loc,
else
actorV = actor.borrow(*this, loc).getValue();

// Open an existential actor type.
CanType actorType = actor.getType().getASTType();
if (actorType->isExistentialType()) {
actorType = OpenedArchetypeType::get(
actorType, F.getGenericSignature())->getCanonicalType();
SILType loweredActorType = getLoweredType(actorType);
actorV = B.createOpenExistentialRef(loc, actorV, loweredActorType);
}

// For now, we just want to emit a hop_to_executor directly to the
// actor; LowerHopToActor will add the emission logic necessary later.
return actorV;
Expand Down
11 changes: 11 additions & 0 deletions test/SILGen/isolated_parameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ public func takeClosureWithIsolatedParam(body: (isolated A) async -> Void) { }
public func testClosureWithIsolatedParam() {
takeClosureWithIsolatedParam { _ in }
}

// CHECK-LABEL: sil{{.*}} [ossa] @$s4test0A19IsolatedExistentialyyScA_pYiYaF
// CHECK: bb0([[ACTOR:%.*]] : @guaranteed $any Actor)
@available(SwiftStdlib 5.1, *)
public func testIsolatedExistential(_ a: isolated Actor) async {
// CHECK: [[ACTOR_COPY:%.*]] = copy_value [[ACTOR]] : $any Actor
// CHECK: [[ACTOR_BORROW:%.*]] = begin_borrow [[ACTOR_COPY]] : $any Actor
// CHECK: [[ACTOR_OPENED:%.*]] = open_existential_ref [[ACTOR_BORROW]] : $any Actor to $@opened("{{.*}}", any Actor) Self
// CHECK: hop_to_executor [[ACTOR_OPENED]] : $@opened("{{.*}}", any Actor) Self
// CHECK: return
}

0 comments on commit 20be955

Please sign in to comment.