Skip to content

Commit b1b64df

Browse files
committed
[SE-0313] Hop to the exector if an async function with an isolated parameter
1 parent 71d9c16 commit b1b64df

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,25 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
503503
switch (actorIsolation.getKind()) {
504504
case ActorIsolation::Unspecified:
505505
case ActorIsolation::Independent:
506+
// If this is an async function that has an isolated parameter, hop
507+
// to it.
508+
if (F.isAsync()) {
509+
for (auto param : *funcDecl->getParameters()) {
510+
if (param->isIsolated()) {
511+
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
512+
Type actorType = param->getType();
513+
RValue actorInstanceRV = emitRValueForDecl(
514+
loc, param, actorType, AccessSemantics::Ordinary);
515+
ManagedValue actorInstance =
516+
std::move(actorInstanceRV).getScalarValue();
517+
ExpectedExecutor = emitLoadActorExecutor(loc, actorInstance);
518+
break;
519+
}
520+
}
521+
}
522+
523+
break;
524+
506525
case ActorIsolation::GlobalActorUnsafe:
507526
break;
508527

test/SILGen/hop_to_executor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,11 @@ func testImplicitAsyncIsolatedParam(
381381
// CHECK-NEXT: hop_to_executor [[CURRENT]] : $Optional<Builtin.Executor>
382382
await otherActor.otherIsolated(i, actor, d)
383383
}
384+
385+
// CHECK-LABEL: sil hidden [ossa] @$s4test22asyncWithIsolatedParam1i5actor1dySi_AA7MyActorCYiSdtYaF : $@convention(thin) @async (Int, @guaranteed MyActor, Double) -> ()
386+
func asyncWithIsolatedParam(i: Int, actor: isolated MyActor, d: Double) async {
387+
// CHECK: [[ACTOR:%.*]] = copy_value %1 : $MyActor
388+
// CHECK-NEXT: [[BORROWED:%.*]] = begin_borrow [[ACTOR]] : $MyActor
389+
// CHECK-NEXT: hop_to_executor [[BORROWED]] : $MyActor
390+
// CHECK-NEXT: end_borrow [[BORROWED]] : $MyActor
391+
}

0 commit comments

Comments
 (0)