Skip to content

Commit 81d191c

Browse files
committed
[SE-0313] Hop to the exector if an async function with an isolated parameter
1 parent 15e1cd2 commit 81d191c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/SILGen/SILGenProlog.cpp

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

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)