Skip to content

Commit 09d2f27

Browse files
committed
[silgen] Change two places we used Builtin.Executor to instead use Optional<any Actor> as an expected executor.
We want SILGen to have a simplified view of its executor and know that whenever one sees an Actor, it is an actual actor instead of a Builtin.Executor. This just simplifies code. Also, we should eventually have an invariant that Builtin.Executor should only be allowed in LoweredSIL after LowerHopToExecutor has run. But that is a change for another day.
1 parent 4d83d63 commit 09d2f27

21 files changed

+155
-149
lines changed

lib/SILGen/SILGenConcurrency.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace Lowering;
2727

2828
static void setExpectedExecutorForGeneric(SILGenFunction &SGF) {
2929
auto loc = RegularLocation::getAutoGeneratedLocation(SGF.F.getLocation());
30-
SGF.ExpectedExecutor.set(SGF.emitGenericExecutor(loc));
30+
SGF.ExpectedExecutor.set(SGF.emitNonIsolatedIsolation(loc).getValue());
3131
}
3232

3333
static void setExpectedExecutorForGlobalActor(SILGenFunction &SGF,
@@ -284,8 +284,9 @@ void SILGenFunction::emitConstructorExpectedExecutorProlog() {
284284
loc.markAsPrologue();
285285
loc = loc.asAutoGenerated();
286286

287-
auto initialExecutor = emitGenericExecutor(loc);
288-
B.createHopToExecutor(loc, initialExecutor, /*mandatory*/ false);
287+
auto initialExecutor = emitNonIsolatedIsolation(loc);
288+
B.createHopToExecutor(loc, initialExecutor.getValue(),
289+
/*mandatory*/ false);
289290
return;
290291
}
291292
}

