10
10
## Introduction
11
11
12
12
In Swift 5.8 introduced [ upcoming features] [ SE-0362 ] ,
13
- which enabled piecemeal adoption of individual source incompatible
14
- changes that are enabled by default in a new langauge mode.
13
+ which enabled piecemeal adoption of individual source- incompatible changes that
14
+ are included in a language mode.
15
15
Many upcoming features have a mechanical migration, meaning the compiler can
16
- determine the exact source changes necessary to allow the code to compile under
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 tools that produce the necessary source code
20
- changes automatically for a given set of upcoming features that a programmer
21
- wants to enable.
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.
22
22
23
23
## Motivation
24
24
25
- Whether you are adjusting code to follow new language rules or researching ways
26
- to apply new functionality, adopting features can be a time-consuming endeavor
27
- at the least.
28
-
29
- Some source-breaking language features are anticipated to generate hundreds
30
- of targeted errors in sizable projects.
31
- Occasionally, errors will also cascade down the dependecy graph or fall out
32
- from changes in behavior without a clear indication of the precise cause or source of
33
- the issue, requiring further investigation.
34
- Developers are left to either resolve all of these errors or address a subset
35
- and take the risk of switching the feature back off before they can resume
36
- development and focus on other important tasks.
37
-
38
- ### User Intent
39
-
40
- > [ !CAUTION]
41
- > TODO: No way for users to declare an intetion to adopt a feature
25
+ Adopting certain features is a time-consuming endeavor at the least.
26
+ 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.
31
+ * Our* responsibility is to make that an easier task for everybody.
32
+
33
+ ### User intent
34
+
35
+ A primary limiting factor in how proactively and accurately the compiler can
36
+ assist developers with adopting a feature is a lack of comprehension of user
37
+ intent.
38
+ Is the developer expecting guidance on adopting an improvement?
39
+ All the compiler knows to do when a feature is enabled is to compile code
40
+ 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.
45
+
46
+ 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
+ [ ` ConciseMagicFile ` ] [ SE-0274 ] , which changes the meaning of an existing
49
+ literal.
42
50
43
51
### Automation
44
52
45
53
Many existing and prospective upcoming features imply or implement simple and
46
- consistent code modifications to facilitate adoption processes :
54
+ consistent source modifications to facilitate adoption:
47
55
48
56
* [ ` NonfrozenEnumExhaustivity ` ] [ SE-0192 ] : Restore exhaustivity with
49
57
` @unknown default: ` .
@@ -72,14 +80,15 @@ consistent code modifications to facilitate adoption processes:
72
80
73
81
Extending diagnostic metadata to include information that allows for
74
82
recognizing these diagnostics and distinguishing semantics-preserving fix-its
75
- from alternative source changes would open up numerous opportunities for
83
+ from alternative source changes will open up numerous opportunities for
76
84
higher-level tools — ranging from the Swift package manager to IDEs — to
77
- implement powerful solutions for organizing, automating, and tuning code
78
- migration processes.
85
+ implement powerful solutions for organizing, automating, and tuning feature
86
+ adoption processes.
79
87
80
- It's not always feasible for an upcoming feature to have a mechanical
81
- migration path. For example, the following upcoming features require manual
82
- migration:
88
+ It is not always feasible or in line with language design principles for an
89
+ upcoming feature to have a mechanical migration path.
90
+ For example, the following upcoming features require manual migration to
91
+ preserve semantics:
83
92
84
93
* [ ` DynamicActorIsolation ` ] [ SE-0423 ]
85
94
* [ ` GlobalActorIsolatedTypesUsability ` ] [ SE-0434 ]
@@ -91,7 +100,7 @@ migration:
91
100
Introduce the notion of an "adoption" mode for individual experimental and
92
101
upcoming features.
93
102
The core idea behind adoption mode is a declaration of intent that can be
94
- leveraged to build holistic supportive adoption experiences for developers.
103
+ leveraged to build better supportive adoption experiences for developers.
95
104
If enabling a feature communicates an intent to * enact* rules, adoption mode
96
105
communicates an intent to * adopt* them.
97
106
An immediate benefit of adoption mode is the capability to deliver source
@@ -100,37 +109,43 @@ existing code whenever the feature provides for them.
100
109
101
110
This proposal will support the set of existing upcoming features that
102
111
have mechanical migrations, as described in the [ Automation] ( #automation )
103
- section. All future proposals that introduce new upcoming features should
104
- include a mechanical migration via adoption mode in the Source compatibility
105
- section of the proposal.
112
+ section.
113
+ All future proposals that introduce a new upcoming feature and provide a
114
+ mechanical migration are expected to support adoption mode and detail its
115
+ behavior in the * Source compatibility* section of the proposal.
106
116
107
117
## Detailed design
108
118
109
119
### Behavior
110
120
111
- Adoption mode should deliver guidance in the shape of warnings, notes, remarks,
112
- and fix-its, as and when appropriate.
113
-
114
121
The action of enabling a previously disabled source-breaking feature in adoption
115
- mode per se must never produce compilation errors.
116
- Additionally, this action will have no effect on the state of the feature if
117
- it does not implement the mode.
122
+ mode per se must not cause compilation errors .
123
+ Additionally, this action will have no effect if the mode is not supported.
118
124
A corresponding warning will be emitted in this case to avoid the false
119
125
impression that the impacted source code is compatible with the feature.
120
126
121
127
> [ !NOTE]
122
128
> Experimental features can be both additive and source-breaking.
123
129
> Upcoming features are necessarily source-breaking.
124
130
125
- When implemented, adoption mode for upcoming features is expected to anticipate
126
- and call out any behavioral differences that will result from enacting the
127
- feature, coupling diagnostic messages with counteracting source-compatible
128
- changes and helpful alternatives whenever possible.
129
- Adoption mode cannot guarantee to provide exclusively source-compatible
130
- modifications because the impact of a change on dependent source code is
131
- generally unpredictable.
132
- Neither can it promise to always offer fix-its in the first place for the
133
- same reason in regards to user intention.
131
+ Adoption mode should deliver guidance in the shape of regular diagnostics.
132
+ For arbitrary upcoming features, adoption mode is expected to anticipate and
133
+ call out any compatibility issues that result from enacting the feature,
134
+ coupling diagnostic messages with counteracting compatible changes and helpful
135
+ alternatives whenever feasible.
136
+ Compatibility issues encompass both source and binary compatibility issues,
137
+ including behavioral changes.
138
+
139
+ Note that adoption mode does not provide any new general guarantees in respect
140
+ to fix-its.
141
+ We cannot promise to offer exclusively compatible modifications.
142
+ Besides the impact of a change on dependent source code being generally
143
+ unpredictable, it can be reasonable to couple compatible fix-its with
144
+ potentially incompatible, albeit better, alternatives, as in ` any P ` → ` some P ` .
145
+ The same stands for provision of modifications — features might not have a
146
+ mechanical migration path, and the compiler remains inherently limited in the
147
+ extent to which it can make assumptions about what is helpful or best for the
148
+ programmer.
134
149
135
150
### Interface
136
151
@@ -217,14 +232,10 @@ SwiftSetting.enableUpcomingFeature("InternalImportsByDefault", mode: .adoption)
217
232
### Diagnostics
218
233
219
234
Diagnostics emitted in relation to a specific feature in adoption mode must
220
- belong to a diagnostic group named after the feature.
221
- There are several reasons why this will be useful:
222
- * Future feature-oriented adoption tooling can use the group identifier to
223
- filter out relevant diagnostics.
224
- * IDEs and other diagnostic consumers can integrate group identifiers into
225
- their interfaces to, well, group diagnostics, as well as to communicate
226
- relationships between diagnostics and features. This can prove especially
227
- handy when multiple features are simultaneously enabled in adoption mode.
235
+ belong to a diagnostic group named after the feature. The names of diagnostic
236
+ groups can be displayed along with diagnostic messages using
237
+ ` -print-diagnostic-groups ` and can be used to associate a message with a
238
+ particular feature.
228
239
229
240
## Source compatibility
230
241
@@ -237,43 +248,59 @@ This proposal does not affect binary compatibility or binary interfaces.
237
248
238
249
## Implications on adoption
239
250
240
- Demoting an enabled source-breaking feature to adoption mode may affect
241
- behavior and is therefore a potentially source-breaking action.
251
+ Entering or exiting adoption mode may affect behavior and is therefore a
252
+ potentially source-breaking action.
242
253
243
254
## Future directions
244
255
245
- ### Augment diagnostic metadata
246
-
247
-
248
-
249
- ### Support baseline features
250
-
251
- Adoption mode can be extrapolated to baseline features, such as ` TypedThrows `
252
- or [ opaque parameter types] [ SE-0341 ] , with an emphasis on actionable adoption
253
- tips and otherwise unsolicited educational notes.
254
- These additive features are hard-enabled in all language modes and become an
255
- integral part of the language as soon as they ship.
256
- Baseline feature identifiers are currently kept around for the sole purpose of
257
- supporting [ feature availability checks] [ feature-detection ] in conditional
258
- compilation blocks.
256
+ ### Applications beyond migration
257
+
258
+ Adoption mode can be extrapolated to additive features, such as
259
+ [ ` typed throws ` ] [ SE-0413 ] or [ opaque parameter types] [ SE-0341 ] , by providing
260
+ actionable adoption tips.
261
+ Additive features are hard-enabled and become an integral part of the language
262
+ as soon as they ship.
263
+ Many recent additive features are already integrated into the Swift feature
264
+ model and kept around for the sole purpose of supporting
265
+ [ feature availability checks] [ feature-detection ] in conditional compilation
266
+ blocks.
267
+
268
+ Another potential direction for adoption mode is promotion of best practices.
269
+
270
+ ### Augmented diagnostic metadata
271
+
272
+ The current serialization format for diagnostics does not include information
273
+ about diagnostic groups or whether a particular fix-it preserves semantics.
274
+ There are several reasons why this data is essential for future tools built
275
+ around adoption mode:
276
+ * The diagnostic group name can be used to, well, group diagnostics, as well as
277
+ to communicate relationships between diagnostics and features and filter out
278
+ relevant diagnostics.
279
+ This can prove especially handy when multiple features are simultaneously
280
+ enabled in adoption mode, or when similar diagnostic messages are caused by
281
+ distinct features.
282
+ * Fix-its that preserve semantics can be prioritized and auto-applied in
283
+ previews.
259
284
260
285
### ` swift adopt `
261
286
262
- The Swift package manager could implement an ` adopt ` subcommand with an
263
- interactive command line interface similar to ` git add --patch ` for selecting
264
- and applying fix-its .. .
287
+ The Swift package manager could implement an ` adopt ` subcommand for interactive
288
+ review and application of adoption mode output for a given set of features,
289
+ with a command line interface similar to ` git add --patch ` .
265
290
266
291
## Alternatives considered
267
292
268
293
### Naming
269
294
270
-
295
+ Perhaps the most intuitive alternative to "adoption" is "migration". We
296
+ settled on the former because there is no reason for this concept to be limited
297
+ to upcoming features or migrational changes.
271
298
272
299
## Acknowledgements
273
300
274
301
This proposal was inspired by documents prepared by [ Allan Shortlidge] [ Allan ]
275
302
and [ Holly Borla] [ Holly ] .
276
- Special thanks to Holly for her feedback throughout the draft stage.
303
+ Special thanks to Holly for her guidance throughout the draft stage.
277
304
278
305
<!-- --------------------------------------------------------------------------->
279
306
@@ -295,6 +322,7 @@ Special thanks to Holly for her feedback throughout the draft stage.
295
322
[ SE-0401 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md
296
323
[ SE-0409 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
297
324
[ SE-0411 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
325
+ [ SE-0413 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0413-typed-throws.md
298
326
[ SE-0412 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
299
327
[ SE-0418 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md
300
328
[ SE-0423 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md
0 commit comments