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
[nonisolated-nonsending] Make the AST not consider nonisolated(nonsending) to be an actor isolation crossing point.
We were effectively working around this previously at the SIL level. This caused
us not to obey the semantics of the actual evolution proposal. As an example of
this, in the following, x should not be considered main actor isolated:
```swift
nonisolated(nonsending) func useValue<T>(_ t: T) async {}
@mainactor func test() async {
let x = NS()
await useValue(x)
print(x)
}
```
we should just consider this to be a merge and since useValue does not have any
MainActor isolated parameters, x should not be main actor isolated and we should
not emit an error here.
I also fixed a separate issue where we were allowing for parameters of
nonisolated(nonsending) functions to be passed to @Concurrent functions. We
cannot allow for this to happen since the nonisolated(nonsending) parameters
/could/ be actor isolated. Of course, we have lost that static information at
this point so we cannot allow for it. Given that we have the actual dynamic
actor isolation information, we could dynamically allow for the parameters to be
passed... but that is something that is speculative and is definitely outside of
the scope of this patch.
rdar://154139237
awaituseValueConcurrently(x) // expected-error {{sending 'x' risks causing data races}}
136
+
// expected-note @-1 {{sending main actor-isolated 'x' to nonisolated global function 'useValueConcurrently' risks causing data races between nonisolated and main actor-isolated uses}}
137
+
}
138
+
139
+
func testTaskLocal(_ y:NSObject)async{
140
+
letx=ObjCObject()
141
+
await x.useValue(y)
142
+
awaituseValueConcurrently(x) // expected-ni-ns-error {{sending 'x' risks causing data races}}
143
+
// expected-ni-ns-note @-1 {{sending task-isolated 'x' to nonisolated global function 'useValueConcurrently' risks causing data races between nonisolated and task-isolated uses}}
144
+
145
+
// This is not safe since we merge x into y's region making x task
146
+
// isolated. We then try to send it to a main actor function.
147
+
awaituseValueMainActor(x) // expected-error {{sending 'x' risks causing data races}}
148
+
// expected-note @-1 {{sending task-isolated 'x' to main actor-isolated global function 'useValueMainActor' risks causing data races between main actor-isolated and task-isolated uses}}
149
+
}
150
+
151
+
actorMyActor{
152
+
varfield=NSObject()
153
+
154
+
// This is safe since x.useValue is going to be nonisolated(nonsending) so we
155
+
// are going to merge x into the actor. And useValueNonIsolatedNonSending
0 commit comments