You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[region-isolation] Squelch use after transfer if the use has effectively the same isolation as the transfer inst.
To be more specific this means that either:
1. The use is actually isolated to the same actor. This could mean that the
use is global actor isolated to the same function.
2. The use is nonisolated but is executing within a function that is globally
isolated to the same isolation domain.
rdar://123474616
// expected-tns-warning @-2 {{transferring 'ns0' may cause a race}}
130
130
// expected-tns-note @-3 {{transferring disconnected 'ns0' to actor-isolated callee could cause races in between callee actor-isolated and local nonisolated uses}}
131
131
132
+
ifawaitbooleanFlag{
133
+
// This is not an actual use since we are passing values to the same
134
+
// isolation domain.
135
+
await a.useKlass(ns1)
136
+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
137
+
} else {
138
+
closure() // expected-tns-note {{use here could race}}
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
155
+
// expected-tns-warning @-2 {{transferring 'ns0' may cause a race}}
156
+
// expected-tns-note @-3 {{transferring disconnected 'ns0' to actor-isolated callee could cause races in between callee actor-isolated and local nonisolated uses}}
157
+
132
158
// We only emit a warning on the first use we see, so make sure we do both
133
-
// klass and the closure.
159
+
// the print and the closure.
134
160
ifawaitbooleanFlag{
135
-
await a.useKlass(ns1) // expected-tns-note {{use here could race}}
161
+
// This is an actual use since a2 is a different actor from a1
162
+
await a2.useKlass(ns1)
136
163
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
137
164
} else {
138
165
closure() // expected-tns-note {{use here could race}}
awaittransferToMain(test) // expected-tns-warning {{transferring 'test' may cause a race}}
1184
1212
// expected-tns-note @-1 {{transferring disconnected 'test' to main actor-isolated callee could cause races in between callee main actor-isolated and local nonisolated uses}}
1185
-
// expected-tns-note @-2 {{use here could race}}
1186
-
// expected-complete-warning @-3 {{passing argument of non-sendable type 'StructFieldTests' into main actor-isolated context may introduce data races}}
1187
-
test =StructFieldTests()
1213
+
// expected-complete-warning @-2 {{passing argument of non-sendable type 'StructFieldTests' into main actor-isolated context may introduce data races}}
1214
+
1215
+
// This is treated as a use since test is in box form and is mutable. So we
1216
+
// treat assignment as a merge.
1217
+
test =StructFieldTests() // expected-tns-note {{use here could race}}
Copy file name to clipboardExpand all lines: test/Concurrency/transfernonsendable_global_actor_transferring.swift
+2-3Lines changed: 2 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -27,9 +27,8 @@ func useValue<T>(_ t: T) {}
27
27
28
28
// Will be resolved once @MainActor is @Sendable
29
29
Task.fakeInit{@MainActorin // expected-error {{main actor-isolated value of type '@MainActor () async -> ()' passed as a strongly transferred parameter}}
30
-
print(ns) // expected-error {{transferring 'ns' may cause a race}}
31
-
// expected-note @-1 {{disconnected 'ns' is captured by a main actor-isolated closure. main actor-isolated uses in closure may race against later nonisolated uses}}
30
+
print(ns)
32
31
}
33
32
34
-
useValue(ns) // expected-note {{use here could race}}
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
// expected-warning @-1 {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
805
-
// expected-note @-2 {{use here could race}}
806
807
807
808
fix_lifetime %rawPointer : $Builtin.RawPointer
808
809
// expected-note @-1 {{use here could race}}
810
+
// expected-note @-2 {{use here could race}}
809
811
810
812
end_borrow %valueB : $SendableKlass
811
813
destroy_value %value : $SendableKlass
@@ -1238,7 +1240,8 @@ bb0:
1238
1240
unchecked_ref_cast_addr NonSendableKlass in %a : $*NonSendableKlass to NonSendableKlass in %b : $*NonSendableKlass // expected-note {{use here could race}}
1239
1241
1240
1242
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context}}
1241
-
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{use here could race}}
apply %use<NonSendableKlass>(%b) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{use here could race}}
1242
1245
1243
1246
destroy_addr %b : $*NonSendableKlass
1244
1247
dealloc_stack %b : $*NonSendableKlass
@@ -1264,7 +1267,8 @@ bb0:
1264
1267
unconditional_checked_cast_addr NonSendableKlass in %a : $*NonSendableKlass to NonSendableKlass in %b : $*NonSendableKlass // expected-note {{use here could race}}
1265
1268
1266
1269
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context}}
1267
-
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{use here could race}}
apply %use<NonSendableKlass>(%b) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{use here could race}}
1268
1272
1269
1273
destroy_addr %b : $*NonSendableKlass
1270
1274
dealloc_stack %b : $*NonSendableKlass
@@ -1290,7 +1294,8 @@ bb0:
1290
1294
destroy_value %aValue : $NonSendableKlass
1291
1295
1292
1296
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<@sil_unowned NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context}}
1293
-
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<@sil_unowned NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{use here could race}}
0 commit comments