Skip to content

Build every target in Swift 6 language mode - #9

Merged
drewmccormack merged 3 commits into
mainfrom
swift6
Sep 18, 2026
Merged

drewmccormack merged 3 commits into
mainfrom
swift6

Conversation

@drewmccormack

Copy link
Copy Markdown
Contributor

All 11 targets now build in Swift 6 language mode, so the compiler checks concurrency strictly. This was audit item 30.

Strict checking earned its keep: it found real races in CloudKitExchange, not just annotation work.

  • Query records were collected from two different callbacks with no lock.
  • The cached restoration state was read, changed and written back in separate steps, so concurrent callbacks could lose version IDs, and those versions would never sync.
  • store was a public var, and the temporary directory a lazy var, which is not thread-safe. BoxExchange had the same lazy var.

The rest is mostly marking value types Sendable. Classes that keep their state under a lock or in an actor declare @unchecked Sendable; a reviewer audited each of those promises against the stored properties.

Two other real fixes fell out of it. Cache's generation type is now a struct, which ends the aliasing that made every generation the same object. Log.level is behind a Mutex, so it can be set from any thread.

Source breaking

  • Exchange and Zone require Sendable. A custom conformance in your own code must be Sendable too.
  • Cache gained a ValueType: Sendable constraint, and its methods take some Hashable & Sendable instead of AnyHashable.
  • @Atomic is renamed to @Guarded. The standard library now has its own Atomic, and the two names clashed.

Both sample apps build with no changes, so ordinary use of the framework is unaffected.

208 tests pass, and swift build --enable-all-traits is clean.

All 11 targets move from .swiftLanguageMode(.v5) to .v6, so the compiler
checks concurrency strictly.

- The public value types are Sendable: Version, Value, Value.Change,
  Value.Fork, ZoneReference, Map nodes, Branch, SnapshotManifest,
  SnapshotPolicy and their nested types. The Exchange and Zone protocols
  require Sendable. SOURCE BREAKING for anyone with their own conformance.
- Classes that hold their state under a lock, or in an actor, declare
  @unchecked Sendable: Store, FileZone, SQLiteZone, and the exchanges. The
  exchange classes are final now.
- Log is Sendable. Its level is behind a Mutex, so it can be set from any
  thread. The global `log` needed this.
- Cache is Sendable. Its generation type is a struct, which also ends the
  aliasing that made every generation the same object. Keys are wrapped in
  a Sendable box, so the methods take `some Hashable & Sendable`.
- @atomic is renamed to @guarded. The standard library now has its own
  Atomic, and the two names clashed.

Strict checking found real races in CloudKitExchange, all fixed:
- Query records were collected from two callbacks with no lock.
- The cached restoration state was read, changed and written back in
  separate steps, so concurrent callbacks could lose version IDs.
- Its store property was a public var, and its temporary directory a lazy
  var. BoxExchange had the same lazy var.

The samples build unchanged. Storage now documents that implementations
must be thread-safe, because Store vouches for them.
Swift 6.1.2 rejects capturing a non-Sendable closure in the operation
queue block. Swift 6.4, which I build with locally, accepts it.
Swift 6.1.2 requires the thrown error to be Sendable, and bindingFailed
carried an Any?. It now carries a description string, which is what the
value was used for anyway. SOURCE BREAKING for anyone matching that case.
@drewmccormack
drewmccormack merged commit ce7cc1c into main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant