swiftlang / swiftly

A Swift toolchain installer and manager, written in Swift.
https://swiftlang.github.io/swiftly/
Apache License 2.0
424 stars 19 forks source link

Ensure swiftly passes complete concurrency checks #124

Open cmcgee1024 opened 2 weeks ago

cmcgee1024 commented 2 weeks ago

Now that Swiftly is switching to 5.10 there is the experimental strict concurrency check feature that will help us to prepare for Swift 6's concurrency. You can add the checks like this in the Package.swift:

diff --git a/Package.swift b/Package.swift
index 0f15e50..725e033 100644
--- a/Package.swift
+++ b/Package.swift
@@ -28,14 +28,16 @@ let package = Package(
                 .target(name: "LinuxPlatform", condition: .when(platforms: [.linux])),
                 .target(name: "MacOSPlatform", condition: .when(platforms: [.macOS])),
                 .product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
-            ]
+            ],
+            swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
         ),
         .target(
             name: "SwiftlyCore",
             dependencies: [
                 .product(name: "AsyncHTTPClient", package: "async-http-client"),
                 .product(name: "NIOFoundationCompat", package: "swift-nio"),
-            ]
+            ],
+            swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
         ),
         .target(
             name: "LinuxPlatform",
@@ -43,6 +45,7 @@ let package = Package(
                 "SwiftlyCore",
                 "CLibArchive",
             ],
+            swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")],
             linkerSettings: [
                 .linkedLibrary("z"),
             ]
@@ -51,7 +54,8 @@ let package = Package(
             name: "MacOSPlatform",
             dependencies: [
                 "SwiftlyCore",
-            ]
+            ],
+            swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]
         ),

When trying this out with the Swiftly code there were a number of warnings that will become errors in Swift 6. These should be fixed in preparation for the update. Here are some examples:

/Users/cmcgee/git/swiftly-public/Sources/SwiftlyCore/SwiftlyVersion.swift:7:16: warning: static property 'regex' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6
    static let regex: Regex<(Substring, Substring, Substring, Substring, Substring?)> =
               ^
/Users/cmcgee/git/swiftly-public/Sources/SwiftlyCore/SwiftlyCore.swift:3:12: warning: let 'version' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor; this is an error in Swift 6
public let version = SwiftlyVersion(major: 0, minor: 3, patch: 0)
           ^
/Users/cmcgee/git/swiftly-public/Sources/SwiftlyCore/SwiftlyCore.swift:7:12: warning: var 'mockedHomeDir' is not concurrency-safe because it is non-isolated global shared mutable state; this is an error in Swift 6
public var mockedHomeDir: URL?
           ^
/Users/cmcgee/git/swiftly-public/Sources/SwiftlyCore/SwiftlyCore.swift:7:12: note: isolate 'mockedHomeDir' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'
public var mockedHomeDir: URL?
           ^
patrickfreed commented 1 week ago

For reference: https://www.swift.org/documentation/concurrency/