@@ -16,13 +16,12 @@ Many upcoming features have a mechanical migration, meaning the compiler can
16
16
determine the exact source changes necessary to allow the code to compile under
17
17
the upcoming feature while preserving the behavior of the code.
18
18
This proposal seeks to improve the experience of enabling individual
19
- upcoming features by providing a mechanism for producing the necessary source
20
- code changes automatically for a given set of upcoming features that a
21
- programmer wants to enable.
19
+ upcoming features by providing an integrated mechanism for producing the
20
+ necessary source code changes automatically for a given set of upcoming
21
+ features that a programmer wants to enable.
22
22
23
23
## Motivation
24
24
25
- Adopting certain features is a time-consuming endeavor at the least.
26
25
It is the responsibility of project maintainers to preserve source (and binary)
27
26
compatibility both internally and externally for library clients when enabling
28
27
an upcoming feature, which can be difficult or tedious without having tools to
@@ -38,21 +37,22 @@ intent.
38
37
Is the developer expecting guidance on adopting an improvement?
39
38
All the compiler knows to do when a feature is enabled is to compile code
40
39
accordingly.
41
- This suffices if a feature merely supplants an existing syntactical construct
42
- or changes the behavior of existing code in strictly predictable ways because
43
- Swift can infer the need to suggest a fix just from spotting certain code
44
- patterns.
40
+ If a upcoming feature supplants an existing grammatical construct or
41
+ invalidates an existing behavior, the language rules alone suffice because
42
+ Swift can consistently infer the irrefutable need to diagnose certain code
43
+ patterns just by spotting them .
45
44
46
45
Needless to say, not all upcoming features fall under these criteria (and not
47
- all features are source-breaking in the first place). Consider
48
- [ ` DisableOutwardActorInference ` ] [ SE-0401 ] , which changes actor isolation
49
- inference of a type that contains an actor-isolated property wrapper. There
50
- is no way for the programmer to specify that they'd like compiler fix-its to
51
- make the existing actor isolation inference explicit. If they enable the
52
- upcoming feature, their code will simply behave differently. This was a
53
- point of debate in the review of SE-0401, and the Language Steering Group
54
- concluded that automatic migration tooling is the right way to address this
55
- particular workflow, as [ noted in the acceptance notes] [ SE-0401-acceptance ] :
46
+ all features are source-breaking in the first place).
47
+ Consider [ ` DisableOutwardActorInference ` ] [ SE-0401 ] , which changes actor
48
+ isolation inference rules with respect to wrapped properties.
49
+ There is no way for the programmer to specify that they'd like compiler fix-its
50
+ to make the existing actor isolation inference explicit.
51
+ If they enable the upcoming feature, their code will simply behave differently.
52
+ This was a point of debate in the review of [ SE-0401] , and the Language
53
+ Steering Group concluded that automatic migration tooling is the right way to
54
+ address this particular workflow, as
55
+ [ noted in the acceptance notes] [ SE-0401-acceptance ] :
56
56
57
57
> the Language Steering Group believes that separate migration tooling to
58
58
> help programmers audit code whose behavior will change under Swift 6 mode
@@ -61,7 +61,7 @@ particular workflow, as [noted in the acceptance notes][SE-0401-acceptance]:
61
61
62
62
### Automation
63
63
64
- Many existing and prospective upcoming features come with simple and reliable
64
+ Many existing and prospective upcoming features account for simple and reliable
65
65
migration paths to facilitate adoption:
66
66
67
67
* [ ` NonfrozenEnumExhaustivity ` ] [ SE-0192 ] : Restore exhaustivity with
@@ -80,31 +80,18 @@ migration paths to facilitate adoption:
80
80
explicitly.
81
81
* [ ` InternalImportsByDefault ` ] [ SE-0409 ] : ` import X ` → ` public import X ` .
82
82
* [ ` GlobalConcurrency ` ] [ SE-0412 ] :
83
- - Convert the global variable to a ` let ` (or)
84
- - ` @MainActor ` -isolate it (or)
85
- - Mark it with ` nonisolated(unsafe) `
83
+ - Convert the global variable to a ` let ` , or
84
+ - ` @MainActor ` -isolate it, or
85
+ - Mark it with ` nonisolated(unsafe) ` .
86
86
* [ ` MemberImportVisibility ` ] [ SE-0444 ] : Add explicit imports appropriately.
87
87
* [ ` InferSendableFromCaptures ` ] [ SE-0418 ] : Suppress inference with coercions
88
88
and type annotations.
89
89
* [ Inherit isolation by default for async functions] [ async-inherit-isolation-pitch ] :
90
90
Mark nonisolated functions with the proposed attribute.
91
91
92
- Extending diagnostic metadata to include information that allows for
93
- recognizing these diagnostics and distinguishing semantics-preserving fix-its
94
- from alternative source changes will open up numerous opportunities for
95
- higher-level tools — ranging from the Swift package manager to IDEs — to
96
- implement powerful solutions for organizing, automating, and tuning feature
97
- adoption processes.
98
-
99
- It is not always feasible or in line with language design principles for an
100
- upcoming feature to have a mechanical migration path.
101
- For example, the following upcoming features require manual migration to
102
- preserve semantics:
103
-
104
- * [ ` DynamicActorIsolation ` ] [ SE-0423 ]
105
- * [ ` GlobalActorIsolatedTypesUsability ` ] [ SE-0434 ]
106
- * [ ` StrictConcurrency ` ] [ SE-0337 ]
107
- * [ ` IsolatedDefaultValues ` ] [ SE-0411 ]
92
+ Application of these adjustments can be fully automated in favor of preserving
93
+ behavior, saving time for more important tasks, such as identifying, auditing
94
+ and testing code where a change in behavior is preferable.
108
95
109
96
## Proposed solution
110
97
@@ -115,39 +102,34 @@ leveraged to build better supportive adoption experiences for developers.
115
102
If enabling a feature communicates an intent to * enact* rules, adoption mode
116
103
communicates an intent to * adopt* them.
117
104
An immediate benefit of adoption mode is the capability to deliver source
118
- modifications that can be applied to preserve or improve the behavior of
119
- existing code whenever the feature provides for them.
105
+ modifications that can be applied to preserve compatibility whenever the
106
+ feature provides for them.
120
107
121
108
This proposal will support the set of existing upcoming features that
122
109
have mechanical migrations, as described in the [ Automation] ( #automation )
123
110
section.
124
111
All future proposals that introduce a new upcoming feature and provide a
125
- mechanical migration are expected to support adoption mode and detail its
126
- behavior in the * Source compatibility* section of the proposal.
112
+ mechanical migration should support adoption mode and detail the migration
113
+ paths in the * Source compatibility* section of the proposal.
127
114
128
115
## Detailed design
129
116
130
117
Upcoming features that have mechanical migrations will support an adoption
131
- mode, which is a a new mode of building a project that will produce compiler
118
+ mode, which is a new mode of building a project that will produce compiler
132
119
warnings with attached fix-its that can be applied to preserve the behavior
133
- of the code when the upcoming feature is enabled. Adoption mode must not
134
- cause any new compiler errors, and the fix-its produced must preserve the
135
- source compatibility and behavior of the code.
120
+ of the code when the upcoming feature is enabled.
136
121
122
+ The action of enabling a previously disabled upcoming feature in adoption
123
+ mode must not cause any new compiler errors or behavioral changes, and the
124
+ fix-its produced must preserve compatibility.
125
+ Compatibility here refers to both source and binary compatibility, as well as
126
+ to behavior.
137
127
Additionally, this action will have no effect if the mode is not supported
138
- for a given upcoming feature, i,e. because the upcoming feature does not
128
+ for a given upcoming feature, i.e., because the upcoming feature does not
139
129
have a mechanical migration.
140
130
A corresponding warning will be emitted in this case to avoid the false
141
131
impression that the impacted source code is compatible with the feature.
142
132
143
- Adoption mode should deliver guidance in the shape of regular diagnostics.
144
- For arbitrary upcoming features, adoption mode is expected to anticipate and
145
- call out any compatibility issues that result from enacting the feature,
146
- coupling diagnostic messages with counteracting compatible changes and helpful
147
- alternatives whenever feasible.
148
- Compatibility issues encompass both source and binary compatibility issues,
149
- including behavioral changes.
150
-
151
133
### Interface
152
134
153
135
#### Compiler
@@ -233,22 +215,22 @@ SwiftSetting.enableUpcomingFeature("InternalImportsByDefault", mode: .adoption)
233
215
### Diagnostics
234
216
235
217
Diagnostics emitted in relation to a specific feature in adoption mode must
236
- belong to a diagnostic group named after the feature. The names of diagnostic
237
- groups can be displayed alongside diagnostic messages using
238
- ` -print-diagnostic-groups ` and used to associate messages with features.
218
+ belong to a diagnostic group named after the feature.
219
+ The names of diagnostic groups can be displayed alongside diagnostic messages
220
+ using ` -print-diagnostic-groups ` and used to associate messages with features.
239
221
240
222
## Source compatibility
241
223
242
- This proposal does not affect language rules. The described changes to the API
243
- surface are source-compatible.
224
+ This proposal does not affect language rules.
225
+ The described changes to the API surface are source-compatible.
244
226
245
227
## ABI compatibility
246
228
247
229
This proposal does not affect binary compatibility or binary interfaces.
248
230
249
231
## Implications on adoption
250
232
251
- Entering or exiting adoption mode may affect behavior and is therefore a
233
+ Entering or exiting adoption mode will affect behavior and is therefore a
252
234
potentially source-breaking action.
253
235
254
236
## Future directions
@@ -257,22 +239,23 @@ potentially source-breaking action.
257
239
258
240
For some upcoming features, a source change which alters the semantics of
259
241
the program is a more desirable approach to addressing an error that comes
260
- from enabling an upcoming feature. For example, programmers might want to
261
- replace cases of ` any P ` with ` some P ` . Adoption tooling could support the
262
- option to produce source incompatible fix-its in cases where the compiler
263
- can detect that a different behavior might be more beneficial.
242
+ from enabling an upcoming feature.
243
+ For example, programmers might want to replace cases of ` any P ` with ` some P ` .
244
+ Adoption tooling could support the option to produce source incompatible
245
+ fix-its in cases where the compiler can detect that a different behavior might
246
+ be more beneficial.
264
247
265
- ### Applications beyond migration
248
+ ### Applications beyond mechanical migration
266
249
267
- Adoption mode can be extrapolated to additive features, such as
250
+ Adoption mode can also be extrapolated to additive features, such as
268
251
[ typed ` throws ` ] [ SE-0413 ] or [ opaque parameter types] [ SE-0341 ] , by providing
269
252
actionable adoption tips.
270
253
Additive features are hard-enabled and become an integral part of the language
271
254
as soon as they ship.
272
255
Many recent additive features are already integrated into the Swift feature
273
256
model and kept around for the sole purpose of supporting
274
- [ feature availability checks] [ feature-detection ] in conditional compilation
275
- blocks.
257
+ [ feature availability checks] [ SE-0362- feature-detection] in conditional
258
+ compilation blocks.
276
259
277
260
Another potential direction for adoption mode is promotion of best practices.
278
261
@@ -288,8 +271,10 @@ is essential for future tools built around adoption mode:
288
271
This can prove especially handy when multiple features are simultaneously
289
272
enabled in adoption mode, or when similar diagnostic messages are caused by
290
273
distinct features.
291
- * Fix-its that preserve semantics can be prioritized and auto-applied in
292
- previews.
274
+ * Exposing the purpose of a fix-it can help developers make quicker decisions
275
+ when offerred multiple fix-its.
276
+ Furthermore, tools can take advantage of this information by favoring and
277
+ auto-applying source-compatible fix-its.
293
278
294
279
### ` swift adopt `
295
280
@@ -301,9 +286,9 @@ with a command line interface similar to `git add --patch`.
301
286
302
287
### Naming
303
288
304
- Perhaps the most intuitive alternative to "adoption" is "migration". We
305
- settled on the former because there is no reason for this concept to be limited
306
- to upcoming features or migrational changes.
289
+ Perhaps the most intuitive alternative to "adoption" is "migration".
290
+ We settled on the former because there is no reason for this concept to be
291
+ limited to upcoming features or migrational changes.
307
292
308
293
## Acknowledgements
309
294
@@ -326,9 +311,10 @@ Special thanks to Holly for her guidance throughout the draft stage.
326
311
[ SE-0352 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md
327
312
[ SE-0354 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0354-regex-literals.md
328
313
[ SE-0362 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md
329
- [ feature-detection ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md#feature-detection-in-source-code
314
+ [ SE-0362- feature-detection] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md#feature-detection-in-source-code
330
315
[ SE-0383 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md
331
316
[ SE-0401 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md
317
+ [ SE-0401-acceptance ] : https://forums.swift.org/t/accepted-with-modifications-se-0401-remove-actor-isolation-inference-caused-by-property-wrappers/66241
332
318
[ SE-0409 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
333
319
[ SE-0411 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
334
320
[ SE-0413 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0413-typed-throws.md
@@ -338,4 +324,3 @@ Special thanks to Holly for her guidance throughout the draft stage.
338
324
[ SE-0434 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0434-global-actor-isolated-types-usability.md
339
325
[ SE-0444 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
340
326
[ async-inherit-isolation-pitch ] : https://forums.swift.org/t/pitch-inherit-isolation-by-default-for-async-functions/74862
341
- [ SE-0401-acceptance ] : https://forums.swift.org/t/accepted-with-modifications-se-0401-remove-actor-isolation-inference-caused-by-property-wrappers/66241
0 commit comments