SwiftPackageIndex-Server icon indicating copy to clipboard operation
SwiftPackageIndex-Server copied to clipboard

Ready for Swift 6 false positives

Open finestructure opened this issue 1 year ago • 10 comments

The APNSwift package is reporting 1 Swift 6 error via Sema.NumSwift6Errors while the package itself does not show any concurrency warnings during compilation.

Test case:

git clone https://github.com/swift-server-community/APNSwift && cd APNSwift
git checkout 36fec7
mkdir .stats
env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.3.app xcrun swift build --arch arm64 -Xswiftc -Xfrontend -Xswiftc -stats-output-dir -Xswiftc -Xfrontend -Xswiftc .stats -Xswiftc -strict-concurrency=complete

Build log:

~/D/APNSwift on HEAD (36fec7e)
❯ env DEVELOPER_DIR=/Applications/Xcode-16.0.0-Beta.3.app xcrun swift build --arch arm64 -Xswiftc -Xfrontend -Xswiftc -stats-output-dir -Xswiftc -Xfrontend -Xswiftc .stats -Xswiftc -strict-concurrency=complete

Fetching https://github.com/apple/swift-nio-http2.git from cache
Fetching https://github.com/apple/swift-nio-ssl.git from cache
Fetching https://github.com/swift-server/async-http-client.git from cache
Fetching https://github.com/apple/swift-crypto.git from cache
Fetching https://github.com/apple/swift-log.git from cache
Fetching https://github.com/apple/swift-docc-plugin from cache
Fetching https://github.com/apple/swift-nio.git from cache
Fetched https://github.com/apple/swift-log.git from cache (1.15s)
Fetched https://github.com/apple/swift-docc-plugin from cache (1.21s)
Fetched https://github.com/apple/swift-nio-http2.git from cache (1.21s)
Fetched https://github.com/swift-server/async-http-client.git from cache (1.34s)
Fetched https://github.com/apple/swift-crypto.git from cache (1.47s)
Fetched https://github.com/apple/swift-nio-ssl.git from cache (1.48s)
Fetched https://github.com/apple/swift-nio.git from cache (1.54s)
Computing version for https://github.com/apple/swift-docc-plugin
Computed https://github.com/apple/swift-docc-plugin at 1.3.0 (0.02s)
Fetching https://github.com/apple/swift-docc-symbolkit from cache
Fetched https://github.com/apple/swift-docc-symbolkit from cache (1.40s)
Computing version for https://github.com/apple/swift-docc-symbolkit
Computed https://github.com/apple/swift-docc-symbolkit at 1.0.0 (0.02s)
Computing version for https://github.com/swift-server/async-http-client.git
Computed https://github.com/swift-server/async-http-client.git at 1.21.2 (0.02s)
Fetching https://github.com/apple/swift-atomics.git from cache
Fetching https://github.com/apple/swift-nio-transport-services.git from cache
Fetching https://github.com/apple/swift-algorithms from cache
Fetching https://github.com/apple/swift-nio-extras.git from cache
Fetched https://github.com/apple/swift-nio-transport-services.git from cache (1.02s)
Fetched https://github.com/apple/swift-atomics.git from cache (1.03s)
Fetched https://github.com/apple/swift-nio-extras.git from cache (1.06s)
Fetched https://github.com/apple/swift-algorithms from cache (1.09s)
Computing version for https://github.com/apple/swift-algorithms
Computed https://github.com/apple/swift-algorithms at 1.2.0 (0.02s)
Fetching https://github.com/apple/swift-numerics.git from cache
Fetched https://github.com/apple/swift-numerics.git from cache (1.01s)
Computing version for https://github.com/apple/swift-numerics.git
Computed https://github.com/apple/swift-numerics.git at 1.0.2 (0.02s)
Computing version for https://github.com/apple/swift-atomics.git
Computed https://github.com/apple/swift-atomics.git at 1.2.0 (0.02s)
Computing version for https://github.com/apple/swift-nio-transport-services.git
Computed https://github.com/apple/swift-nio-transport-services.git at 1.21.0 (0.01s)
Computing version for https://github.com/apple/swift-nio.git
Computed https://github.com/apple/swift-nio.git at 2.68.0 (0.02s)
Fetching https://github.com/apple/swift-collections.git from cache
Fetching https://github.com/apple/swift-system.git from cache
Fetched https://github.com/apple/swift-system.git from cache (0.96s)
Fetched https://github.com/apple/swift-collections.git from cache (1.02s)
Computing version for https://github.com/apple/swift-system.git
Computed https://github.com/apple/swift-system.git at 1.3.1 (0.01s)
Computing version for https://github.com/apple/swift-nio-ssl.git
Computed https://github.com/apple/swift-nio-ssl.git at 2.27.0 (0.02s)
Computing version for https://github.com/apple/swift-log.git
Computed https://github.com/apple/swift-log.git at 1.6.1 (0.01s)
Computing version for https://github.com/apple/swift-collections.git
Computed https://github.com/apple/swift-collections.git at 1.1.2 (0.01s)
Computing version for https://github.com/apple/swift-nio-extras.git
Computed https://github.com/apple/swift-nio-extras.git at 1.23.0 (0.01s)
Fetching https://github.com/apple/swift-http-types from cache
Fetched https://github.com/apple/swift-http-types from cache (0.74s)
Computing version for https://github.com/apple/swift-http-types
Computed https://github.com/apple/swift-http-types at 1.3.0 (0.01s)
Computing version for https://github.com/apple/swift-nio-http2.git
Computed https://github.com/apple/swift-nio-http2.git at 1.33.0 (0.02s)
Computing version for https://github.com/apple/swift-crypto.git
Computed https://github.com/apple/swift-crypto.git at 3.5.2 (0.02s)
Creating working copy for https://github.com/apple/swift-nio-ssl.git
Working copy of https://github.com/apple/swift-nio-ssl.git resolved at 2.27.0
warning: /Users/sas/Downloads/APNSwift/.build/repositories/swift-numerics-d936ec6c is not valid git repository for 'https://github.com/apple/swift-numerics.git', will fetch again.
Fetching https://github.com/apple/swift-numerics.git from cache
Fetched https://github.com/apple/swift-numerics.git from cache (0.06s)
warning: /Users/sas/Downloads/APNSwift/.build/repositories/swift-numerics-d936ec6c is not valid git repository for 'https://github.com/apple/swift-numerics.git', will fetch again.
Fetching https://github.com/apple/swift-numerics.git from cache
Fetched https://github.com/apple/swift-numerics.git from cache (0.06s)
Creating working copy for https://github.com/apple/swift-numerics.git
Working copy of https://github.com/apple/swift-numerics.git resolved at 1.0.2
Creating working copy for https://github.com/apple/swift-crypto.git
Working copy of https://github.com/apple/swift-crypto.git resolved at 3.5.2
Creating working copy for https://github.com/apple/swift-system.git
Working copy of https://github.com/apple/swift-system.git resolved at 1.3.1
warning: /Users/sas/Downloads/APNSwift/.build/repositories/swift-algorithms-bf5a01cd is not valid git repository for 'https://github.com/apple/swift-algorithms', will fetch again.
Fetching https://github.com/apple/swift-algorithms from cache
Fetched https://github.com/apple/swift-algorithms from cache (0.09s)
warning: /Users/sas/Downloads/APNSwift/.build/repositories/swift-algorithms-bf5a01cd is not valid git repository for 'https://github.com/apple/swift-algorithms', will fetch again.
Fetching https://github.com/apple/swift-algorithms from cache
Fetched https://github.com/apple/swift-algorithms from cache (0.08s)
Creating working copy for https://github.com/apple/swift-algorithms
Working copy of https://github.com/apple/swift-algorithms resolved at 1.2.0
Creating working copy for https://github.com/apple/swift-nio.git
Working copy of https://github.com/apple/swift-nio.git resolved at 2.68.0
Creating working copy for https://github.com/apple/swift-atomics.git
Working copy of https://github.com/apple/swift-atomics.git resolved at 1.2.0
Creating working copy for https://github.com/apple/swift-log.git
Working copy of https://github.com/apple/swift-log.git resolved at 1.6.1
Creating working copy for https://github.com/swift-server/async-http-client.git
Working copy of https://github.com/swift-server/async-http-client.git resolved at 1.21.2
Creating working copy for https://github.com/apple/swift-nio-http2.git
Working copy of https://github.com/apple/swift-nio-http2.git resolved at 1.33.0
Creating working copy for https://github.com/apple/swift-nio-transport-services.git
Working copy of https://github.com/apple/swift-nio-transport-services.git resolved at 1.21.0
Creating working copy for https://github.com/apple/swift-nio-extras.git
Working copy of https://github.com/apple/swift-nio-extras.git resolved at 1.23.0
Creating working copy for https://github.com/apple/swift-docc-symbolkit
Working copy of https://github.com/apple/swift-docc-symbolkit resolved at 1.0.0
Creating working copy for https://github.com/apple/swift-docc-plugin
Working copy of https://github.com/apple/swift-docc-plugin resolved at 1.3.0
Creating working copy for https://github.com/apple/swift-collections.git
Working copy of https://github.com/apple/swift-collections.git resolved at 1.1.2
Creating working copy for https://github.com/apple/swift-http-types
Working copy of https://github.com/apple/swift-http-types resolved at 1.3.0
warning: 'swift-algorithms': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    /Users/sas/Downloads/APNSwift/.build/checkouts/swift-algorithms/Sources/Algorithms/Documentation.docc
warning: 'swift-nio-ssl': found 1 file(s) which are unhandled; explicitly declare them as resources or exclude from the target
    /Users/sas/Downloads/APNSwift/.build/checkouts/swift-nio-ssl/Sources/NIOSSL/PrivacyInfo.xcprivacy
