|
1 |
| -// RUN: %target-swift-frontend -O -primary-file %s -emit-sil -enable-experimental-distributed | %FileCheck %s |
| 1 | +// RUN: %target-swift-frontend -module-name test -primary-file %s -emit-sil -enable-experimental-distributed | %FileCheck %s --enable-var-scope --dump-input=fail --implicit-check-not=actorReady --implicit-check-not=resignIdentity --implicit-check-not=hop_to_executor |
2 | 2 | // REQUIRES: concurrency
|
3 | 3 | // REQUIRES: distributed
|
4 | 4 |
|
5 | 5 | import _Distributed
|
6 | 6 |
|
7 |
| -@available(SwiftStdlib 5.5, *) |
8 |
| -distributed actor SimpleEmptyDistributedActor { |
| 7 | +class SomeClass {} |
| 8 | + |
| 9 | +@available(macOS 12, *) |
| 10 | +distributed actor MyDistActor { |
| 11 | + var localOnlyField: SomeClass |
| 12 | + |
| 13 | + init(transport_sync: ActorTransport) { |
| 14 | + self.localOnlyField = SomeClass() |
| 15 | + } |
| 16 | + |
| 17 | +// CHECK-LABEL: sil hidden{{.*}} @$s4test11MyDistActorC14transport_syncAC12_Distributed0D9Transport_p_tcfc : $@convention(method) (@in ActorTransport, @owned MyDistActor) -> @owned MyDistActor { |
| 18 | +// CHECK: bb0([[TPORT:%[0-9]+]] : $*ActorTransport, [[SELF:%[0-9]+]] : $MyDistActor): |
| 19 | +// CHECK: builtin "initializeDefaultActor"([[SELF]] : $MyDistActor) |
| 20 | + // *** save transport *** |
| 21 | +// CHECK: [[TP_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorTransport |
| 22 | +// CHECK: copy_addr [[TPORT]] to [initialization] [[TP_FIELD]] : $*ActorTransport // id: %6 |
| 23 | + // *** obtain an identity *** |
| 24 | +// CHECK: [[TPORT_OPEN:%[0-9]+]] = open_existential_addr immutable_access [[TPORT]] |
| 25 | +// CHECK: [[SELF_METATYPE:%[0-9]+]] = metatype $@thick MyDistActor.Type |
| 26 | +// CHECK: [[ASSIGN_ID_FN:%[0-9]+]] = witness_method $@opened({{.*}}) ActorTransport, #ActorTransport.assignIdentity : <Self where Self : ActorTransport><Act where Act : DistributedActor> (Self) -> (Act.Type) -> AnyActorIdentity, [[TPORT_OPEN]] |
| 27 | +// CHECK: [[ID_STACK:%[0-9+]+]] = alloc_stack $AnyActorIdentity |
| 28 | +// CHECK: = apply [[ASSIGN_ID_FN]]<@opened({{.*}}) ActorTransport, MyDistActor>([[ID_STACK]], [[SELF_METATYPE]], [[TPORT_OPEN]]) |
| 29 | + // *** save identity *** |
| 30 | +// CHECK: [[ID_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.id |
| 31 | +// CHECK: copy_addr [[ID_STACK]] to [initialization] [[ID_FIELD]] : $*AnyActorIdentity |
| 32 | + // *** save user-defined property *** |
| 33 | +// CHECK: store {{%[0-9]+}} to {{%[0-9]+}} : $*SomeClass |
| 34 | + // *** invoke actorReady *** |
| 35 | +// CHECK: [[TPORT_OPEN:%[0-9]+]] = open_existential_addr immutable_access [[TPORT]] |
| 36 | +// CHECK: [[READY_FN:%[0-9]+]] = witness_method $@opened({{.*}}) ActorTransport, #ActorTransport.actorReady : <Self where Self : ActorTransport><Act where Act : DistributedActor> (Self) -> (Act) -> (), [[TPORT_OPEN]] |
| 37 | +// CHECK: = apply [[READY_FN]]<@opened({{.*}}) ActorTransport, MyDistActor>([[SELF]], [[TPORT_OPEN]]) |
| 38 | + // *** clean-ups *** |
| 39 | +// CHECK: dealloc_stack [[ID_STACK]] : $*AnyActorIdentity |
| 40 | +// CHECK: destroy_addr [[TPORT]] : $*ActorTransport |
| 41 | +// CHECK: return [[SELF]] : $MyDistActor |
| 42 | +// CHECK: } // end sil function '$s4test11MyDistActorC14transport_syncAC12_Distributed0D9Transport_p_tcfc' |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + init?(transport_sync_fail: ActorTransport, cond: Bool) { |
| 47 | + guard cond else { return nil } |
| 48 | + self.localOnlyField = SomeClass() |
| 49 | + } |
| 50 | + |
| 51 | +// CHECK-LABEL: sil hidden{{.*}} @$s4test11MyDistActorC19transport_sync_fail4condACSg12_Distributed0D9Transport_p_Sbtcfc : $@convention(method) (@in ActorTransport, Bool, @owned MyDistActor) -> @owned Optional<MyDistActor> { |
| 52 | +// CHECK: bb0([[TPORT:%[0-9]+]] : $*ActorTransport, [[COND:%[0-9]+]] : $Bool, [[SELF:%[0-9]+]] : $MyDistActor): |
| 53 | +// CHECK: builtin "initializeDefaultActor"([[SELF]] : $MyDistActor) |
| 54 | +// CHECK: [[TPORT_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorTransport |
| 55 | +// CHECK: copy_addr [[TPORT]] to [initialization] [[TPORT_FIELD]] : $*ActorTransport |
| 56 | +// CHECK: [[ID_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.id |
| 57 | +// CHECK: copy_addr {{%[0-9]+}} to [initialization] [[ID_FIELD]] : $*AnyActorIdentity |
| 58 | +// CHECK: [[RAW_BOOL:%[0-9]+]] = struct_extract [[COND]] : $Bool, #Bool._value |
| 59 | +// CHECK: cond_br [[RAW_BOOL]], [[SUCCESS_BB:bb[0-9]+]], [[FAIL_BB:bb[0-9]+]] |
| 60 | + |
| 61 | +// CHECK: [[SUCCESS_BB]]: |
| 62 | +// CHECK: [[READY_FN:%[0-9]+]] = witness_method $@opened({{.*}}) ActorTransport, #ActorTransport.actorReady |
| 63 | +// CHECK: = apply [[READY_FN]] |
| 64 | +// CHECK: br [[RET_BB:bb[0-9]+]] |
| 65 | + |
| 66 | +// CHECK: [[FAIL_BB]]: |
| 67 | +// CHECK: builtin "destroyDefaultActor" |
| 68 | +// CHECK: br [[RET_BB]] |
| 69 | + |
| 70 | +// CHECK: [[RET_BB]]({{%[0-9]+}} : $Optional<MyDistActor>): |
| 71 | +// CHECK: return |
| 72 | +// CHECK: } // end sil function '$s4test11MyDistActorC19transport_sync_fail4condACSg12_Distributed0D9Transport_p_Sbtcfc' |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + init(transport_async: ActorTransport, cond: Bool) async { |
| 77 | + if cond { |
| 78 | + self.localOnlyField = SomeClass() |
| 79 | + } |
| 80 | + self.localOnlyField = SomeClass() |
| 81 | + } |
| 82 | + |
| 83 | +// CHECK-LABEL: sil hidden{{.*}} @$s4test11MyDistActorC15transport_async4condAC12_Distributed0D9Transport_p_SbtYacfc : $@convention(method) @async (@in ActorTransport, Bool, @owned MyDistActor) -> @owned MyDistActor { |
| 84 | +// CHECK: bb0([[TPORT:%[0-9]+]] : $*ActorTransport, [[COND:%[0-9]+]] : $Bool, [[SELF:%[0-9]+]] : $MyDistActor): |
| 85 | +// CHECK: builtin "initializeDefaultActor"([[SELF]] : $MyDistActor) |
| 86 | +// CHECK: [[TPORT_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorTransport |
| 87 | +// CHECK: copy_addr [[TPORT]] to [initialization] [[TPORT_FIELD]] : $*ActorTransport |
| 88 | +// CHECK: [[ID_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.id |
| 89 | +// CHECK: copy_addr {{%[0-9]+}} to [initialization] [[ID_FIELD]] : $*AnyActorIdentity |
| 90 | +// CHECK: [[RAW_BOOL:%[0-9]+]] = struct_extract [[COND]] : $Bool, #Bool._value |
| 91 | +// CHECK: cond_br [[RAW_BOOL]], [[TRUE_BB:bb[0-9]+]], [[FALSE_BB:bb[0-9]+]] |
| 92 | + |
| 93 | +// CHECK: [[TRUE_BB]]: |
| 94 | +// CHECK: hop_to_executor [[SELF]] : $MyDistActor |
| 95 | +// CHECK-NEXT: open_existential_addr immutable_access {{%[0-9]+}} : $*ActorTransport |
| 96 | +// CHECK-NEXT: [[READY_FN:%[0-9]+]] = witness_method $@opened({{.*}}) ActorTransport, #ActorTransport.actorReady |
| 97 | +// CHECK-NEXT: = apply [[READY_FN]] |
| 98 | +// CHECK: br [[JOIN:bb[0-9]+]] |
| 99 | + |
| 100 | +// CHECK: [[FALSE_BB]]: |
| 101 | +// CHECK: br [[JOIN]] |
| 102 | + |
| 103 | +// CHECK: [[JOIN]]: |
| 104 | +// CHECK: cond_br {{%[0-9]+}}, [[PARTIAL_DEINIT:bb[0-9]+]], [[NO_DEINIT:bb[0-9]+]] |
| 105 | + |
| 106 | +// CHECK: [[PARTIAL_DEINIT]]: |
| 107 | +// CHECK: destroy_addr {{.*}} : $*SomeClass |
| 108 | +// CHECK: br [[CONTINUE:bb[0-9]+]] |
| 109 | + |
| 110 | +// CHECK: [[NO_DEINIT]]: |
| 111 | +// CHECK: br [[CONTINUE]] |
| 112 | + |
| 113 | +// CHECK: [[CONTINUE]]: |
| 114 | +// CHECK: hop_to_executor [[SELF]] : $MyDistActor |
| 115 | +// CHECK-NEXT: open_existential_addr immutable_access {{%[0-9]+}} : $*ActorTransport |
| 116 | +// CHECK-NEXT: [[READY_FN:%[0-9]+]] = witness_method $@opened({{.*}}) ActorTransport, #ActorTransport.actorReady |
| 117 | +// CHECK-NEXT: = apply [[READY_FN]] |
| 118 | +// CHECK: return |
| 119 | +// CHECK: } // end sil function '$s4test11MyDistActorC15transport_async4condAC12_Distributed0D9Transport_p_SbtYacfc' |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | +// Acknowledge that the deinit has an actorReady call. We cover deinits more in another test. |
| 124 | +// CHECK-LABEL: sil hidden{{.*}} @$s4test11MyDistActorCfd : $@convention(method) (@guaranteed MyDistActor) -> @owned Builtin.NativeObject { |
| 125 | +// CHECK: #ActorTransport.resignIdentity |
| 126 | +// CHECK: } // end sil function '$s4test11MyDistActorCfd' |
| 127 | + |
| 128 | + |
9 | 129 | }
|
10 | 130 |
|
11 |
| -// CHECK: // SimpleEmptyDistributedActor.init(transport:) |
12 |
| -// CHECK: sil hidden{{.*}} @$s34distributed_actor_default_init_sil27SimpleEmptyDistributedActorC9transportAC01_H00I9Transport_p_tcfc : $@convention(method) (@in ActorTransport, @owned SimpleEmptyDistributedActor) -> @owned SimpleEmptyDistributedActor { |
13 |
| -// CHECK: // %0 "transport" // users: %15, %7, %6, %2 |
14 |
| -// CHECK: // %1 "self" // users: %5, %12, %4, %16, %3 |
15 |
| -// CHECK: bb0(%0 : $*ActorTransport, %1 : $SimpleEmptyDistributedActor): |
16 |
| -// CHECK: debug_value %0 : $*ActorTransport, let, name "transport", argno 1, implicit, expr op_deref // id: %2 |
17 |
| -// CHECK: debug_value %1 : $SimpleEmptyDistributedActor, let, name "self", argno 2, implicit // id: %3 |
18 |
| -// CHECK: %4 = builtin "initializeDefaultActor"(%1 : $SimpleEmptyDistributedActor) : $() |
19 |
| - |
20 |
| -// Store the transport |
21 |
| -// CHECK: %5 = ref_element_addr %1 : $SimpleEmptyDistributedActor, #SimpleEmptyDistributedActor.actorTransport // user: %6 |
22 |
| -// CHECK: copy_addr %0 to [initialization] %5 : $*ActorTransport // id: %6 |
23 |
| - |
24 |
| -// Assign an identity |
25 |
| -// CHECK: %7 = open_existential_addr immutable_access %0 : $*ActorTransport to $*@opened("{{.*}}") ActorTransport // users: %11, %11, %9 |
26 |
| -// CHECK: %8 = metatype $@thick SimpleEmptyDistributedActor.Type // user: %11 |
27 |
| -// CHECK: %9 = witness_method $@opened("{{.*}}") ActorTransport, #ActorTransport.assignIdentity : <Self where Self : ActorTransport><Act where Act : DistributedActor> (Self) -> (Act.Type) -> AnyActorIdentity, %7 : $*@opened("{{.*}}") ActorTransport : $@convention(witness_method: ActorTransport) <τ_0_0 where τ_0_0 : ActorTransport><τ_1_0 where τ_1_0 : DistributedActor> (@thick τ_1_0.Type, @in_guaranteed τ_0_0) -> @out AnyActorIdentity // type-defs: %7; user: %11 |
28 |
| -// CHECK: %10 = alloc_stack $AnyActorIdentity // users: %14, %13, %11 |
29 |
| -// CHECK: %11 = apply %9<@opened("{{.*}}") ActorTransport, SimpleEmptyDistributedActor>(%10, %8, %7) : $@convention(witness_method: ActorTransport) <τ_0_0 where τ_0_0 : ActorTransport><τ_1_0 where τ_1_0 : DistributedActor> (@thick τ_1_0.Type, @in_guaranteed τ_0_0) -> @out AnyActorIdentity // type-defs: %7 |
30 |
| - |
31 |
| -// Store the identity |
32 |
| -// CHECK: %12 = ref_element_addr %1 : $SimpleEmptyDistributedActor, #SimpleEmptyDistributedActor.id // user: %13 |
33 |
| -// CHECK: copy_addr [take] %10 to [initialization] %12 : $*AnyActorIdentity // id: %13 |
34 |
| - |
35 |
| -// CHECK: dealloc_stack %10 : $*AnyActorIdentity // id: %14 |
36 |
| -// CHECK: destroy_addr %0 : $*ActorTransport // id: %15 |
37 |
| -// CHECK: return %1 : $SimpleEmptyDistributedActor // id: %16 |
38 |
| -// CHECK: } // end sil function '$s34distributed_actor_default_init_sil27SimpleEmptyDistributedActorC9transportAC01_H00I9Transport_p_tcfc' |
| 131 | + |
0 commit comments