SwiftAA icon indicating copy to clipboard operation
SwiftAA copied to clipboard

Prepare for Swift 6 strict concurrency: mark `NumericTypes` as `Sendable`

Open alex-vasenin opened this issue 11 months ago • 0 comments

Swift 6 (which expected to be released Sep 2024) is going to have strict concurrency mode to prevent data races. While (AFAIK) SwiftAA does not uses concurrency itself, its clients might want to use some of its primitives in concurrent context. I tried to compile my current project with SWIFT_STRICT_CONCURRENCY = complete and I got a lots of warnings, because I was sending primitives like JulianDay, EquatorialCoordinates, Magnitude, etc between between actor boundaries (i.e. between threads).

While those types are safe to use concurrently because they are value types, they are not explicitly declared as Sendable, which triggers the warnings. Swift 6 declares that Sendable conformance must be declared in the same file where the type is declared, so you can't do it in an extension. So we need to mark types which safe to send across actors as Sendable in the package itself. It might be a little tricky, because the package still supports iOS12.0, i.e. Swift 4.2 and we are risking breaking backward compatibility.

As a workaround it is possible to mark those types in a client app as so: extension Magnitude: @unchecked Sendable {}

alex-vasenin avatar Mar 11 '24 20:03 alex-vasenin