Use of `Mutex` within the stdlib's `Concurrency` module

using compiler directives like #if swift(6.0) seems to allow the code to compile, but when i try and run the unit tests, they don't appear to exercise the new code path.

I assume you mean that you used if #available(SwiftStdlib 6.0, *) as you did in your code snippet, rather than #if swift(>=6.0) which accomplishes something very different. The standard library doesn't compile with -swift-version 6 so code guarded with #if swift(>=6.0) would be ignored entirely.

if #available(SwiftStdlib 6.0, *) expands to if #available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *), so whether or not the code runs would depend on whether you're executing the tests on a Mac running macOS 15.0 or later.

The fact that APIs like Mutex have availability restrictions that make their use in the implementation of the stdlib more awkward is something we've been grappling with recently. There's a PR here that implemented a short term solution where you can apply a different availability macro to stdlib APIs that need their availability artificially lowered when building that stdlib separately from the operating system that it actually gets distributed with. I have ideas about using custom availability domains to implement a more permanent solution that would address this problem and also facilitate safe use of a future ABI stable stdlib distribution on other operating systems, where the availability of stdlib APIs would not be tied to the operating system version. There's quite a bit more work to do to make that a reality though.

3 Likes