As far as I know it is not possible to treat some specific warnings as errors. Like it was with -Werror
.
Right now we are trying to adopt swift concurrency in our project. And fixing Sendable-related warnings is important to keep the code safe. But it's difficult right now because it is easy to miss a warning in a big project, when you have a lot of PRs and code changes every day. So it is critical to have the ability to turn this warning into error.
So looks like currently is only possible to achieve this by post-processing the compiler logs. Are there any plans to support converting sendable warnings into errors?
5 Likes
You could run an additional build with a Swift 6 toolchain in language mode 6 to catch concurrency errors specifically:
env DEVELOPER_DIR=/Applications/Xcode-15.4.0.app xcrun --toolchain org.swift.600202405261a swift build -Xswiftc -swift-version -Xswiftc 6
That will convert the warnings into errors:
❯ env DEVELOPER_DIR=/Applications/Xcode-15.4.0.app xcrun --toolchain org.swift.600202405261a swift build -Xswiftc -swift-version -Xswiftc 6
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/sas/Projects/SPI/ReadyForSwift6Test/Sources/ReadyForSwift6Test/ReadyForSwift6Test.swift:1:5: error: var 'global' is not concurrency-safe because it is non-isolated global shared mutable state
1 | var global = 0
| |- error: var 'global' is not concurrency-safe because it is non-isolated global shared mutable state
| |- note: convert 'global' to a 'let' constant to make 'Sendable' shared state immutable
| |- note: annotate 'global' with '@MainActor' if property should only be accessed from the main actor
| `- note: disable concurrency-safety checks if accesses are protected by an external synchronization mechanism
2 |
3 | func f() async {
/Users/sas/Projects/SPI/ReadyForSwift6Test/Sources/ReadyForSwift6Test/ReadyForSwift6Test.swift:1:5: error: var 'global' is not concurrency-safe because it is non-isolated global shared mutable state
1 | var global = 0
| |- error: var 'global' is not concurrency-safe because it is non-isolated global shared mutable state
| |- note: convert 'global' to a 'let' constant to make 'Sendable' shared state immutable
| |- note: annotate 'global' with '@MainActor' if property should only be accessed from the main actor
| `- note: disable concurrency-safety checks if accesses are protected by an external synchronization mechanism
2 |
3 | func f() async {
2 Likes
In general that’s currently the best approach, but it worth mentioning that Swift 6 also includes additions like import visibility, and if this feature wasn’t enabled so far in the project, along with concurrency errors you’ll get a lot of errors on imports.
2 Likes