Hello, I'd be interested in hearing thoughts about the interaction of non-Escapable Types and Region-Based Isolation. I known this escapes the focus of the proposal, but, well, I ask anyway.
According to SE-0414, Rules for Merging Isolation Regions:
Given a function
fwith argumentsaiand result that is assigned to
variabley:y = f(a0, ..., an)
- All regions of non-
Sendableargumentsaiare merged into one larger
region afterfexecutes.- If any of
aiare non-Sendableandyis non-Sendable, thenyis in
the same merged region asai. If all of theaiareSendable,
thenyis within a new disconnected region that consists only ofy.- [...]
Should the rule 2 still hold if an argument is non-Sendable, and non-Escapable?
The reason why I ask is that it is currently impossible to write the following method when Resource is not Sendable:
func accessResource<T>(
_ work: sending @escaping (Resource) -> sending T
) async throw -> sending T
The reason why it is not possible is that at use site, all values grabbed from the "resource" are in its Region, and can not be sent out:
accessResource { rez in
let value = makeValue(resource: rez)
return value // warning or error
}
The only way this API must be written today if full of Sendable constraints:
func accessResource<T: Sendable>(
_ work: @escaping @Sendable (Resource) -> T
) async throw -> T
We know "sending" was invented in order to help dealing with non-Sendable types, so this version is strictly inferior to the previous one that uses sending (but can't be made to work when Resource is not Sendable).
If the Resource type was made non-Escapable as well, would it be a sufficient guarantee that it can't "pollute" the value according to Region-Based Isolation, and could thus be "sent" without compiler warning or error?