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