Skip to content

Commit b1ca06d

Browse files
committed
[Concurrency] #isolation+nonsending nonisolated - review followup and SIL test
1 parent b0d2ca9 commit b1ca06d

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7299,6 +7299,18 @@ RValue RValueEmitter::visitCurrentContextIsolationExpr(
72997299
dyn_cast_or_null<AbstractFunctionDecl>(SGF.F.getDeclRef().getDecl());
73007300
if (afd) {
73017301
auto isolation = getActorIsolation(afd);
7302+
auto ctor = dyn_cast_or_null<ConstructorDecl>(afd);
7303+
if (ctor && ctor->isDesignatedInit() &&
7304+
isolation == ActorIsolation::ActorInstance &&
7305+
isolation.getActorInstance() == ctor->getImplicitSelfDecl()) {
7306+
// If we are in an actor initializer that is isolated to self, the
7307+
// current isolation is flow-sensitive; use that instead of the
7308+
// synthesized expression.
7309+
auto isolationValue =
7310+
SGF.emitFlowSensitiveSelfIsolation(E, isolation);
7311+
return RValue(SGF, E, isolationValue);
7312+
}
7313+
73027314
if (isolation == ActorIsolation::CallerIsolationInheriting) {
73037315
auto *isolatedArg = SGF.F.maybeGetIsolatedArgument();
73047316
assert(isolatedArg &&
@@ -7311,18 +7323,6 @@ RValue RValueEmitter::visitCurrentContextIsolationExpr(
73117323
}
73127324
return RValue(SGF, E, isolatedMV);
73137325
}
7314-
7315-
auto ctor = dyn_cast_or_null<ConstructorDecl>(afd);
7316-
if (ctor && ctor->isDesignatedInit() &&
7317-
isolation == ActorIsolation::ActorInstance &&
7318-
isolation.getActorInstance() == ctor->getImplicitSelfDecl()) {
7319-
// If we are in an actor initializer that is isolated to self, the
7320-
// current isolation is flow-sensitive; use that instead of the
7321-
// synthesized expression.
7322-
auto isolationValue =
7323-
SGF.emitFlowSensitiveSelfIsolation(E, isolation);
7324-
return RValue(SGF, E, isolationValue);
7325-
}
73267326
}
73277327

73287328
return visit(E->getActor(), C);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swift-frontend -parse-as-library -emit-sil %s | %FileCheck %s
2+
3+
// REQUIRES: concurrency
4+
5+
nonisolated(nonsending) func nonisolatedNonsending() async {
6+
let iso = #isolation
7+
take(iso: iso)
8+
}
9+
10+
func take(iso: (any Actor)?) {}
11+
12+
// CHECK-LABEL: // nonisolatedNonsending()
13+
// CHECK-NEXT: // Isolation: caller_isolation_inheriting
14+
// CHECK-NEXT: sil hidden @$s39isolated_nonsending_isolation_macro_sil21nonisolatedNonsendingyyYaF : $@convention(thin) @async (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> () {
15+
// CHECK: bb0(%0 : $Optional<any Actor>):
16+
// CHECK-NEXT: hop_to_executor %0 // id: %1
17+
// CHECK-NEXT: retain_value %0 // id: %2
18+
// CHECK-NEXT: debug_value %0, let, name "iso" // id: %3
19+
// CHECK-NEXT: // function_ref take(iso:)
20+
// CHECK-NEXT: %4 = function_ref @$s39isolated_nonsending_isolation_macro_sil4take3isoyScA_pSg_tF : $@convention(thin) (@guaranteed Optional<any Actor>) -> () // user: %5
21+
// CHECK-NEXT: %5 = apply %4(%0) : $@convention(thin) (@guaranteed Optional<any Actor>) -> ()
22+
// CHECK-NEXT: release_value %0 // id: %6
23+
// CHECK-NEXT: %7 = tuple () // user: %8
24+
// CHECK-NEXT: return %7 // id: %8
25+
// CHECK-NEXT: } // end sil function '$s39isolated_nonsending_isolation_macro_sil21nonisolatedNonsendingyyYaF'

0 commit comments

Comments
 (0)