Building for debugging...
[1115/1115] Applying APNSExample
Build complete! (235.40s)

Error count:

❯ grep Sema.NumSwift6Errors .stats/stats-*-swift-frontend-APNS-all-arm64_apple_macosx13.0-swiftmodule-Onone-*.json
	"Sema.NumSwift6Errors": 1,

finestructure avatar Jul 20 '24 12:07 finestructure

Another package that's affected is https://github.com/vapor/jwt-kit (Xcode 16b6)

finestructure avatar Aug 29 '24 06:08 finestructure

Hummingbird 2 seems to be affected as well

Joannis avatar Aug 29 '24 08:08 Joannis

Likely also https://swiftpackageindex.com/groue/GRDB.swift

finestructure avatar Sep 29 '24 13:09 finestructure

This package is also impacted (version 1.2.0-beta.1) https://github.com/xcode-actions/swift-signal-handling

Frizlab avatar Dec 24 '24 10:12 Frizlab

This also says there are ~20 for Alamofire on most platforms, and 60! on watchOS. There are exactly 7 warnings on macOS currently, all of which are either backward compatibility issues (Any is not compatible with concurrency, but it's usage is deprecated) or Apple framework issues (Stream is not Sendable, decoders are not Sendable before '22 OSes). So in addition to the false issue count, any way to hide the result entire, as none of them are actual safety issues?

