pointfreeco / swift-custom-dump

A collection of tools for debugging, diffing, and testing your application's data structures.
MIT License
800 stars 89 forks source link

Fix Swift 6 concurrency error (on Linux) #127

Closed finestructure closed 2 months ago

finestructure commented 3 months ago

This fixes a Swift 6 compile error (on Linux):

/host/Sources/CustomDump/Conformances/Foundation.swift:50:24: error: static property 'formatter' is not concurrency-safe because non-'Sendable' type 'DateFormatter' may have shared mutable state
 48 |     }
 49 | 
 50 |     private static let formatter: DateFormatter = {
    |                        `- error: static property 'formatter' is not concurrency-safe because non-'Sendable' type 'DateFormatter' may have shared mutable state
 51 |       let formatter = DateFormatter()
 52 |       formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"

See also: https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/3115#issuecomment-2153037172

finestructure commented 2 months ago

I believe this fix might be superfluous thanks to the new Swift Foundation:

❯ docker pull swiftlang/swift:nightly-6.0-jammy
nightly-6.0-jammy: Pulling from swiftlang/swift
4ce000a43472: Already exists 
2f93d687a70b: Pull complete 
4f4fb700ef54: Pull complete 
989dc8e70c12: Pull complete 
04d2dc059ad6: Pull complete 
9cc74bbadbae: Pull complete 
Digest: sha256:046fec375e24ecf96a1ed9794e01045bcf8a86fb465e374536230e0b266b7551
Status: Downloaded newer image for swiftlang/swift:nightly-6.0-jammy
docker.io/swiftlang/swift:nightly-6.0-jammy

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview swiftlang/swift:nightly-6.0-jammy
~/D/swift-custom-dump on main took 1m37s 
❯ dsh swiftlang/swift@sha256:046fec375e24ecf96a1ed9794e01045bcf8a86fb465e374536230e0b266b7551
# bash
################################################################
#                                                              #
# Swift Nightly Docker Image                                   #
# Tag: swift-6.0-DEVELOPMENT-SNAPSHOT-2024-08-01-a             #
#                                                              #
################################################################
root@docker-desktop:/host# swift build
warning: 'xctest-dynamic-overlay': /host/.build/checkouts/xctest-dynamic-overlay/Package@swift-6.0.swift:5:15: warning: 'init(name:defaultLocalization:platforms:pkgConfig:providers:products:dependencies:targets:swiftLanguageVersions:cLanguageStandard:cxxLanguageStandard:)' is deprecated: replaced by 'init(name:defaultLocalization:platforms:pkgConfig:providers:products:dependencies:targets:swiftLanguageModes:cLanguageStandard:cxxLanguageStandard:)'
 3 | import PackageDescription
 4 | 
 5 | let package = Package(
   |               |- warning: 'init(name:defaultLocalization:platforms:pkgConfig:providers:products:dependencies:targets:swiftLanguageVersions:cLanguageStandard:cxxLanguageStandard:)' is deprecated: replaced by 'init(name:defaultLocalization:platforms:pkgConfig:providers:products:dependencies:targets:swiftLanguageModes:cLanguageStandard:cxxLanguageStandard:)'
   |               `- note: use 'init(name:defaultLocalization:platforms:pkgConfig:providers:products:dependencies:targets:swiftLanguageModes:cLanguageStandard:cxxLanguageStandard:)' instead
 6 |   name: "xctest-dynamic-overlay",
 7 |   platforms: [
Building for debugging...
[56/56] Compiling CustomDump UserNotificationsUI.swift
Build complete! (3.08s)
root@docker-desktop:/host# 
root@docker-desktop:/host# git rev-parse @
aec6a73f5c1dc1f1be4f61888094b95cf995d973

(dsh == docker run --rm -it -v $PWD:/host -w /host --network="host" --entrypoint sh $argv;)

finestructure commented 2 months ago

Using the computed value should definitely be safer though, as I'm not sure if Johannes advices changes with the new Foundation.

stephencelis commented 2 months ago

Yeah I think it's probably harmless to have a computed var here given this is a debug tool.