9
9
10
10
## Introduction
11
11
12
- In Swift 5.8 introduced [ upcoming features] [ SE-0362 ] ,
13
- which enabled piecemeal adoption of individual source-incompatible changes that
14
- are included in a language mode.
12
+ Swift 5.8 introduced [ upcoming features] [ SE-0362 ] , which enabled piecemeal
13
+ adoption of individual source-incompatible changes that are included in a
14
+ language mode.
15
15
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
- 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.
18
+ This proposal seeks to improve the experience of enabling individual Swift
19
+ features by providing an integrated mechanism for producing these source code
20
+ modifications automatically.
22
21
23
22
## Motivation
24
23
25
- Adopting certain features is a time-consuming endeavor at the least.
26
24
It is the responsibility of project maintainers to preserve source (and binary)
27
- compatibility both internally and externally for library clients when enabling
28
- an upcoming feature, which can be difficult or tedious without having tools to
29
- help detect possibly inadvertent changes and perform monotonous migration
30
- shenanigans for you.
25
+ compatibility both internally and for library clients when enabling an upcoming
26
+ feature, which can be difficult or tedious without having tools to help detect
27
+ possibly inadvertent changes or perform monotonous migration shenanigans for
28
+ you.
31
29
* Our* responsibility is to make that an easier task for everybody.
32
30
33
31
### User intent
@@ -38,21 +36,22 @@ intent.
38
36
Is the developer expecting guidance on adopting an improvement?
39
37
All the compiler knows to do when a feature is enabled is to compile code
40
38
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.
39
+ If an upcoming feature supplants an existing grammatical construct or
40
+ invalidates an existing behavior, the language rules alone suffice because
41
+ Swift can consistently infer the irrefutable need to diagnose certain code
42
+ patterns just by spotting them .
45
43
46
44
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 ] :
45
+ all features are source-breaking in the first place).
46
+ Consider [ ` DisableOutwardActorInference ` ] [ SE-0401 ] , which changes actor
47
+ isolation inference rules with respect to wrapped properties.
48
+ There is no way for the programmer to specify that they'd like compiler fix-its
49
+ to make the existing actor isolation inference explicit.
50
+ If they enable the upcoming feature, their code will simply behave differently.
51
+ This was a point of debate in the review of [ SE-0401] , and the Language
52
+ Steering Group concluded that automatic migration tooling is the right way to
53
+ address this particular workflow, as
54
+ [ noted in the acceptance notes] [ SE-0401-acceptance ] :
56
55
57
56
> the Language Steering Group believes that separate migration tooling to
58
57
> help programmers audit code whose behavior will change under Swift 6 mode
@@ -61,7 +60,7 @@ particular workflow, as [noted in the acceptance notes][SE-0401-acceptance]:
61
60
62
61
### Automation
63
62
64
- Many existing and prospective upcoming features come with simple and reliable
63
+ Many existing and prospective upcoming features account for simple and reliable
65
64
migration paths to facilitate adoption:
66
65
67
66
* [ ` NonfrozenEnumExhaustivity ` ] [ SE-0192 ] : Restore exhaustivity with
@@ -79,32 +78,17 @@ migration paths to facilitate adoption:
79
78
* [ ` DisableOutwardActorInference ` ] [ SE-0401 ] : Specify global actor isolation
80
79
explicitly.
81
80
* [ ` InternalImportsByDefault ` ] [ SE-0409 ] : ` import X ` → ` public import X ` .
82
- * [ ` GlobalConcurrency ` ] [ SE-0412 ] :
83
- - Convert the global variable to a ` let ` (or)
84
- - ` @MainActor ` -isolate it (or)
85
- - Mark it with ` nonisolated(unsafe) `
81
+ * [ ` GlobalConcurrency ` ] [ SE-0412 ] : Convert the global variable to a ` let ` , or
82
+ ` @MainActor ` -isolate it, or mark it with ` nonisolated(unsafe) ` .
86
83
* [ ` MemberImportVisibility ` ] [ SE-0444 ] : Add explicit imports appropriately.
87
84
* [ ` InferSendableFromCaptures ` ] [ SE-0418 ] : Suppress inference with coercions
88
85
and type annotations.
89
86
* [ Inherit isolation by default for async functions] [ async-inherit-isolation-pitch ] :
90
87
Mark nonisolated functions with the proposed attribute.
91
88
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 ]
89
+ Application of these adjustments can be fully automated in favor of preserving
90
+ behavior, saving time for more important tasks, such as identifying, auditing,
91
+ and testing code where a change in behavior is preferable.
108
92
109
93
## Proposed solution
110
94
@@ -115,39 +99,35 @@ leveraged to build better supportive adoption experiences for developers.
115
99
If enabling a feature communicates an intent to * enact* rules, adoption mode
116
100
communicates an intent to * adopt* them.
117
101
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.
102
+ modifications that can be applied to preserve compatibility whenever a feature
103
+ provides for them.
120
104
121
105
This proposal will support the set of existing upcoming features that
122
106
have mechanical migrations, as described in the [ Automation] ( #automation )
123
107
section.
124
- 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.
108
+ All future proposals that intend to introduce an upcoming feature and
109
+ provide for a mechanical migration should include an adoption mode and detail
110
+ its behavior alongside the migration paths in the * Source compatibility*
111
+ section.
127
112
128
113
## Detailed design
129
114
130
115
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
116
+ mode, which is a new mode of building a project that will produce compiler
132
117
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.
118
+ of the code once the upcoming feature is enacted.
136
119
120
+ The action of enabling a previously disabled upcoming feature in adoption
121
+ mode must not cause any new compiler errors or behavioral changes, and the
122
+ fix-its produced must preserve compatibility.
123
+ Compatibility here refers to both source and binary compatibility, as well as
124
+ to behavior.
137
125
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
126
+ for a given upcoming feature, i.e., because the upcoming feature does not
139
127
have a mechanical migration.
140
128
A corresponding warning will be emitted in this case to avoid the false
141
129
impression that the impacted source code is compatible with the feature.
142
130
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
131
### Interface
152
132
153
133
#### Compiler
@@ -233,46 +213,47 @@ SwiftSetting.enableUpcomingFeature("InternalImportsByDefault", mode: .adoption)
233
213
### Diagnostics
234
214
235
215
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.
216
+ belong to a diagnostic group named after the feature.
217
+ The names of diagnostic groups can be displayed alongside diagnostic messages
218
+ using ` -print-diagnostic-groups ` and used to associate messages with features.
239
219
240
220
## Source compatibility
241
221
242
- This proposal does not affect language rules. The described changes to the API
243
- surface are source-compatible.
222
+ This proposal does not affect language rules.
223
+ The described changes to the API surface are source-compatible.
244
224
245
225
## ABI compatibility
246
226
247
227
This proposal does not affect binary compatibility or binary interfaces.
248
228
249
229
## Implications on adoption
250
230
251
- Entering or exiting adoption mode may affect behavior and is therefore a
231
+ Entering or exiting adoption mode will affect behavior and is therefore a
252
232
potentially source-breaking action.
253
233
254
234
## Future directions
255
235
256
236
### Producing source incompatible fix-its
257
237
258
- For some upcoming features, a source change which alters the semantics of
238
+ For some features, a source change that alters the semantics of
259
239
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.
240
+ from enabling the feature.
241
+ For example, programmers might want to replace cases of ` any P ` with ` some P ` .
242
+ Adoption tooling could support the option to produce source incompatible
243
+ fix-its in cases where the compiler can detect that a different behavior might
244
+ be more beneficial.
264
245
265
- ### Applications beyond migration
246
+ ### Applications beyond mechanical migration
266
247
267
- Adoption mode can be extrapolated to additive features, such as
248
+ Adoption mode can also be extrapolated to additive features, such as
268
249
[ typed ` throws ` ] [ SE-0413 ] or [ opaque parameter types] [ SE-0341 ] , by providing
269
250
actionable adoption tips.
270
251
Additive features are hard-enabled and become an integral part of the language
271
252
as soon as they ship.
272
253
Many recent additive features are already integrated into the Swift feature
273
- model and kept around for the sole purpose of supporting
274
- [ feature availability checks] [ feature-detection ] in conditional compilation
275
- blocks.
254
+ model, and their metadata is kept around either to support
255
+ [ feature availability checks] [ SE-0362- feature-detection] in conditional
256
+ compilation blocks or because they started off as experimental features .
276
257
277
258
Another potential direction for adoption mode is promotion of best practices.
278
259
@@ -288,22 +269,24 @@ is essential for future tools built around adoption mode:
288
269
This can prove especially handy when multiple features are simultaneously
289
270
enabled in adoption mode, or when similar diagnostic messages are caused by
290
271
distinct features.
291
- * Fix-its that preserve semantics can be prioritized and auto-applied in
292
- previews.
272
+ * Exposing the purpose of a fix-it can help developers make quicker decisions
273
+ when offered multiple fix-its.
274
+ Furthermore, tools can take advantage of this information by favoring and
275
+ auto-applying source-compatible fix-its.
293
276
294
277
### ` swift adopt `
295
278
296
279
The Swift package manager could implement an ` adopt ` subcommand for interactive
297
280
review and application of adoption mode output for a given set of features,
298
- with a command line interface similar to ` git add --patch ` .
281
+ with a command- line interface similar to ` git add --patch ` .
299
282
300
283
## Alternatives considered
301
284
302
285
### Naming
303
286
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.
287
+ Perhaps the most intuitive alternative to "adoption" is "migration".
288
+ We settled on the former because there is no reason for this concept to be
289
+ limited to upcoming features or migrational changes.
307
290
308
291
## Acknowledgements
309
292
@@ -326,9 +309,10 @@ Special thanks to Holly for her guidance throughout the draft stage.
326
309
[ SE-0352 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md
327
310
[ SE-0354 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0354-regex-literals.md
328
311
[ 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
312
+ [ SE-0362- feature-detection] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md#feature-detection-in-source-code
330
313
[ SE-0383 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md
331
314
[ SE-0401 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md
315
+ [ SE-0401-acceptance ] : https://forums.swift.org/t/accepted-with-modifications-se-0401-remove-actor-isolation-inference-caused-by-property-wrappers/66241
332
316
[ SE-0409 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
333
317
[ SE-0411 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
334
318
[ SE-0413 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0413-typed-throws.md
@@ -338,4 +322,3 @@ Special thanks to Holly for her guidance throughout the draft stage.
338
322
[ SE-0434 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0434-global-actor-isolated-types-usability.md
339
323
[ SE-0444 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
340
324
[ 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