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
[concurrency] Change #isolated to mask out the TBI bits of the witness pointer of the implicit isolated any Actor pointer so we can do optimizations on TBI supporting platforms in the future.
Specifically, this will let us perform an optimization in the future where a
caller can set bits in the TBI byte to signal information dynamically to a
nonisolated(nonsending) callee. The intent is that this will let us signal to a
nonisolated(nonsending) callee that the caller isn't performing any isolated
work before it hops (or potentially a caller of the caller) hops meaning that
the nonisolated(nonsending) function can avoid a tail hop that restores
isolation after calling some sort of actor isolated call.
E.x.:
```swift
nonisolated(nonsending) func callsActor(_ a: MyActor) async {
await a.doSomething()
}
@Concurrent func runOnBackground() async {}
actor A {
func doSomething() async { ... }
func caller() async {
await callsActor(self)
await runOnBackgroud()
}
}
```
In the above case, the hop back in callsActor is not needed dynamically in
caller since we are going to immediately await ontot he background. But we do
not know that. An optimization can be written that can recognize this case and
dynamically tell via the tbi bits of the protocol witness table of the any Actor
call that the hop to executor call can avoid the hop.
Since this only applies to the implicit isolated any Actor parameter which is
only used for the purpose of hopping, it is safe to do this since when we hop we
just call the Actor unowned executor dispatch thunk which directly accesses the
witness table by loading from that pointer... meaning that anything set in the
TBI bit is irrelevent.
The only other way to grab this implicit bit is to use `#isolation` and that is
where this commit comes into play. Since we can access the actor via
`#isolation`, we need to ensure that we mask out the TBI bits so that the rest
of the runtime/compiled code never see the TBI bits. This is because we do not
want the fact that we are using these TBI bits to ever escape into other code
(e.x.: consider things that may cast).
So we have basically created a hermetically sealed world where we can pass
information from callee to caller using the protocol witness TBI bits.
rdar://156525771
0 commit comments