Moving this discussion from pitch thread to here:
Our app still targets iOS 15, so it cannot use DispatchSerialQueue
. Instead there are custom executor implementations that attempt to wrap DispatchQueue
(non-main). Since underlying Dispatch API implementing isIsolatingCurrentContext()
is private, custom implementations won't be able to implement it. They can only implement checkIsolated()
. But even if implemented, checkIsolated()
won't be called in pre-iOS 18 runtimes.
Assuming X is the runtime version where this feature becomes available:
Min Version | Runtime Version | Behavior |
---|---|---|
< iOS 17 | < iOS 18 | Custom executor; assumeIsolated() fails; dynamic cast ignoring current executor could be used as a workaround. |
< iOS 17 | >= iOS 18, < X | Custom executor; assumeIsolated() passes; dynamic cast ignores custom executor. |
< iOS 17 | >= X | Custom executor; assumeIsolated() passes; dynamic cast checks custom executor without isIsolatingCurrentContext() . ![]() |
>= iOS 17 | < iOS 18. | DispatchSerialQueue ; assumeIsolated() fails; dynamic cast ignoring current executor could be used as a workaround. |
>= iOS 17 | >= iOS 18, < X | DispatchSerialQueue ; assumeIsolated() passes; dynamic cast ignores custom executor. |
>= iOS 17 | >= X | DispatchSerialQueue ; assumeIsolated() passes; dynamic cast checks custom executor, with isIsolatingCurrentContext() provided by DispatchSerialQueue . |
There is still one problematic case. I don't think we should let conditional casts silently pass, but not being able to use force casts can become a blocker.
I don't like idea of as!
and as?
having different behavior. We can keep their behavior in sync, if there is another way of asserting the current actor, that can be combined with dynamic casts.
And there is already one - it is assumeIsolated()
. But currently it does not dynamically store the isolation that has been recovered. If it starts doing so, and dynamic casts can be used inside the closure passed to the assumeIsolated()
- I think it will cover the remaining problematic use case.
Can this be done as part of SE-0470?