Your Swift modules still build in Swift 5 mode with warnings as errors in CI; what policy do you set for enabling upcoming features one at a time before Swift 6 mode?
answer
- per module, per feature, reversible
- gating lane and advisory lane
- exempt a group, keep the policy
- flags expire at the mode switch
- future-mode features are separate
basics
~20 sAdopt one Swift 6 upcoming feature per module per change, keep -warnings-as-errors with named -Wwarning exemptions, preview the next feature in a non-gating lane, and delete each module's feature flags in the change that moves it to Swift 6 mode.
solid answer
~50 sI treat the flags as a dated migration, not a dialect. Each module adopts one Swift 6 upcoming feature per change, leaf modules before the ones that depend on them, starting where the feature's warnings are fewest. The gating CI lane keeps `-warnings-as-errors`, adds `-Werror StrictLanguageFeatures` so a misspelt feature name fails instead of silently doing nothing, and exempts groups the team does not own, such as `-Wwarning DeprecatedDeclaration` after an SDK bump, instead of dropping the policy. A second, non-gating lane builds with the next feature so its warnings become a visible backlog. On Swift 6.4, `@diagnose(Group, as: warning, reason: …)` records a justified local exception. When a module moves to `-language-mode 6`, its Swift 6 feature flags go in the same change, because Swift 6.4 warns that each is "already enabled as of the Swift 6 language mode", and `-warnings-as-errors` makes that fatal. Future-mode features such as `ExistentialAny` are a separate decision.
code
bash · 14 lines# Gating lane: Swift 5 mode, adopted features, warnings fail the build
swiftc -language-mode 5 -parse-as-library -module-name Payments \
-enable-upcoming-feature InferSendableFromCaptures \
-enable-upcoming-feature RegionBasedIsolation \
-warnings-as-errors -Werror StrictLanguageFeatures \
-Wwarning DeprecatedDeclaration \
-typecheck Sources/Payments/*.swift
# Advisory lane: adopted features plus the next one, warnings not fatal
swiftc -language-mode 5 -parse-as-library -module-name Payments \
-enable-upcoming-feature InferSendableFromCaptures \
-enable-upcoming-feature RegionBasedIsolation \
-enable-upcoming-feature StrictConcurrency \
-typecheck Sources/Payments/*.swiftgo deeper
Recall that upcoming features can be enabled one at a time while a module stays in Swift 5 mode, and that CI may treat warnings as errors.
Explain which features Swift 6 mode includes, why flags are per module, and how -Wwarning exempts one group under -warnings-as-errors.
Run a gating lane and an advisory lane, catch misspelt feature names with StrictLanguageFeatures, and remove stale flags when a module changes mode.
Own the order of modules and features, the exemption rules and their expiry, and make future-mode features an explicit team decision rather than drift.
## What the lead is deciding Moving a multi-module Swift codebase to Swift 6 mode is a sequence of small, reversible steps, and the compiler flags are how you sequence them. The decisions a lead owns: - which modules move first; - which upcoming features each module adopts, and in what order; - how the warnings-as-errors policy survives the extra noise; - when each module's feature flags are retired. There is no single right order. It depends on the dependency graph and on where the warnings concentrate. ## The mechanics the policy rests on - Upcoming features are enabled **per module** and do not cross module boundaries, and modules in different language modes link together. Each module can migrate on its own schedule. - Swift 6 mode includes a fixed set: `StrictConcurrency`, `RegionBasedIsolation`, `InferSendableFromCaptures`, `GlobalConcurrency`, `ConciseMagicFile` and others. Future-mode features such as `ExistentialAny` and `MemberImportVisibility` are not on that path. - A misspelt feature name is ignored silently, even under `-warnings-as-errors`, because that warning is off by default until `-Wwarning` or `-Werror StrictLanguageFeatures` names its group. - Since Swift 6.2, `X:migrate` gives fix-it warnings for features that support migration mode, without changing behaviour. - Once a module is in Swift 6 mode, a leftover flag for a feature the mode already includes warns "upcoming feature 'RegionBasedIsolation' already enabled as of the Swift 6 language mode". Under `-warnings-as-errors` that warning is an error, and it carries no group tag, so no `-Wwarning` can exempt it. ## Ordering modules and features Because modes interoperate, any order *works*; the question is which order is cheapest. 1. **Leaf modules first.** A module that depends on nothing else in the app can be fixed without waiting for anyone, and the types it exports become better annotated before the modules that import it start their own checks. 2. **Fewest warnings first, per feature.** Run each candidate feature in the advisory lane, count the warnings per module, and admit the cheap ones to the gate early. Momentum matters: a migration that starts with its largest feature can stall before anything lands. 3. **One feature per change.** A review that mixes two features' fixes is hard to reason about and hard to revert. ## A two-lane CI 1. **Gating lane.** The module's current mode, the features it has adopted, `-warnings-as-errors` and `-Werror StrictLanguageFeatures`. Any new warning blocks the merge. 2. **Advisory lane.** The same module with the next feature turned on, without `-warnings-as-errors`. Its warnings, especially those ending "this is an error in the Swift 6 language mode", are that feature's backlog. 3. When the advisory lane is clean, the feature moves into the gating lane in one change, and the advisory lane takes the next one. `StrictConcurrency` often carries the largest backlog, so it may sit in the advisory lane for a long time while cheaper features move through the gate. ## Exceptions without abandoning the policy - A new SDK deprecates APIs the team cannot replace yet: append `-Wwarning DeprecatedDeclaration` after `-warnings-as-errors`. Do not drop the policy. - One declaration legitimately needs an exception: on Swift 6.4, put `@diagnose(Group, as: warning, reason: "…")` on it, so the exception is visible in review and easy to search for later. - Never reach for `-suppress-warnings`: the compiler refuses it alongside `-warnings-as-errors`, and it hides everything. ## Retiring the flags 1. Move one module to `-language-mode 6` once every Swift 6 feature is adopted and clean. 2. Delete those features' `-enable-upcoming-feature` flags in the same change. 3. Keep future-mode features as an explicit, separate team decision, written down with the reason. ## Trade-offs | Approach | Gains | Costs | |---|---|---| | Flip modules straight to Swift 6 mode | One step, no flag bookkeeping | Every Swift 6 rule lands at once, as errors | | Swift 5 mode plus one feature at a time | Small, reviewable changes | Flag lists to maintain and retire | | Drop `-warnings-as-errors` during migration | Merges unblock quickly | New warnings pile up unseen | | Keep it, with named `-Wwarning` exemptions | Policy stays enforced | Each exemption needs an owner and an end date | The judgment is mostly about the last two rows. A migration that switches the warnings policy off "temporarily" can end with hundreds of warnings nobody reads. A policy with explicit, owned exemptions keeps every new warning visible while the old ones are worked down.
- Why not put every upcoming feature into one shared flag list for all modules?Because features cost different amounts in different modules, and the flags are per module anyway. A shared list forces the slowest module's backlog onto everyone, mixes Swift 6 features with future-mode ones that carry no deadline, and leaves stale flags behind as modules flip. Per-module lists, each trimmed when its module changes mode, keep the migration visible.
- How do you stop a typo in a feature name from silently doing nothing in CI?Add `-Werror StrictLanguageFeatures`. Unrecognized names are ignored by default, and the warning that reports them is off by default, so `-warnings-as-errors` alone never sees it. Naming the group turns the warning on, and `-Werror` makes "'RegionBasedIsolatoin' is not a recognized upcoming feature" fail the build.
- When would you adopt a future-mode feature such as ExistentialAny at all?When the team wants its rule now and accepts that no language mode forces it yet: writing `any` explicitly makes existential costs visible in review. Run `ExistentialAny:migrate` first to get fix-its, then enable the feature, optionally with `-Werror ExistentialAny`. Record it as a choice, since no mode switch will retire that flag on a schedule.
- Turning off -warnings-as-errors for the whole migration is the safe default.
- Enabling an upcoming feature in a core module applies it to every importer.
- Old -enable-upcoming-feature flags are harmless after a module moves to Swift 6 mode.
- Swift 6 mode also brings ExistentialAny, so no separate decision is needed.
- Experimental feature flags are a good way to get ahead of Swift 6 in production.
Assumes Swift 6.4: diagnostic-group flags (6.1), :migrate (6.2) and @diagnose (6.4) are available; the Swift 6 feature set is on in Swift 6 mode, while ExistentialAny and the other future-mode features are not.