Description
When building a project that depends on swift-snapshot-testing with Swift 6.2 strict concurrency checking enabled (-strict-concurrency=complete), the compiler reports data races on several global var declarations that can be accessed concurrently from parallel tests.
Affected globals
| File |
Variable |
Issue |
AssertSnapshot.swift |
__diffTool |
Bare var with no synchronization |
AssertSnapshot.swift |
__record |
Bare var with no synchronization |
AssertSnapshot.swift |
CleanCounterBetweenTestCases.registered |
Non-atomic read-modify-write |
Deprecations.swift |
recordings |
Bare var dictionary, concurrent access from inline snapshot writes |
AssertInlineSnapshot.swift |
testSourceCache |
Bare dictionary, concurrent reads/writes |
PlistEncoder.swift |
_plistNullNSString |
Global let of NSString triggers isolation warning |
Reproduction
- Add swift-snapshot-testing as a dependency
- Build with Swift 6.2 toolchain and
-strict-concurrency=complete
- Observe data race warnings on the globals listed above
Suggested fix
Wrap mutable globals in a lock-protected container (e.g., NSLock-based wrapper with @unchecked Sendable). A Mutex (SE-0433) would be ideal but requires iOS 18+ / macOS 15+, which is above this library's deployment targets.
See #1072 for a proposed fix.
Description
When building a project that depends on swift-snapshot-testing with Swift 6.2 strict concurrency checking enabled (
-strict-concurrency=complete), the compiler reports data races on several globalvardeclarations that can be accessed concurrently from parallel tests.Affected globals
AssertSnapshot.swift__diffToolvarwith no synchronizationAssertSnapshot.swift__recordvarwith no synchronizationAssertSnapshot.swiftCleanCounterBetweenTestCases.registeredDeprecations.swiftrecordingsvardictionary, concurrent access from inline snapshot writesAssertInlineSnapshot.swifttestSourceCachePlistEncoder.swift_plistNullNSStringletofNSStringtriggers isolation warningReproduction
-strict-concurrency=completeSuggested fix
Wrap mutable globals in a lock-protected container (e.g.,
NSLock-based wrapper with@unchecked Sendable). AMutex(SE-0433) would be ideal but requires iOS 18+ / macOS 15+, which is above this library's deployment targets.See #1072 for a proposed fix.