Global actor as TaskLocal

This is a wild discovery.

I do not believe it is possible to guarantee safety even if these tests are run serialized. A single task could still create child tasks internally that rely on a global actor being a singleton. That might not happen, but the language does need this to be an invariant.

I promise I don't want to make your life more difficult, but unfortunately this must be a compiler bug and should fail to compile. I think you are almost certainly correct that you have reentrancy issues here.

(I personally believe we must go even further and completely disallow global actor instantiation altogether, but that is a different discussion.)

2 Likes