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