|
| 1 | +// RUN: %target-swift-frontend -parse-as-library -O -module-name=test %s -emit-sil -enable-experimental-feature IsolatedDeinit > ~/foo.sil |
| 2 | +// RUN: cat ~/foo.sil | %FileCheck %s |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | + |
| 5 | +@globalActor actor AnotherActor: GlobalActor { |
| 6 | + static let shared = AnotherActor() |
| 7 | +} |
| 8 | + |
| 9 | +final class Inner {} |
| 10 | + |
| 11 | +final class IsolatedDeinit { |
| 12 | + var inner: Inner? |
| 13 | + @AnotherActor deinit {} |
| 14 | +} |
| 15 | + |
| 16 | +final class Container { |
| 17 | + var ref: IsolatedDeinit? |
| 18 | +} |
| 19 | + |
| 20 | +// CHECK-LABEL: sil [noinline] {{.*}}@$s4test0A16ContainerOutsideyyF : $@convention(thin) () -> () { |
| 21 | +// CHECK: [[C:%.*]] = alloc_ref [bare] [stack] $Container |
| 22 | +// CHECK: [[ID:%.*]] = alloc_ref $IsolatedDeinit |
| 23 | +// CHECK: dealloc_stack_ref [[C]] : $Container |
| 24 | +// CHECK: return |
| 25 | +@inline(never) |
| 26 | +public func testContainerOutside() { |
| 27 | + // container can be promoted |
| 28 | + let container = Container() |
| 29 | + let obj = IsolatedDeinit() |
| 30 | + container.ref = obj |
| 31 | +} |
| 32 | + |
| 33 | +// CHECK-LABEL: sil [noinline] @$s4test0A15ContainerInsideyyF : $@convention(thin) () -> () { |
| 34 | +// CHECK: [[D:%.*]] = alloc_ref $IsolatedDeinit |
| 35 | +// CHECK: [[C:%.*]] = alloc_ref [bare] [stack] $Container |
| 36 | +// CHECK: dealloc_stack_ref [[C]] : $Container |
| 37 | +// CHECK: return |
| 38 | +@inline(never) |
| 39 | +public func testContainerInside() { |
| 40 | + let obj = IsolatedDeinit() |
| 41 | + // container can be promoted |
| 42 | + let container = Container() |
| 43 | + container.ref = obj |
| 44 | +} |
| 45 | + |
| 46 | +// CHECK-LABEL: sil [noinline] @$s4test0A12InnerOutsideyyF : $@convention(thin) () -> () { |
| 47 | +// CHECK: [[I:%.*]] = alloc_ref $Inner |
| 48 | +// CHECK: [[D:%.*]] = alloc_ref $IsolatedDeinit |
| 49 | +// CHECK: [[DI:%.*]] = end_init_let_ref [[D]] : $IsolatedDeinit |
| 50 | +// CHECK: strong_release [[DI]] : $IsolatedDeinit |
| 51 | +// CHECK: return |
| 52 | +@inline(never) |
| 53 | +public func testInnerOutside() { |
| 54 | + // inner cannot be promoted, because it escapes to isolated deinit |
| 55 | + let inner = Inner() |
| 56 | + let obj = IsolatedDeinit() |
| 57 | + obj.inner = inner |
| 58 | +} |
| 59 | + |
| 60 | +// CHECK-LABEL: sil [noinline] @$s4test0A11InnerInsideyyF : $@convention(thin) () -> () { |
| 61 | +// CHECK: [[D:%.*]] = alloc_ref $IsolatedDeinit |
| 62 | +// CHECK: [[DI:%.*]] = end_init_let_ref [[D]] : $IsolatedDeinit |
| 63 | +// CHECK: [[I:%.*]] = alloc_ref $Inner |
| 64 | +// CHECK: strong_release [[DI]] : $IsolatedDeinit |
| 65 | +// CHECK: return |
| 66 | +@inline(never) |
| 67 | +public func testInnerInside() { |
| 68 | + let obj = IsolatedDeinit() |
| 69 | + // inner cannot be promoted, because it escapes to isolated deinit |
| 70 | + let inner = Inner() |
| 71 | + obj.inner = inner |
| 72 | +} |
0 commit comments