swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.4k stars 159 forks source link

`Unit` / `Dimension` concurrency warnings. Add `Sendable` conformance? #471

Open tcldr opened 8 months ago

tcldr commented 8 months ago

I'm not sure of the best place to surface this, but as mentioned on this Swift forums post it seems to me that the explicit, unavailable Sendable conformance of Unit and Dimension, is incompatible with the stated usage of Unit and Dimension.

Specifically, in strict concurrency 'complete' mode, the Swift 5.10 compiler flags the creation of static properties with the warning 'Static property 'x' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor'. Of course, Isolating properties to an Actor isn't feasible either as not only does being tied to an Actor limit the utility of the class, but the the properties become inaccessible to the essential baseUnit override.

Perhaps this is something that https://github.com/apple/swift-foundation/issues/237 will address?

itingliu commented 3 weeks ago

237 will be a way to address this, but until then we can just mark the class Unit and class Dimension Sendable. The Objective-C header that defines NSUnit and NSDimension isn't open source, so I'm going to throw the proposal here: I propose that we append __attribute__((swift_attr("@Sendable"))) to the class definition, so that subclasses can and must truthfully conform to @unchecked Sendable.