[Pitch] Unsafe Assume on MainActor

Thanks for pointing this out. The unsafe variant of MainActor checks the context in which the function is called. It will emit an error if the context has adopted any concurrency features (e.g., the call is in an actor method), or if compiled with -strict-concurrency=complete. That mode is suppose to be a preview of Swift 6, so as a long-term adoption tool I don't know if it will hold-up.

That's one of the downsides of trying to use @MainActor(unsafe) for this: the dependence on the strictness of concurrency checking. The other downside is that it doesn't do any runtime check that you are on the right actor. If you remembered to compile with -enable-actor-data-race-checks when using @MainActor(unsafe) then you will the check, and then you'll have a pretty close approximation of this unsafeAssumeMainActor.

Yea seems like a bug that @MainActor(unsafe) closures get treated like @MainActor, even with -strict-concurrency=minimal.

3 Likes