jshier avatar Jan 10 '25 20:01 jshier

The error count for APNSwift package drops to 0 with Xcode-16.3.0-Beta.2 but GRDB still reports 9 errors, as it did with Swift 6.1.

I suspect the patch hasn't landed in Xcode yet and APNSwift has seen an improvement for other reasons.

finestructure avatar Mar 12 '25 10:03 finestructure

ATCryptography doesn't show any data race issues when building on macOS or Linux. However, SPI is reporting that there are four errors (on macOS, visionOS and Linux) and eight errors (on watchOS), but the logs doesn't show anything that suggests this is the case.

MasterJ93 avatar Apr 01 '25 02:04 MasterJ93

I retested the packages that reported false positives with the versions tested at the time:

  • APNSwift 5.1.0 now reports 0 errors ✅
  • jwt-kit 5.0.0-rc.2 now reports 0 errors ✅
  • GRDB v7.0.0-beta.2 now reports 9 errors
    • v7.0.0 also reports 9 errors
    • v7.4.1 also reports 9 errors
    • this appears to be correct, however, see the log extract below ✅
    • these errors disappear when building with Swift 6.0, so these are new warnings that we correctly identify
/private/var/folders/nk/tlpts6bs799038htr6rx1xnc0000gn/T/565B2E7D-6A15-4D7A-8E3D-262888B398CE/checkout/GRDB/Record/EncodableRecord.swift:243:28: warning: type 'Any' does not conform to the 'Sendable' protocol
241 |         // guarantee some stability in order to ease record comparison
242 |         encoder.outputFormatting = .sortedKeys
243 |         encoder.userInfo = databaseEncodingUserInfo
    |                            `- warning: type 'Any' does not conform to the 'Sendable' protocol
244 |         return encoder
245 |     }
  • Hummingbird 2.0.0-rc.5 now reports 2 errors
    • again, this appears to be correct, see the log below ✅
    • these errors disappear when building with Swift 6.0, so these are new warnings that we correctly identify
/private/var/folders/nk/tlpts6bs799038htr6rx1xnc0000gn/T/E0064427-AAC5-47D6-A969-F291292AB451/checkout/Sources/HummingbirdTLS/TLSChannel.swift:40:44: warning: type 'NIOSSLServerHandler' does not conform to the 'Sendable' protocol
38 |     @inlinable
39 |     public func setup(channel: Channel, logger: Logger) -> EventLoopFuture<Value> {
40 |         return channel.pipeline.addHandler(NIOSSLServerHandler(context: self.sslContext)).flatMap {
   |                                            `- warning: type 'NIOSSLServerHandler' does not conform to the 'Sendable' protocol
