Skip to content

Prepare for Swift 6 strict concurrency: mark NumericTypes as Sendable #120

@alex-vasenin

Description

@alex-vasenin

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 {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions