Actor `assumeIsolated` erroneously crashes when using a dispatch queue as the underlying executor

Ok this helps understand the question. So you're asking about the runtime warning, this was a bit hidden in all those messages here tbh and I missed it :slight_smile:

That's a runtime warning that is gone in Swift 6 (well, in Concurrency library shipping in those OSes that contain Swift 6+), so in before Swift 6 which you care about here... I believe you can disable it with the env var SWIFT_UNEXPECTED_EXECUTOR_LOG_LEVEL=0:

Here's some notes about it:

/// Logging level for unexpected executors:
/// 0 - no logging -- will be IGNORED when Swift6 mode of isCurrentExecutor is used
/// 1 - warn on each instance -- will be IGNORED when Swift6 mode of isCurrentExecutor is used
/// 2 - fatal error
///
/// NOTE: The default behavior on Apple platforms depends on the SDK version
/// an application was linked to. Since Swift 6 the default is to crash,
/// and the logging behavior is no longer available.

It's worth documenting some more perhaps in the migration guide, would you mind filing an issue about it or contributing a section? GitHub - apple/swift-migration-guide


All this is a very "have the cake and eat it too" situation to be honest. The entire reason this warning happens is because the "old" runtime cannot detect the queues properly - because as you now know, there's no APIs to do so.

The fix for this detecting is checkIsolated basically and turning off the runtime warning into strict checks which are entirely correct.

In other words, the same functionality that was powering the warning is what we've improved in 6.0, so if you're going to do 6.0 assume... style APIs, the previous runtime just has no idea about how that's correct and to the best of its knowledge is warning you about it.

For development I think it's fine to try to disable that logging mode, but be super careful with the assumptions, and then try to move to 6.0 runtimes as soon as you can.

3 Likes