41 |             self.baseChannel.setup(channel: channel, logger: logger)
42 |         }

finestructure avatar May 10 '25 15:05 finestructure

Hello,

I add a comment here because even if this issue is closed, it is still linked from the What is data race safety and how is it tested? FAQ.

https://swiftpackageindex.com/groue/AsyncQueues reports "Has data race safety errors", which I can not replicate from within Xcode.

groue avatar Jun 06 '25 10:06 groue

https://swiftpackageindex.com/groue/Queue reports "Has data race safety errors", which I can not replicate from within Xcode.

Ok, it looks like the false positives are not completely fixed. I can both reproduce that there are no errors building the package and that the build reports two warnings via the "stats" mechanism that we're using to detect Swift 6 errors, both with Xcode 16.4 as well as 16.3:

 sas  …/AsyncQueues   main ? 
 rm .stats/* ; swift package clean ; env DEVELOPER_DIR=/Applications/Xcode-16.4.0.app xcrun swift build --arch arm64 -Xswiftc -Xfrontend -Xswiftc -stats-output-dir -Xswiftc -Xfrontend -Xswiftc .stats -Xswiftc -strict-concurrency=complete -Xswiftc -enable-upcoming-feature -Xswiftc StrictConcurrency && grep Swift6 .stats/*-all-*.json
Building for debugging...
[10/10] Emitting module AsyncQueues
Build complete! (3.61s)
	"Sema.NumSwift6Errors": 2,

 sas  …/AsyncQueues   main ? 
 rm .stats/* ; swift package clean ; env DEVELOPER_DIR=/Applications/Xcode-16.3.0.app xcrun swift build --arch arm64 -Xswiftc -Xfrontend -Xswiftc -stats-output-dir -Xswiftc -Xfrontend -Xswiftc .stats -Xswiftc -strict-concurrency=complete -Xswiftc -enable-upcoming-feature -Xswiftc StrictConcurrency && grep Swift6 .stats/*-all-*.json
Building for debugging...
[10/10] Compiling AsyncQueues Mutex.swift
Build complete! (3.78s)
	"Sema.NumSwift6Errors": 2,

cc @hborla

Thanks for the report, @groue !

finestructure avatar Jun 07 '25 07:06 finestructure