test/Concurrency/attr_execution/conversions_silgen.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,15 @@ public func testCallerToCaller(_ x: nonisolated(nonsending) @escaping () async -
152152

153153
// CHECK-LABEL: sil [ossa] @$s21attr_execution_silgen24testCallerLocalVariablesyyyyYaYCcYaF : $@convention(thin) @async (@guaranteed @async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> ()) -> () {
154154
// CHECK: bb0([[PARAM:%.*]] : @guaranteed $@async @callee_guaranteed (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>) -> ()):
155+
// CHECK: [[ACTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
156+
// CHECK: hop_to_executor [[ACTOR]]
155157
// CHECK: [[PARAM_COPY:%.*]] = copy_value [[PARAM]]
156158
// CHECK: [[Y:%.*]] = move_value [lexical] [var_decl] [[PARAM_COPY]]
157159
// CHECK: [[Y_B:%.*]] = begin_borrow [[Y]]
158160
// CHECK: [[Y_B_C:%.*]] = copy_value [[Y_B]]
159161
// CHECK: [[Y2:%.*]] = move_value [lexical] [var_decl] [[Y_B_C]]
160162
// CHECK: [[Y2_B:%.*]] = begin_borrow [[Y2]]
161163
// CHECK: [[Y2_B_C:%.*]] = copy_value [[Y2_B]]
162-
// CHECK: [[ACTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
163164
// CHECK: [[Y2_B_C_B:%.*]] = begin_borrow [[Y2_B_C]]
164165
// CHECK: apply [[Y2_B_C_B]]([[ACTOR]])
165166
// CHECK: } // end sil function '$s21attr_execution_silgen24testCallerLocalVariablesyyyyYaYCcYaF'
@@ -522,7 +523,7 @@ func testThatClosuresAssumeIsolation(fn: inout nonisolated(nonsending) (Int) asy
522523
testParam { 42 }
523524

524525
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen31testThatClosuresAssumeIsolation2fnyySiYaYCcz_tFyyYaXEfU1_ : $@convention(thin) @async () -> ()
525-
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
526+
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
526527
// CHECK: hop_to_executor [[GENERIC_EXECUTOR]]
527528
testParam { @concurrent in 42 }
528529

@@ -538,7 +539,7 @@ func testThatClosuresAssumeIsolation(fn: inout nonisolated(nonsending) (Int) asy
538539
fn = { _ in }
539540

540541
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen31testThatClosuresAssumeIsolation2fnyySiYaYCcz_tFySiYacfU3_ : $@convention(thin) @async (Int) -> ()
541-
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
542+
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
542543
// CHECK: hop_to_executor [[GENERIC_EXECUTOR]]
543544
// CHECK: } // end sil function '$s21attr_execution_silgen31testThatClosuresAssumeIsolation2fnyySiYaYCcz_tFySiYacfU3_'
544545

@@ -557,7 +558,7 @@ func testNoIsolationTransfer() {
557558
func testErasure(@_inheritActorContext _: @escaping @isolated(any) () async -> Void) {}
558559

559560
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen23testNoIsolationTransferyyFyyYacfU_ : $@convention(thin) @async (@guaranteed Optional<any Actor>) -> ()
560-
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
561+
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
561562
// CHECK: hop_to_executor [[GENERIC_EXECUTOR]]
562563
testErasure { @concurrent in }
563564
}
@@ -566,7 +567,7 @@ func testClosuresDontAssumeGlobalActorWithMarkedAsConcurrent() {
566567
func test(_ fn: @MainActor () async -> Void) {}
567568

568569
// CHECK-LABEL: sil private [ossa] @$s21attr_execution_silgen55testClosuresDontAssumeGlobalActorWithMarkedAsConcurrentyyFyyYaYbXEfU_
569-
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
570+
// CHECK: [[GENERIC_EXECUTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
570571
// CHECK-NEXT: hop_to_executor [[GENERIC_EXECUTOR]]
571572
// CHECK: } // end sil function '$s21attr_execution_silgen55testClosuresDontAssumeGlobalActorWithMarkedAsConcurrentyyFyyYaYbXEfU_'
572573
test { @Sendable @concurrent in

test/Concurrency/attr_execution/witnesses.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ func testMainActorDispatch<T: P>(t: T) async {
4141
}
4242

4343
// CHECK-LABEL: sil hidden [ossa] @$s9witnesses19testGenericExecutor1tyx_tYaAA1PRzlF : $@convention(thin) @async <T where T : P> (@in_guaranteed T) -> ()
44-
// CHECK: [[CONTEXT_ISOLATION:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
44+
// CHECK: [[CONTEXT_ISOLATION:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
4545
// CHECK-NEXT: hop_to_executor [[CONTEXT_ISOLATION]]
46-
// CHECK-NEXT: [[ISOLATION_ERASED_TO_ACTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
4746
// CHECK-NEXT: [[PROP_WITNESS:%.*]] = witness_method $T, #P.prop!getter : <Self where Self : P> (Self) -> () async -> String : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> @owned String
48-
// CHECK-NEXT: {{.*}} = apply [[PROP_WITNESS]]<T>([[ISOLATION_ERASED_TO_ACTOR]], %0) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> @owned String
47+
// CHECK-NEXT: {{.*}} = apply [[PROP_WITNESS]]<T>([[CONTEXT_ISOLATION]], %0) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> @owned String
4948
// CHECK-NEXT: hop_to_executor [[CONTEXT_ISOLATION]]
50-
// CHECK: [[ISOLATION_ERASED_TO_ACTOR:%.*]] = enum $Optional<any Actor>, #Optional.none!enumelt
51-
// CHECK-NEXT: [[FN_WITNESS:%.*]] = witness_method $T, #P.fn : <Self where Self : P> (Self) -> () async -> () : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> ()
52-
// CHECK-NEXT: {{.*}} = apply [[FN_WITNESS]]<T>([[ISOLATION_ERASED_TO_ACTOR]], %0) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> ()
49+
// CHECK: [[FN_WITNESS:%.*]] = witness_method $T, #P.fn : <Self where Self : P> (Self) -> () async -> () : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> ()
50+
// CHECK-NEXT: {{.*}} = apply [[FN_WITNESS]]<T>([[CONTEXT_ISOLATION]], %0) : $@convention(witness_method: P) @async <τ_0_0 where τ_0_0 : P> (@sil_isolated @sil_implicit_leading_param @guaranteed Optional<any Actor>, @in_guaranteed τ_0_0) -> ()
5351
// CHECK: } // end sil function '$s9witnesses19testGenericExecutor1tyx_tYaAA1PRzlF'
5452
func testGenericExecutor<T: P>(t: T) async {
5553
_ = await t.prop

test/Concurrency/cross_module_let_sil.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import OtherActors
77

88
// CHECK-LABEL: sil hidden [ossa] @$s4test6check1ySi11OtherActors0C11ModuleActorCYaF : $@convention(thin) @async (@guaranteed OtherModuleActor) -> Int {
99
// CHECK: bb0([[SELF:%[0-9]+]] : @guaranteed $OtherModuleActor):
10-
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none
11-
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]] : $Optional<Builtin.Executor>
10+
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<any Actor>, #Optional.none
11+
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]] : $Optional<any Actor>
1212
// CHECK: [[REF:%[0-9]+]] = ref_element_addr [[SELF]] : $OtherModuleActor, #OtherModuleActor.a
1313
// CHECK: hop_to_executor [[SELF]] : $OtherModuleActor
1414
// CHECK-NEXT: load [trivial] [[REF]]
15-
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]] : $Optional<Builtin.Executor>
15+
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]]
1616
// CHECK: } // end sil function '$s4test6check1ySi11OtherActors0C11ModuleActorCYaF'
1717
func check1(_ actor: OtherModuleActor) async -> Int {
1818
return await actor.a
@@ -24,23 +24,23 @@ func check2(_ actor: isolated OtherModuleActor) -> Int {
2424

2525
// CHECK-LABEL: sil hidden [ossa] @$s4test6check3ySi11OtherActors0C11ModuleActorCYaF : $@convention(thin) @async (@guaranteed OtherModuleActor) -> Int {
2626
// CHECK: bb0([[SELF:%[0-9]+]] : @guaranteed $OtherModuleActor):
27-
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none
28-
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]] : $Optional<Builtin.Executor>
27+
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<any Actor>, #Optional.none
28+
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]]
2929
func check3(_ actor: OtherModuleActor) async -> Int {
3030
return actor.b
3131
}
3232

