swiftstructured-concurrency

Is there a way to use Swift 6 without SWIFT_STRICT_CONCURRENCY=COMPLETE?


Swift 6 introduces a couple of cool features which I would like to use, but there is zero hope of compiling my 10000 lines of code project in Swift 6 mode - because of strict concurrency checking.

My code is perfectly safe and bug free, and it's guaranteed dynamically. I am not willing to use either the actor-based synchronization model, nor the Swift structured concurrency altogether.

And please to not suggest to eliminate the "strict concurrency checking"-produced errors - my goal is to move on to Swift 6 without "strict concurrency checking".

How can I use Swift 6, but still be allowed global mutable non-actor isolated variables?

(All of this is of course an imaginary situation)


Solution

  • You cannot disable strict concurrency checking in Swift 6 mode. From the build settings reference,

    Setting name: SWIFT_STRICT_CONCURRENCY

    Enables strict concurrency checking to produce warnings for possible data races. This is always ‘complete’ when in the Swift 6 language mode and produces errors instead of warnings.

    If you just want to use Swift 6 features in new code, you can still compile your 10000 lines of old code in Swift 5 mode, as a separate module (as suggested by the official guide). You can then write new Swift 6 code, with the old code as a dependency. You can @preconcurrency import the module, so that there are no Sendable-related errors in your new code when using types from the old code. See also SE-0435.

    There are also upcoming feature flags, which allows you to use new features without changing the language version. However, these are usually only available for features that might break existing code, which I assume you won't want to use anyway.