|
| 1 | +// RUN: %target-swift-frontend -swift-version 6 -emit-silgen -enable-experimental-feature UnspecifiedMeansMainActorIsolated %s | %FileCheck %s |
| 2 | +// RUN: %target-swift-frontend -swift-version 6 -emit-sil -enable-experimental-feature UnspecifiedMeansMainActorIsolated %s -verify |
| 3 | + |
| 4 | +// READ THIS! This test is meant to FileCheck the specific isolation when |
| 5 | +// UnspecifiedMeansMainActorIsolated is enabled. Please do not put other types |
| 6 | +// of tests in here. |
| 7 | + |
| 8 | +class Klass { |
| 9 | + // Implicit deinit |
| 10 | + // CHECK: // Klass.deinit |
| 11 | + // CHECK-NEXT: // Isolation: nonisolated |
| 12 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor5KlassCfd : $@convention(method) (@guaranteed Klass) -> @owned Builtin.NativeObject { |
| 13 | + |
| 14 | + // Implicit deallocating deinit |
| 15 | + // CHECK: // Klass.__deallocating_deinit |
| 16 | + // CHECK-NEXT: // Isolation: nonisolated |
| 17 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor5KlassCfD : $@convention(method) (@owned Klass) -> () { |
| 18 | + |
| 19 | + // Implicit allocating init |
| 20 | + // CHECK: // Klass.__allocating_init() |
| 21 | + // CHECK-NEXT: // Isolation: nonisolated |
| 22 | + // CHECK-NEXT: sil hidden [exact_self_class] [ossa] @$s16assume_mainactor5KlassCACycfC : $@convention(method) (@thick Klass.Type) -> @owned Klass { |
| 23 | + |
| 24 | + // Implicit designated init |
| 25 | + // CHECK: // Klass.init() |
| 26 | + // CHECK-NEXT: // Isolation: nonisolated |
| 27 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor5KlassCACycfc : $@convention(method) (@owned Klass) -> @owned Klass { |
| 28 | +} |
| 29 | + |
| 30 | +struct StructContainingKlass { |
| 31 | + // CHECK: // variable initialization expression of StructContainingKlass.k |
| 32 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 33 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor21StructContainingKlassV1kAA0E0Cvpfi : $@convention(thin) () -> @owned Klass { |
| 34 | + |
| 35 | + // CHECK: // StructContainingKlass.k.getter |
| 36 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 37 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor21StructContainingKlassV1kAA0E0Cvg : $@convention(method) (@guaranteed StructContainingKlass) -> @owned Klass { |
| 38 | + |
| 39 | + // CHECK: // StructContainingKlass.k.setter |
| 40 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 41 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor21StructContainingKlassV1kAA0E0Cvs : $@convention(method) (@owned Klass, @inout StructContainingKlass) -> () { |
| 42 | + var k = Klass() |
| 43 | + |
| 44 | + // CHECK: // StructContainingKlass.init() |
| 45 | + // CHECK-NEXT: // Isolation: nonisolated |
| 46 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor21StructContainingKlassVACycfC : $@convention(method) (@thin StructContainingKlass.Type) -> @owned StructContainingKlass { |
| 47 | +} |
| 48 | + |
| 49 | +// TODO: Allow for nonisolated to be applied to structs. |
| 50 | +struct NonIsolatedStructContainingKlass { |
| 51 | + // CHECK: // variable initialization expression of NonIsolatedStructContainingKlass.k |
| 52 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 53 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor32NonIsolatedStructContainingKlassV1kAA0G0Cvpfi : $@convention(thin) () -> @owned Klass { |
| 54 | + |
| 55 | + // CHECK: // NonIsolatedStructContainingKlass.k.getter |
| 56 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 57 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor32NonIsolatedStructContainingKlassV1kAA0G0Cvg : $@convention(method) (@guaranteed NonIsolatedStructContainingKlass) -> @owned Klass { |
| 58 | + |
| 59 | + // CHECK: // NonIsolatedStructContainingKlass.k.setter |
| 60 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 61 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor32NonIsolatedStructContainingKlassV1kAA0G0Cvs : $@convention(method) (@owned Klass, @inout NonIsolatedStructContainingKlass) -> () { |
| 62 | + var k = Klass() |
| 63 | + |
| 64 | + // CHECK: // NonIsolatedStructContainingKlass.init() |
| 65 | + // CHECK-NEXT: // Isolation: nonisolated |
| 66 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor32NonIsolatedStructContainingKlassVACycfC : $@convention(method) (@thin NonIsolatedStructContainingKlass.Type) -> @owned NonIsolatedStructContainingKlass { |
| 67 | +} |
| 68 | + |
| 69 | +@globalActor |
| 70 | +actor CustomActor { |
| 71 | + static let shared = CustomActor() |
| 72 | +} |
| 73 | + |
| 74 | +// CHECK: // unspecifiedAsync<A>(_:) |
| 75 | +// CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 76 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor16unspecifiedAsyncyyxYalF : $@convention(thin) @async <T> (@in_guaranteed T) -> () { |
| 77 | +func unspecifiedAsync<T>(_ t: T) async {} |
| 78 | + |
| 79 | +// CHECK: // nonisolatedAsync<A>(_:) |
| 80 | +// CHECK-NEXT: // Isolation: nonisolated |
| 81 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor16nonisolatedAsyncyyxYalF : $@convention(thin) @async <T> (@in_guaranteed T) -> () { |
| 82 | +nonisolated func nonisolatedAsync<T>(_ t: T) async {} |
| 83 | + |
| 84 | +// CHECK: // mainActorAsync<A>(_:) |
| 85 | +// CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 86 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor14mainActorAsyncyyxYalF : $@convention(thin) @async <T> (@in_guaranteed T) -> () { |
| 87 | +@MainActor func mainActorAsync<T>(_ t: T) async {} |
| 88 | + |
| 89 | +// CHECK: // customActorAsync<A>(_:) |
| 90 | +// CHECK-NEXT: // Isolation: global_actor. type: CustomActor |
| 91 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor16customActorAsyncyyxYalF : $@convention(thin) @async <T> (@in_guaranteed T) -> () { |
| 92 | +@CustomActor func customActorAsync<T>(_ t: T) async {} |
| 93 | + |
| 94 | + |
| 95 | +@CustomActor |
| 96 | +struct CustomActorStruct { |
| 97 | + // Variable expression is custom actor... but since we have a nonisolated |
| 98 | + // init, we should be fine? |
| 99 | + // |
| 100 | + // CHECK: // variable initialization expression of CustomActorStruct.k |
| 101 | + // CHECK-NEXT: // Isolation: global_actor. type: CustomActor |
| 102 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor17CustomActorStructV1kAA5KlassCvpfi : $@convention(thin) () -> @owned Klass { |
| 103 | + |
| 104 | + // CHECK: // CustomActorStruct.k.getter |
| 105 | + // CHECK-NEXT: // Isolation: global_actor. type: CustomActor |
| 106 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor17CustomActorStructV1kAA5KlassCvg : $@convention(method) (@guaranteed CustomActorStruct) -> @owned Klass { |
| 107 | + |
| 108 | + // CHECK: // CustomActorStruct.k.setter |
| 109 | + // CHECK-NEXT: // Isolation: global_actor. type: CustomActor |
| 110 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor17CustomActorStructV1kAA5KlassCvs : $@convention(method) (@owned Klass, @inout CustomActorStruct) -> () { |
| 111 | + var k = Klass() |
| 112 | +} |
| 113 | + |
| 114 | +// CHECK: // unspecifiedFunctionTest() |
| 115 | +// CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 116 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor23unspecifiedFunctionTestyyYaF : $@convention(thin) @async () -> () { |
| 117 | +func unspecifiedFunctionTest() async { |
| 118 | + let k = Klass() |
| 119 | + await unspecifiedAsync(k) |
| 120 | + await nonisolatedAsync(k) |
| 121 | + await mainActorAsync(k) |
| 122 | +} |
| 123 | + |
| 124 | +// CHECK: // unspecifiedFunctionTest2() |
| 125 | +// CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 126 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor24unspecifiedFunctionTest2yyYaF : $@convention(thin) @async () -> () { |
| 127 | +func unspecifiedFunctionTest2() async { |
| 128 | + let k = StructContainingKlass() |
| 129 | + await unspecifiedAsync(k) |
| 130 | + await nonisolatedAsync(k) |
| 131 | + await mainActorAsync(k) |
| 132 | + |
| 133 | + await unspecifiedAsync(k.k) |
| 134 | + await nonisolatedAsync(k.k) |
| 135 | + await mainActorAsync(k.k) |
| 136 | +} |
| 137 | + |
| 138 | +// CHECK: // unspecifiedFunctionTest3() |
| 139 | +// CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 140 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor24unspecifiedFunctionTest3yyYaF : $@convention(thin) @async () -> () { |
| 141 | +func unspecifiedFunctionTest3() async { |
| 142 | + let k = NonIsolatedStructContainingKlass() |
| 143 | + await unspecifiedAsync(k) |
| 144 | + await nonisolatedAsync(k) |
| 145 | + await mainActorAsync(k) |
| 146 | + |
| 147 | + await unspecifiedAsync(k.k) |
| 148 | + await nonisolatedAsync(k.k) |
| 149 | + await mainActorAsync(k.k) |
| 150 | +} |
| 151 | + |
| 152 | +// CHECK: // nonisolatedFunctionTest() |
| 153 | +// CHECK-NEXT: // Isolation: nonisolated |
| 154 | +// CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor23nonisolatedFunctionTestyyYaF : $@convention(thin) @async () -> () { |
| 155 | +nonisolated func nonisolatedFunctionTest() async { |
| 156 | + let k = NonIsolatedStructContainingKlass() |
| 157 | + await unspecifiedAsync(k.k) |
| 158 | + await nonisolatedAsync(k.k) |
| 159 | + await mainActorAsync(k.k) |
| 160 | +} |
| 161 | + |
| 162 | +actor MyActor { |
| 163 | + // CHECK: // variable initialization expression of MyActor.k |
| 164 | + // CHECK-NEXT: // Isolation: actor_instance |
| 165 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor7MyActorC1kAA5KlassCvpfi : $@convention(thin) () -> @owned Klass { |
| 166 | + |
| 167 | + // CHECK: // MyActor.k.getter |
| 168 | + // CHECK-NEXT: // Isolation: actor_instance. name: 'self' |
| 169 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor7MyActorC1kAA5KlassCvg : $@convention(method) (@sil_isolated @guaranteed MyActor) -> @owned Klass { |
| 170 | + |
| 171 | + // CHECK: // MyActor.k.setter |
| 172 | + // CHECK-NEXT: // Isolation: actor_instance. name: 'self' |
| 173 | + // CHECK-NEXT: sil hidden [transparent] [ossa] @$s16assume_mainactor7MyActorC1kAA5KlassCvs : $@convention(method) (@owned Klass, @sil_isolated @guaranteed MyActor) -> () { |
| 174 | + var k = Klass() |
| 175 | + |
| 176 | + // Implicit deinit |
| 177 | + // CHECK: // MyActor.deinit |
| 178 | + // CHECK-NEXT: // Isolation: nonisolated |
| 179 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor7MyActorCfd : $@convention(method) (@guaranteed MyActor) -> @owned Builtin.NativeObject { |
| 180 | + |
| 181 | + // Non-async init should be nonisolated |
| 182 | + // CHECK: // MyActor.init() |
| 183 | + // CHECK-NEXT: // Isolation: nonisolated |
| 184 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor7MyActorCACycfc : $@convention(method) (@owned MyActor) -> @owned MyActor { |
| 185 | +} |
| 186 | + |
| 187 | +actor MyActor2 { |
| 188 | + // CHECK: // MyActor2.init() |
| 189 | + // CHECK-NEXT: // Isolation: global_actor. type: MainActor |
| 190 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor8MyActor2CACycfc : $@convention(method) (@owned MyActor2) -> @owned MyActor2 { |
| 191 | + @MainActor |
| 192 | + init() {} |
| 193 | + |
| 194 | + // CHECK: // MyActor2.init(x:) |
| 195 | + // CHECK-NEXT: // Isolation: global_actor. type: CustomActor |
| 196 | + // CHECK-NEXT: sil hidden [ossa] @$s16assume_mainactor8MyActor2C1xACyt_tcfc : $@convention(method) (@owned MyActor2) -> @owned MyActor2 { |
| 197 | + @CustomActor |
| 198 | + init(x: ()) {} |
| 199 | +} |
0 commit comments