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] If a value is dynamically actor isolated, do not consider it transferred if the transfer statically was to that same actor isolation.
This issue can come up when a value is initially statically disconnected, but
after we performed dataflow, we discovered that it was actually actor isolated
at the transfer point, implying that we are not actually transferring.
Example:
```swift
@mainactor func testGlobalAndGlobalIsolatedPartialApplyMatch2() {
var ns = (NonSendableKlass(), NonSendableKlass())
// Regions: (ns.0, ns.1), {(mainActorIsolatedGlobal), @mainactor}
ns.0 = mainActorIsolatedGlobal
// Regions: {(ns.0, ns.1, mainActorIsolatedGlobal), @mainactor}
// This is not a transfer since ns is already main actor isolated.
let _ = { @mainactor in
print(ns)
}
useValue(ns)
}
```
To do this, I also added to SILFunction an actor isolation that SILGen puts on
the SILFunction during pre function visitation. We don't print it or serialize
it for now.
rdar://123474616
// TODO: We should not consider this to be a transfer.
193
+
// This is not a transfer since ns is already main actor isolated.
194
194
let _ ={@MainActorin
195
-
print(ns) // expected-tns-warning {{transferring 'ns' may cause a race}}
196
-
// expected-tns-note @-1 {{main actor-isolated 'ns' is captured by a main actor-isolated closure. main actor-isolated uses in closure may race against later nonisolated uses}}
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}}
32
+
}
33
+
34
+
useValue(ns) // expected-note {{use here could race}}
Copy file name to clipboardExpand all lines: test/Concurrency/transfernonsendable_isolationcrossing_partialapply.swift
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ actor ProtectsNonSendable {
41
41
// isolated since this is nonisolated.
42
42
self.assumeIsolated{ isolatedSelf in
43
43
isolatedSelf.ns = nsArg // expected-warning {{transferring 'nsArg' may cause a race}}
44
-
// expected-note @-1 {{actor-isolated 'nsArg' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses}}
44
+
// expected-note @-1 {{task-isolated 'nsArg' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses}}
45
45
}
46
46
}
47
47
@@ -50,7 +50,7 @@ actor ProtectsNonSendable {
50
50
doSomething(l, nsArg)
51
51
self.assumeIsolated{ isolatedSelf in
52
52
isolatedSelf.ns = l // expected-warning {{transferring 'l' may cause a race}}
53
-
// expected-note @-1 {{actor-isolated 'l' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses}}
53
+
// expected-note @-1 {{task-isolated 'l' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses}}
0 commit comments