[Pitch] strict concurrency checking for async functions

A common, borderline universal experience when starting with Swift concurrency is to begin with Swift 5 mode and with strict-concurrency set to minimal. This allows developers to use quite a lot of concurrency features without getting any feedback from the compiler. By the time you do get around to complete or Swift 6 mode, you might have built quite a lot of problematic systems. But way worse is that, this allows a developer to form incorrect mental models of how Swift concurrency works. I have regularly encountered this phenomenon.

I'd like to get feedback on the idea of adding a fourth mode to strict-concurrency. This mode would behave like complete, but would only present diagnostics within async function bodies. I've come up with the name usage, but I'm definitely open to suggestions here.

I think that a mode like usage would introduce more progressive disclosure to the concurrency system. Developers are accustomed to the compiler providing feedback to them as they learn new language features. They expect it to work that way. Of course complete does that, but it also brings along a lot of other, unrelated diagnostics. And that makes it much harder to use when experimenting in even a modest-sized code base.

I don't have a great idea on how this new mode could be introduced into the system such that it could be a default, though. Wholesale changing the default would have wide-spread impact. But, I still think there's value in at least considering this as an option. I could definitely see this mode could be a useful tool for incremental migration towards Swift 6. It would provide a way for a module author to enforce correctness in new, asynchronous code, without being burdened by un-migrated areas.

Anyways I'd love to hear your thoughts on this idea! I'm especially interested in hearing about how difficult such a change would be to implement technically, as I have zero experience with the compiler's diagnostic systems.

Update: Could it be that this is what targeted is supposed to do? I tried out a few tests with this mode, which I admit I'm not very familiar with, and found it easy to introduce races using the Task APIs. But I wonder if that's just a bug?

9 Likes

Is this really the case? I didn’t start a new Xcode project since release of Swift 6 but I guess the language mode is set to Swift 6 and for SwiftPM, when creating a new project it’s also Swift 6.

It was a problem with existing projects when strict concurrency was still in "beta" but I don’t think anyone will forcibly set their new project to language mode 5 and the concurrency checking to "minimal" unless they have a compelling reason to do so.

Xcode 16's default for new projects is 5 mode with minimal checking. But you are right that SwiftPM sets the tools version to 6 and that has the effect of setting the language mode to 6.

I’m also not sure of the specifics but this is one of my main worries (team mates adding async code to our swift 5 app and inadvertently adding bugs). So plus 1 from me if this is all correct.

This pitch seems relevant...