|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift |
| 3 | +// RUN: %target-swift-frontend -module-name default_deinit -primary-file %s -emit-sil -verify -disable-availability-checking -I %t | %FileCheck %s --enable-var-scope --dump-input=fail |
| 4 | +// REQUIRES: concurrency |
| 5 | +// REQUIRES: distributed |
| 6 | + |
| 7 | +/// The convention in this test is that the Swift declaration comes before its FileCheck lines. |
| 8 | + |
| 9 | +import Distributed |
| 10 | +import FakeDistributedActorSystems |
| 11 | + |
| 12 | +/// This actor system is a class, therefore SIL is slightly different |
| 13 | +typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem |
| 14 | + |
| 15 | +// ==== ---------------------------------------------------------------------------------------------------------------- |
| 16 | + |
| 17 | +class SomeClass {} |
| 18 | + |
| 19 | +enum Err : Error { |
| 20 | + case blah |
| 21 | +} |
| 22 | + |
| 23 | +func getSomeClass() throws -> SomeClass { throw Err.blah } |
| 24 | +func getSystem() throws -> FakeRoundtripActorSystem { throw Err.blah } |
| 25 | + |
| 26 | +distributed actor MyDistActor { |
| 27 | + var someField: SomeClass |
| 28 | + |
| 29 | + init() throws { |
| 30 | + do { |
| 31 | + actorSystem = try getSystem() |
| 32 | + } catch { |
| 33 | + actorSystem = FakeRoundtripActorSystem() |
| 34 | + } |
| 35 | + someField = try getSomeClass() |
| 36 | + } |
| 37 | + |
| 38 | +// CHECK: sil hidden @$s14default_deinit11MyDistActorCACyKcfc : $@convention(method) (@owned MyDistActor) -> (@owned MyDistActor, @error any Error) { |
| 39 | +// CHECK: bb0([[SELF:%[0-9]+]] : $MyDistActor): |
| 40 | +// CHECK: builtin "initializeDefaultActor"([[SELF]] : $MyDistActor) |
| 41 | +// CHECK: try_apply {{%[0-9]+}}() : $@convention(thin) () -> (@owned FakeRoundtripActorSystem, @error any Error), normal [[SYSTEM_SUCCESS_BB:bb[0-9]+]], error [[SYSTEM_ERROR_BB:bb[0-9]+]] |
| 42 | + |
| 43 | +// CHECK: [[SYSTEM_SUCCESS_BB]]([[SYSTEM_VAL:%[0-9]+]] : $FakeRoundtripActorSystem): |
| 44 | + // *** save system *** |
| 45 | +// CHECK: [[TP_FIELD1:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorSystem |
| 46 | +// CHECK: store [[SYSTEM_VAL]] to [[TP_FIELD1]] : $*FakeRoundtripActorSystem |
| 47 | + // *** obtain an identity *** |
| 48 | +// CHECK: [[TP_FIELD2:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorSystem |
| 49 | +// CHECK: [[RELOADED_SYS1:%[0-9]+]] = load [[TP_FIELD2]] : $*FakeRoundtripActorSystem |
| 50 | +// CHECK: [[SELF_METATYPE:%[0-9]+]] = metatype $@thick MyDistActor.Type |
| 51 | +// CHECK: strong_retain [[RELOADED_SYS1]] : $FakeRoundtripActorSystem |
| 52 | +// CHECK: [[ASSIGN_ID_FN:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0a9RoundtripC6SystemC8assignIDyAA0C7AddressVxm0B00bC0RzlF |
| 53 | +// CHECK: [[ID:%[0-9]+]] = apply [[ASSIGN_ID_FN]]<MyDistActor>([[SELF_METATYPE]], [[RELOADED_SYS1]]) |
| 54 | +// CHECK: strong_release [[RELOADED_SYS1]] : $FakeRoundtripActorSystem |
| 55 | + // *** save identity *** |
| 56 | +// CHECK: [[ID_FIELD:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.id |
| 57 | +// CHECK: store [[ID]] to [[ID_FIELD]] : $*ActorAddress |
| 58 | +// CHECK-NOT: apply |
| 59 | +// CHECK: br [[JOIN_PT:bb[0-9]+]] |
| 60 | + |
| 61 | +// CHECK: [[JOIN_PT]]: |
| 62 | +// CHECK: try_apply {{.*}}() : $@convention(thin) () -> (@owned SomeClass, @error any Error), normal [[CLASS_SUCCESS_BB:bb[0-9]+]], error [[CLASS_ERROR_BB:bb[0-9]+]] |
| 63 | + |
| 64 | +// CHECK: [[CLASS_SUCCESS_BB]]{{.*}}: |
| 65 | +// CHECK: store {{.*}} to {{.*}} : $*SomeClass |
| 66 | + // *** invoke actorReady *** |
| 67 | +// CHECK: [[TP_FIELD3:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorSystem |
| 68 | +// CHECK: [[RELOADED_SYS2:%[0-9]+]] = load [[TP_FIELD3]] : $*FakeRoundtripActorSystem |
| 69 | +// CHECK: [[READY_FN:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0a9RoundtripC6SystemC10actorReadyyyx0B00bC0RzAA0C7AddressV2IDRtzlF |
| 70 | +// CHECK: = apply [[READY_FN]]<MyDistActor>([[SELF]], [[RELOADED_SYS2]]) |
| 71 | +// CHECK: return [[SELF]] : $MyDistActor |
| 72 | + |
| 73 | +// CHECK: [[SYSTEM_ERROR_BB]]([[ERROR_ARG:%[0-9]+]] : $any Error): |
| 74 | +// CHECK: strong_retain [[ERROR_ARG]] : $any Error |
| 75 | +// CHECK: function_ref @$s27FakeDistributedActorSystems0a9RoundtripC6SystemCACycfC |
| 76 | +// CHECK: store {{.*}} to {{.*}} : $*FakeRoundtripActorSystem |
| 77 | +// CHECK: store {{.*}} to {{.*}} : $*ActorAddress |
| 78 | +// CHECK: br [[JOIN_PT]] |
| 79 | + |
| 80 | +// CHECK: [[CLASS_ERROR_BB]]{{.*}}: |
| 81 | + // ** deinit the id ** |
| 82 | +// CHECK: [[REF_ID_D:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.id |
| 83 | +// CHECK: [[ID_D:%[0-9]+]] = begin_access [deinit] [static] [[REF_ID_D]] : $*ActorAddress |
| 84 | +// CHECK: [[REF_SYS_D:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorSystem |
| 85 | +// CHECK: [[ID:%[0-9]+]] = load [[ID_D]] : $*ActorAddress |
| 86 | +// CHECK: [[SYS:%[0-9]+]] = load [[REF_SYS_D]] : $*FakeRoundtripActorSystem |
| 87 | +// CHECK: [[RESIGN_FN:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0a9RoundtripC6SystemC8resignIDyyAA0C7AddressVF |
| 88 | +// CHECK: = apply [[RESIGN_FN]]([[ID]], [[SYS]]) : $@convention(method) (@guaranteed ActorAddress, @guaranteed FakeRoundtripActorSystem) -> () |
| 89 | +// CHECK: destroy_addr [[ID_D]] : $*ActorAddress |
| 90 | +// CHECK: end_access [[ID_D]] : $*ActorAddress |
| 91 | + // ** deinit the system ** |
| 92 | +// CHECK: [[REF_SYS_D2:%[0-9]+]] = ref_element_addr [[SELF]] : $MyDistActor, #MyDistActor.actorSystem |
| 93 | +// CHECK: [[SYSTEM_ACC:%[0-9]+]] = begin_access [deinit] [static] [[REF_SYS_D2]] : $*FakeRoundtripActorSystem |
| 94 | +// CHECK: destroy_addr [[SYSTEM_ACC]] : $*FakeRoundtripActorSystem |
| 95 | +// CHECK: end_access [[SYSTEM_ACC]] : $*FakeRoundtripActorSystem |
| 96 | +// CHECK: builtin "destroyDefaultActor"([[SELF]] : $MyDistActor) : $() |
| 97 | +// CHECK: dealloc_partial_ref [[SELF]] |
| 98 | +// CHECK: throw |
| 99 | + |
| 100 | + |
| 101 | +} |
| 102 | + |
0 commit comments