3333
// CHECK-LABEL: sil hidden [ossa] @$s4test6check4y11OtherActors17SomeSendableClassCSgAC0C11ModuleActorCSgYaF : $@convention(thin) @async (@guaranteed Optional<OtherModuleActor>) -> @owned Optional<SomeSendableClass> {
3434
// CHECK: bb0({{%[0-9]+}} : @guaranteed $Optional<OtherModuleActor>):
35-
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<Builtin.Executor>, #Optional.none
36-
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]] : $Optional<Builtin.Executor>
35+
// CHECK: [[GENERIC_EXEC:%.*]] = enum $Optional<any Actor>, #Optional.none
36+
// CHECK-NEXT: hop_to_executor [[GENERIC_EXEC]]
3737
// CHECK: switch_enum {{%[0-9]+}} : $Optional<OtherModuleActor>, case #Optional.some!enumelt: [[SOME:bb[0-9]+]], case #Optional.none!enumelt: {{bb[0-9]+}}
3838

3939
// CHECK: [[SOME]]({{%[0-9]+}} : @owned $OtherModuleActor):
4040
// CHECK: [[REF:%[0-9]+]] = ref_element_addr {{%[0-9]+}} : $OtherModuleActor, #OtherModuleActor.d
4141
// CHECK: hop_to_executor {{%[0-9]+}} : $OtherModuleActor
4242
// CHECK-NEXT: load [copy] [[REF]]
43-
// CHECK: hop_to_executor [[GENERIC_EXEC]] : $Optional<Builtin.Executor>
43+
// CHECK: hop_to_executor [[GENERIC_EXEC]]
4444
// CHECK: } // end sil function '$s4test6check4y11OtherActors17SomeSendableClassCSgAC0C11ModuleActorCSgYaF'
4545
func check4(_ actor: OtherModuleActor?) async -> SomeSendableClass? {
4646
return await actor?.d

test/Concurrency/isolated_default_argument_eval.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ func mainActorMultiDefaultArg(x: Int = requiresMainActor(),
2727

2828
// CHECK-LABEL: sil hidden [ossa] @$s30isolated_default_argument_eval22nonisolatedAsyncCalleryyYaF
2929
func nonisolatedAsyncCaller() async {
30-
// CHECK: hop_to_executor {{.*}} : $Optional<Builtin.Executor>
30+
// CHECK: hop_to_executor {{.*}}
3131
// CHECK: hop_to_executor {{.*}} : $MainActor
3232
// CHECK: [[GET_VALUE:%[0-9]+]] = function_ref @$s30isolated_default_argument_eval19mainActorDefaultArg5valueS2i_tFfA_
3333
// CHECK-NEXT: apply [[GET_VALUE]]()
34-
// CHECK: hop_to_executor {{.*}} : $Optional<Builtin.Executor>
34+
// CHECK: hop_to_executor {{.*}}
3535
await mainActorDefaultArg()
3636

3737
// CHECK: hop_to_executor {{.*}} : $MainActor
@@ -46,7 +46,7 @@ func nonisolatedAsyncCaller() async {
4646
// CHECK-NOT: hop_to_executor
4747
// CHECK: [[GET_Z:%[0-9]+]] = function_ref @$s30isolated_default_argument_eval24mainActorMultiDefaultArg1x1y5tuple1zySi_S2i_SitSitFfA2_
4848
// CHECK-NEXT: apply [[GET_Z]]()
49-
// CHECK: hop_to_executor {{.*}} : $Optional<Builtin.Executor>
49+
// CHECK: hop_to_executor {{.*}}
5050
await mainActorMultiDefaultArg()
5151
}
5252

@@ -57,7 +57,7 @@ var argValue: Int { 0 }
5757

5858
// CHECK-LABEL: sil hidden [ossa] @$s30isolated_default_argument_eval20passInoutWithDefaultyyYaF
5959
func passInoutWithDefault() async {
60-
// CHECK: hop_to_executor {{.*}} : $Optional<Builtin.Executor>
60+
// CHECK: hop_to_executor {{.*}}
6161

6262
var x = 0
6363

@@ -69,7 +69,7 @@ func passInoutWithDefault() async {
6969
// CHECK-NEXT: [[Z:%[0-9]+]] = apply [[GET_Z]]()
7070
// CHECK: [[FN:%[0-9]+]] = function_ref @$s30isolated_default_argument_eval0A15DefaultInoutMix1x1y1zySiz_S2itF : $@convention(thin) (@inout Int, Int, Int) -> ()
7171
// CHECK: apply [[FN]]([[INOUT_X]], [[ARG_VALUE]], [[Z]])
72-
// CHECK: hop_to_executor {{.*}} : $Optional<Builtin.Executor>
72+
// CHECK: hop_to_executor {{.*}}
7373
await isolatedDefaultInoutMix(x: &x, y: argValue)
7474
}
7575

test/IRGen/typed_throws_abi.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,7 @@ func callNonMatching_f1(_ b: Bool) -> (Int, Float, Bool, Float) {
31073107
// CHECK: [[SUCCESS]]:
31083108
// CHECK: call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr {{%.*}}, i1 false, ptr @"$s16typed_throws_abi20nonMatching_f0_asyncySf_SftSbYaAA7OneWordVYKF{{.*}}", ptr {{%.*}}, ptr {{%.*}}, float 1.000000e+00, float 2.000000e+00, i64 undef, ptr null)
31093109
// CHECK: unreachable
3110-
// CHECK: 18:
3110+
// CHECK: [[ERROR]]:
31113111
// CHECK: [[ERROR_X:%.*]] = call swiftcc i64 @"$s16typed_throws_abi7OneWordVACycfC"()
31123112
// CHECK: [[ERROR_RET:%.*]] = insertvalue { float, float, i64 } undef, i64 [[ERROR_X]], 2
31133113
// CHECK: [[ERROR_RET0:%.*]] = extractvalue { float, float, i64 } [[ERROR_RET]], 0

test/SILGen/async_builtins.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// REQUIRES: concurrency
33

44
import Swift
5+
import _Concurrency
56

67
public struct X {
78
// CHECK-LABEL: sil hidden [ossa] @$s4test1XV14getCurrentTaskBoyYaF

0 commit comments

Comments
 (0)