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] Teach SIL isolation inference how to infer applies isolation from their callee's isolation.
This fixes a few issues I missed in the past bit of commits.
I need to fix one issue around async let, but I am going to fix it when I do a
sweep across async let.
// expected-note @-1 4 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
251
+
// expected-note @-1 5 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
243
252
// TransferNonSendable emits 3 fewer errors here.
244
-
// expected-targeted-and-complete-note @-3 5 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
253
+
// expected-targeted-and-complete-note @-3 7 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
245
254
// expected-complete-and-tns-note @-4 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
246
255
varvalue=""
247
256
@@ -270,19 +279,52 @@ final class NonSendable {
270
279
271
280
@MainActor
272
281
varx:Int{0}
282
+
283
+
@CustomActor
284
+
vary:Int{0}
285
+
286
+
varz:Int{0}
273
287
}
274
288
289
+
// This is not an error since t.update and t.x are both main actor isolated. We
290
+
// still get the returning main actor-isolated property 'x' error though.
275
291
@available(SwiftStdlib 5.1,*)
276
292
func testNonSendableBaseArg()async{
277
293
lett=NonSendable()
278
294
await t.update()
279
295
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
280
-
// expected-tns-warning @-2 {{sending 't' risks causing data races}}
281
-
// expected-tns-note @-3 {{sending 't' to main actor-isolated instance method 'update()' risks causing data races between main actor-isolated and local nonisolated uses}}
282
296
283
297
_ =await t.x
284
298
// expected-warning @-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to main actor-isolated property 'x' cannot cross actor boundary}}
285
-
// expected-tns-note@-2 {{access can happen concurrently}}
299
+
}
300
+
301
+
// We get the region isolation error here since t.y is custom actor isolated.
302
+
@available(SwiftStdlib 5.1,*)
303
+
func testNonSendableBaseArg2()async{
304
+
lett=NonSendable()
305
+
await t.update()
306
+
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
307
+
// expected-tns-warning @-2 {{sending 't' risks causing data races}}
308
+
// TODO: Improve the diagnostic so that we say custom actor isolated instead since t.y
309
+
// is custom actor isolated.
310
+
// expected-tns-note @-5 {{sending 't' to main actor-isolated instance method 'update()' risks causing data races between main actor-isolated and local nonisolated uses}}
311
+
312
+
_ =await t.y
313
+
// expected-warning @-1 {{non-sendable type 'NonSendable' passed in implicitly asynchronous call to global actor 'CustomActor'-isolated property 'y' cannot cross actor boundary}}
314
+
// expected-tns-note @-2 {{access can happen concurrently}}
315
+
}
316
+
317
+
// We get the region isolation error here since t.z is not isolated.
318
+
@available(SwiftStdlib 5.1,*)
319
+
func testNonSendableBaseArg3()async{
320
+
lett=NonSendable()
321
+
await t.update()
322
+
// expected-targeted-and-complete-warning @-1 {{passing argument of non-sendable type 'NonSendable' into main actor-isolated context may introduce data races}}
323
+
// expected-tns-warning @-2 {{sending 't' risks causing data races}}
324
+
// expected-tns-note @-3 {{sending 't' to main actor-isolated instance method 'update()' risks causing data races between main actor-isolated and local nonisolated uses}}
325
+
326
+
_ = t.z
327
+
// expected-tns-note @-1 {{access can happen concurrently}}
// expected-tns-warning @-1 {{sending 'x' risks causing data races}}
607
609
// expected-tns-note @-2 {{sending global actor 'CustomActor'-isolated 'x' to main actor-isolated global function 'transferToMainDirect' risks causing data races between main actor-isolated and global actor 'CustomActor'-isolated uses}}
608
610
// expected-complete-warning @-3 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
611
+
612
+
letx2= nonIsolatedUnsafeVarObject
613
+
awaittransferToMainDirect(x2)
614
+
// expected-tns-warning @-1 {{sending 'x2' risks causing data races}}
615
+
// expected-tns-note @-2 {{sending global actor 'CustomActor'-isolated 'x2' to main actor-isolated global function 'transferToMainDirect' risks causing data races between main actor-isolated and global actor 'CustomActor'-isolated uses}}
616
+
// expected-complete-warning @-3 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
617
+
618
+
letx3= nonIsolatedUnsafeVarComputedObject
619
+
awaittransferToMainDirect(x3)
620
+
// expected-tns-warning @-1 {{sending 'x3' risks causing data races}}
621
+
// expected-tns-note @-2 {{sending global actor 'CustomActor'-isolated 'x3' to main actor-isolated global function 'transferToMainDirect' risks causing data races between main actor-isolated and global actor 'CustomActor'-isolated uses}}
622
+
// expected-complete-warning @-3 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
// expected-tns-warning @-1 {{sending 'x' risks causing data races}}
630
-
// expected-tns-note @-2 {{sending 'x' to main actor-isolated global function 'transferToMainDirect' risks causing data races between main actor-isolated and local global actor 'CustomActor'-isolated uses}}
645
+
// expected-tns-note @-2 {{sending global actor 'CustomActor'-isolated 'x' to main actor-isolated global function 'transferToMainDirect' risks causing data races between main actor-isolated and global actor 'CustomActor'-isolated uses}}
631
646
// expected-complete-warning @-3 {{passing argument of non-sendable type 'NonSendableKlass' into main actor-isolated context may introduce data races}}
632
-
print(x) // expected-tns-note {{access can happen concurrently}}
0 commit comments