1
- # Adoption tooling for Swift features
1
+ # Migration tooling for Swift features
2
2
3
3
* Proposal: [ SE-NNNN] ( NNNN-filename.md )
4
4
* Authors: [ Anthony Latsis] ( https://github.com/AnthonyLatsis )
@@ -92,32 +92,30 @@ and testing code where a change in behavior is preferable.
92
92
93
93
## Proposed solution
94
94
95
- Introduce the notion of an "adoption" mode for individual experimental and
95
+ Introduce the notion of a *** migrate *** mode for individual experimental and
96
96
upcoming features.
97
- The core idea behind adoption mode is a declaration of intent that can be
97
+ The core idea behind migration mode is a declaration of intent that can be
98
98
leveraged to build better supportive adoption experiences for developers.
99
- If enabling a feature communicates an intent to * enact* rules, adoption mode
100
- communicates an intent to * adopt* them.
101
- An immediate benefit of adoption mode is the capability to deliver source
102
- modifications that can be applied to preserve compatibility whenever a feature
103
- provides for them.
99
+ If enabling a feature communicates an intent to * enact* rules, migration mode
100
+ communicates an intent to migrate code so as to preserve compatibility once the
101
+ feature is enabled.
104
102
105
103
This proposal will support the set of existing upcoming features that
106
104
have mechanical migrations, as described in the [ Automation] ( #automation )
107
105
section.
108
106
All future proposals that intend to introduce an upcoming feature and
109
- provide for a mechanical migration should include an adoption mode and detail
107
+ provide for a mechanical migration should include a migration mode and detail
110
108
its behavior alongside the migration paths in the * Source compatibility*
111
109
section.
112
110
113
111
## Detailed design
114
112
115
- Upcoming features that have mechanical migrations will support an adoption
113
+ Upcoming features that have mechanical migrations will support a migration
116
114
mode, which is a new mode of building a project that will produce compiler
117
115
warnings with attached fix-its that can be applied to preserve the behavior
118
- of the code once the upcoming feature is enacted .
116
+ of the code under the feature.
119
117
120
- The action of enabling a previously disabled upcoming feature in adoption
118
+ The action of enabling a previously disabled upcoming feature in migration
121
119
mode must not cause any new compiler errors or behavioral changes, and the
122
120
fix-its produced must preserve compatibility.
123
121
Compatibility here refers to both source and binary compatibility, as well as
@@ -131,92 +129,33 @@ This warning will belong to the diagnostic group `StrictLanguageFeatures`.
131
129
132
130
### Interface
133
131
134
- #### Compiler
135
-
136
132
The ` -enable-*-feature ` frontend and driver command line options will start
137
- supporting an optional mode specifier with ` adoption ` as the only valid mode:
133
+ supporting an optional mode specifier with ` migrate ` as the only valid mode:
138
134
139
135
```
140
136
-enable-upcoming-feature <feature>[:<mode>]
141
137
-enable-experimental-feature <feature>[:<mode>]
142
138
143
- <mode> := adoption
139
+ <mode> := migrate
144
140
```
145
141
146
142
For example:
147
143
148
144
```
149
- -enable-upcoming-feature InternalImportsByDefault:adoption
145
+ -enable-upcoming-feature InternalImportsByDefault:migrate
150
146
```
151
147
152
- If the specified mode is invalid, the flag will be ignored, and a warning will
148
+ If the specified mode is invalid, the option will be ignored, and a warning will
153
149
be emitted.
154
150
This warning will belong to the diagnostic group ` StrictLanguageFeatures ` .
155
151
In a series of either of these options applied to a given feature, only the
156
152
last option will be honored.
157
153
If an upcoming feature is both implied by the effective language mode and
158
- enabled in adoption mode using either of the aforementioned options, the latter
159
- will be disregarded.
160
-
161
- #### Swift package manager
162
-
163
- The [ ` SwiftSetting.enableUpcomingFeature ` ] and
164
- [ ` SwiftSetting.enableExperimentalFeature ` ] methods from the
165
- [ ` PackageDescription ` ] ( https://developer.apple.com/documentation/packagedescription )
166
- library will be augmented with a ` mode ` parameter defaulted to match the
167
- current behavior:
168
-
169
- ``` swift
170
- extension SwiftSetting {
171
- @available (_PackageDescription, introduced : 6.2 )
172
- public enum SwiftFeatureMode {
173
- case adoption
174
- case on
175
- }
176
- }
177
- ```
178
- ``` diff
179
- public static func enableUpcomingFeature(
180
- _ name: String,
181
- + mode: SwiftFeatureMode = .on,
182
- _ condition: BuildSettingCondition? = nil
183
- ) -> SwiftSetting {
184
- + let argument = switch mode {
185
- + case .adoption: "\(name):adoption"
186
- + case .mode: name
187
- + }
188
- +
189
- return SwiftSetting(
190
- - name: "enableUpcomingFeature", value: [name], condition: condition)
191
- + name: "enableUpcomingFeature", value: [argument], condition: condition)
192
- }
193
- ```
194
- ``` diff
195
- public static func enableExperimentalFeature(
196
- _ name: String,
197
- + mode: SwiftFeatureMode = .on,
198
- _ condition: BuildSettingCondition? = nil
199
- ) -> SwiftSetting {
200
- + let argument = switch mode {
201
- + case .adoption: "\(name):adoption"
202
- + case .mode: name
203
- + }
204
- +
205
- return SwiftSetting(
206
- - name: "enableExperimentalFeature", value: [name], condition: condition)
207
- + name: "enableExperimentalFeature", value: [argument], condition: condition)
208
- }
209
- ```
210
-
211
- For example:
212
-
213
- ```
214
- SwiftSetting.enableUpcomingFeature("InternalImportsByDefault", mode: .adoption)
215
- ```
154
+ enabled in migration, the latter will be disregarded.
216
155
217
156
### Diagnostics
218
157
219
- Diagnostics emitted in relation to a specific feature in adoption mode must
158
+ Diagnostics emitted in relation to a specific feature in migration mode must
220
159
belong to a diagnostic group named after the feature.
221
160
The names of diagnostic groups can be displayed alongside diagnostic messages
222
161
using ` -print-diagnostic-groups ` and used to associate messages with features.
@@ -232,7 +171,7 @@ This proposal does not affect binary compatibility or binary interfaces.
232
171
233
172
## Implications on adoption
234
173
235
- Entering or exiting adoption mode will affect behavior and is therefore a
174
+ Entering or exiting migration mode can affect behavior and is therefore a
236
175
potentially source-breaking action.
237
176
238
177
## Future directions
@@ -243,14 +182,14 @@ For some features, a source change that alters the semantics of
243
182
the program is a more desirable approach to addressing an error that comes
244
183
from enabling the feature.
245
184
For example, programmers might want to replace cases of ` any P ` with ` some P ` .
246
- Adoption tooling could support the option to produce source incompatible
185
+ Migration tooling could support the option to produce source incompatible
247
186
fix-its in cases where the compiler can detect that a different behavior might
248
187
be more beneficial.
249
188
250
189
### Applications beyond mechanical migration
251
190
252
- Adoption mode can be extrapolated to additive features, such as
253
- [ typed ` throws ` ] [ SE-0413 ] or [ opaque parameter types] [ SE-0341 ] , by providing
191
+ The concept of migration mode could be extrapolated to additive features, such
192
+ as [ typed ` throws ` ] [ SE-0413 ] or [ opaque parameter types] [ SE-0341 ] , by providing
254
193
actionable adoption tips.
255
194
Additive features are hard-enabled and become an integral part of the language
256
195
as soon as they ship.
@@ -259,49 +198,112 @@ model, and their metadata is kept around either to support
259
198
[ feature availability checks] [ SE-0362-feature-detection ] in conditional
260
199
compilation blocks or because they started off as experimental features.
261
200
262
- Another potential direction for adoption mode is promotion of best practices.
201
+ Another feasible extension of migration mode is promotion of best practices.
263
202
264
203
### Augmented diagnostic metadata
265
204
266
205
The current serialization format for diagnostics does not include information
267
206
about diagnostic groups or whether a particular fix-it preserves semantics.
268
207
There are several reasons why this data can be valuable for users, and why it
269
- is essential for future tools built around adoption mode:
208
+ is essential for future tools built around migration mode:
270
209
* The diagnostic group name can be used to, well, group diagnostics, as well as
271
210
to communicate relationships between diagnostics and features and filter out
272
211
relevant diagnostics.
273
212
This can prove especially handy when multiple features are simultaneously
274
- enabled in adoption mode, or when similar diagnostic messages are caused by
213
+ enabled in migration mode, or when similar diagnostic messages are caused by
275
214
distinct features.
276
215
* Exposing the purpose of a fix-it can help developers make quicker decisions
277
216
when offered multiple fix-its.
278
217
Furthermore, tools can take advantage of this information by favoring and
279
218
auto-applying source-compatible fix-its.
280
219
281
- ### ` swift adopt `
220
+ ### ` swift migrate `
282
221
283
- The Swift package manager could implement an ` adopt ` subcommand for interactive
284
- review and application of adoption mode output for a given set of features,
222
+ The Swift package manager could implement a ` migrate ` subcommand for interactive
223
+ review and application of migration mode output for a given set of features,
285
224
with a command-line interface similar to ` git add --patch ` .
286
225
287
226
## Alternatives considered
288
227
228
+ ### A distinct ` -migrate ` option
229
+
230
+ This direction has a questionably balanced set of advantanges and downsides.
231
+ On one hand, it would provide an adequate foundation for invoking migration
232
+ for a language mode in addition to individual features.
233
+ On the other hand, an independent option is less discoverable, has a steeper
234
+ learning curve, and makes the necessary relationships between it and the
235
+ existing ` -enable-*-feature ` options harder to infer.
236
+ Perhaps more notably, a bespoke option by itself would not scale to any future
237
+ modes, setting what might be an unfortunate example for further decentralizion
238
+ of language feature control.
239
+
240
+ ### API for package manifests
241
+
242
+ The decision around surfacing migration mode in the ` PackageDescription `
243
+ library depends on whether there is a concensus on the value of enabling it as
244
+ a persistent setting as opposed to a automated procedure in the long run.
245
+
246
+ Here is how an API change could look like for the proposed solution:
247
+
248
+ ``` swift
249
+ + extension SwiftSetting {
250
+ + @available (_PackageDescription, introduced : 6.2 )
251
+ + public enum SwiftFeatureMode {
252
+ + case migrate
253
+ + case on
254
+ + }
255
+ + }
256
+ ```
257
+ ``` diff
258
+ public static func enableUpcomingFeature(
259
+ _ name: String,
260
+ + mode: SwiftFeatureMode = .on,
261
+ _ condition: BuildSettingCondition? = nil
262
+ ) -> SwiftSetting
263
+
264
+ public static func enableExperimentalFeature(
265
+ _ name: String,
266
+ + mode: SwiftFeatureMode = .on,
267
+ _ condition: BuildSettingCondition? = nil
268
+ ) -> SwiftSetting
269
+ ```
270
+
271
+ It can be argued that both Swift modules and the volume of changes required for
272
+ migration can be large enough to justify spreading the review over several
273
+ sessions, especially if migration mode gains support for parallel
274
+ [ source-incompatible fix-its] [ #producing-source-incompatible-fix-its ] .
275
+ However, we also expect higher-level migration tooling to allow for
276
+ incremental progress.
277
+
289
278
### Naming
290
279
291
- Perhaps the most intuitive alternative to "adoption" is "migration".
292
- We settled on the former because there is no reason for this concept to remain
293
- limited to upcoming features or mechanical migration.
280
+ The next candidates in line per discussions are *** adopt*** , *** audit*** ,
281
+ *** stage*** , and *** preview*** , respectively.
282
+ * *** preview*** and *** stage*** can both be understood as to report on the
283
+ impact of a change, but are less commonly used in the sense of code
284
+ migration.
285
+ * *** audit*** best denotes a recurrent action in this context, which we believe
286
+ is more characteristic of the static analysis domain, such as enforcing a set
287
+ of custom compile-time rules on code.
288
+ * An important reservation about *** adoption*** of source-breaking features is
289
+ that it comprises both code migration and integration.
290
+ It may be more prudent to save this term for a future add-on mode that,
291
+ unlike migration mode, implies that the feature is enabled and can be invoked
292
+ in any language mode to aid developers in making better use of new behaviors
293
+ or rules.
294
+ To illustrate, this mode could appropriately suggest switching from ` any P `
295
+ to ` some P ` for ` ExistentialAny ` .
294
296
295
297
## Acknowledgements
296
298
297
- This proposal was inspired by documents prepared by [ Allan Shortlidge] [ Allan ]
298
- and [ Holly Borla] [ Holly ] .
299
+ This proposal was inspired by documents prepared by [ Allan Shortlidge] and
300
+ [ Holly Borla] .
299
301
Special thanks to Holly for her guidance throughout the draft stage.
300
302
301
303
<!-- Links -------------------------------------------------------------------->
302
304
303
- [ Holly ] : https://github.com/hborla
304
- [ Allan ] : https://github.com/tshortli
305
+ [ Holly Borla ] : https://github.com/hborla
306
+ [ Allan Shortlidge ] : https://github.com/tshortli
305
307
306
308
[ SE-0192 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0192-non-exhaustive-enums.md
307
309
[ SE-0274 ] : https://github.com/swiftlang/swift-evolution/blob/main/proposals/0274-magic-file.md
0 commit comments