hborla
(Holly Borla)
October 7, 2023, 5:31pm
10
ellie20:
Would this proposal also apply to isolation domains that aren't global actors? For example, currently the below code generates a warning, because NSMutableString
is not Sendable
but is sent across an actor isolation boundary.
actor SomeActor {
func doThing(string: NSMutableString = NSMutableString()) { ... }
}
let a = SomeActor()
await a.doThing()
We could make it so that the default value expression is executed within the isolation domain of a
. Going further, we could do that for arguments that are written out at the call site.
No, I don't think we can change the fundamental isolation rules for call arguments. I agree that it should be valid to transfer non-Sendable values across isolation boundaries when they are not protected by the isolation domain they were created in (e.g. because it's just a local variable or a temporary), and that's the goal of a different pitch:
Hello Swift Community!
As strict concurrency checking comes closer to being a standard, error-producing part of the Swift language, the restriction that only Sendable values can be communicated between tasks, actors, and other isolation domains is becoming increasingly problematic. For many datatypes, sacrificing mutability to attain Sendable conformance is awkward to program around. A particularly unfortunate case arises for datatypes that cannot safely be made Sendable; computation involving …
2 Likes