What are upcoming features and experimental features, and how do they help a migration?
Predict first
What does the compiler say about this with ExistentialAny enabled (in mode 5)?
protocol Shape {}
func draw(_ s: Shape) {}
- Nothing
- A warning that the protocol must be written as any Shape
Predict first
And without the feature?
protocol Shape {}
func draw(_ s: Shape) {}
- Nothing
- A warning
Mental model. Upcoming features are fire drills held before the real law changes. You practise one at a time, so no one is surprised on the day it becomes mandatory.
Many language changes are source-breaking, so they cannot simply be switched on for everyone. Instead each ships as an upcoming feature with its own name and proposal number, which you can enable individually before the language mode that will make it the default: -enable-upcoming-feature ExistentialAny on the command line, .enableUpcomingFeature("ExistentialAny") in a SwiftPM target, or a build setting in Xcode. Some become the default in a later language mode, others remain opt-in.
That is the migration tool: adopt features one at a time, each producing a manageable set of diagnostics, instead of facing every change at once. For example, ExistentialAny asks you to write any Shape instead of the bare protocol name, first as warnings. Experimental features (-enable-experimental-feature) are different: unstable, may change or disappear, and not for shipping code. Keep a list of the features your project has adopted, and let CI build with them so a new file cannot regress.
With the feature on, using a protocol name as a type without any is diagnosed as something that will become an error.
The bare protocol name is accepted silently in this mode.
Common traps
- Enabling an experimental feature in production code. It may change shape or vanish in the next toolchain.
- Turning on several upcoming features at once. You lose the ability to tell which change caused which diagnostics.
They might follow up with
- How do you find the available names? The compiler’s feature list, and the Swift Evolution proposal for each.
- Are warnings from a feature errors later? Often yes: a warning now means an error in the language mode that makes it standard.
Related questions
- 5.7.1 What is the difference between the Swift 6 compiler and Swift 6 language mode?
- 5.7.3 How would you migrate a large codebase to Swift 6 without a freeze?
- 1.4.2 some View vs any View — what is the difference, and why does SwiftUI use some?
← What is the difference between the Swift 6 compiler and Swift 6… How would you migrate a large codebase to Swift 6 without a freeze? →