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
Propagate global actor-ness of functions/closures.
I fixed a bunch of small issues around here that resulted in a bunch of radars
being fixed. Specifically:
1. I made it so that we treat function_refs that are from an actor isolated
function as actor isolated instead of sendable.
2. I made it so that autoclosures which return global actor isolated functions
are treated as producing a global actor isolated function.
3. I made it so that we properly handle SILGen code patterns produced by
Sendable GlobalActor isolated things.
rdar://125452372
rdar://121954871
rdar://121955895
rdar://122692698
Copy file name to clipboardExpand all lines: test/Concurrency/isolated_captures.swift
+6-4Lines changed: 6 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -39,9 +39,9 @@ class NotSendable {
39
39
letns=NotSendable(x:0)
40
40
MyActor.ns = ns
41
41
42
-
// expected-region-isolation-warning @+2 {{transferring 'ns' may cause a race}}
43
-
// expected-region-isolation-note @+1 {{transferring global actor 'MyActor'-isolated 'ns' to global actor 'YourActor'-isolated callee could cause races between global actor 'YourActor'-isolated and global actor 'MyActor'-isolated uses}}
44
42
await{@YourActorin
43
+
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
44
+
// expected-region-isolation-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
45
45
// expected-complete-warning@+1 {{capture of 'ns' with non-sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
46
46
YourActor.ns = ns
47
47
}()
@@ -61,8 +61,9 @@ class NotSendable {
61
61
letns=NotSendable(x:0)
62
62
ns.stash()
63
63
64
-
// FIXME: Region isolation should diagnose this (https://github.com/apple/swift/issues/71533)
65
64
await{@YourActorin
65
+
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
66
+
// expected-region-isolation-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
66
67
// expected-complete-warning@+1 {{capture of 'ns' with non-sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
67
68
YourActor.ns = ns
68
69
}()
@@ -81,8 +82,9 @@ class NotSendable {
81
82
@MyActorfunc exhibitRace3()async{
82
83
letns=NotSendable()
83
84
84
-
// FIXME: Region isolation should diagnose this (https://github.com/apple/swift/issues/71533)
85
85
await{@YourActorin
86
+
// expected-region-isolation-warning @+3 {{transferring 'ns' may cause a race}}
87
+
// expected-region-isolation-note @+2 {{global actor 'MyActor'-isolated 'ns' is captured by a global actor 'YourActor'-isolated closure. global actor 'YourActor'-isolated uses in closure may race against later global actor 'MyActor'-isolated uses}}
86
88
// expected-complete-warning@+1 {{capture of 'ns' with non-sendable type 'NotSendable' in an isolated closure; this is an error in the Swift 6 language mode}}
awaituseValueAsync(erased) // expected-tns-warning {{transferring 'erased' may cause a race}}
236
+
// expected-tns-note @-1 {{transferring main actor-isolated 'erased' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}
237
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '() -> Void' outside of main actor-isolated context may introduce data races}}
238
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
awaituseValueAsync(erased) // expected-tns-warning {{transferring 'erased' may cause a race}}
245
+
// expected-tns-note @-1 {{transferring main actor-isolated 'erased' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}
246
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '() -> Void' outside of main actor-isolated context may introduce data races}}
247
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
awaituseValueAsync(erased) // expected-tns-warning {{transferring 'erased' may cause a race}}
254
+
// expected-tns-note @-1 {{transferring main actor-isolated 'erased' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}
255
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '(T) -> Void' outside of main actor-isolated context may introduce data races}}
256
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
awaituseValueAsync(erased) // expected-tns-warning {{transferring 'erased' may cause a race}}
268
+
// expected-tns-note @-1 {{transferring main actor-isolated 'erased' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}
269
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '() -> Void' outside of main actor-isolated context may introduce data races}}
270
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
awaituseValueAsync(erased) // expected-tns-warning {{transferring 'erased' may cause a race}}
282
+
// expected-tns-note @-1 {{transferring main actor-isolated 'erased' to nonisolated callee could cause races between nonisolated and main actor-isolated uses}}
283
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '() -> Void' outside of main actor-isolated context may introduce data races}}
284
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
awaittransferToCustomActor(closure) // expected-tns-warning {{transferring 'closure' may cause a race}}
293
+
// expected-tns-note @-1 {{transferring main actor-isolated 'closure' to global actor 'CustomActor'-isolated callee could cause races between global actor 'CustomActor'-isolated and main actor-isolated uses}}
294
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '() -> ()' into global actor 'CustomActor'-isolated context may introduce data races}}
295
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
awaittransferToCustomActor(closure) // expected-tns-warning {{transferring 'closure' may cause a race}}
303
+
// expected-tns-note @-1 {{transferring main actor-isolated 'closure' to global actor 'CustomActor'-isolated callee could cause races between global actor 'CustomActor'-isolated and main actor-isolated uses}}
304
+
// expected-complete-warning @-2 {{passing argument of non-sendable type '() -> ()' into global actor 'CustomActor'-isolated context may introduce data races}}
305
+
// expected-complete-note @-3 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
0 commit comments