Skip to content

Commit 60a1491

Browse files
committed
"adopt" -> "migrate" & alternatives considered
* Move SwiftPM changes to alternatives considered * Consider the alternative of an independent command line option * Add more alternative naming considerations
1 parent 8ae57e8 commit 60a1491

File tree

1 file changed

+96
-94
lines changed

1 file changed

+96
-94
lines changed

proposals/NNNN-adoption-tooling-for-swift-features.md

Lines changed: 96 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adoption tooling for Swift features
1+
# Migration tooling for Swift features
22

33
* Proposal: [SE-NNNN](NNNN-filename.md)
44
* Authors: [Anthony Latsis](https://github.com/AnthonyLatsis)
@@ -92,32 +92,30 @@ and testing code where a change in behavior is preferable.
9292

9393
## Proposed solution
9494

95-
Introduce the notion of an "adoption" mode for individual experimental and
95+
Introduce the notion of a ***migrate*** mode for individual experimental and
9696
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
9898
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.
104102

105103
This proposal will support the set of existing upcoming features that
106104
have mechanical migrations, as described in the [Automation](#automation)
107105
section.
108106
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
110108
its behavior alongside the migration paths in the *Source compatibility*
111109
section.
112110

113111
## Detailed design
114112

115-
Upcoming features that have mechanical migrations will support an adoption
113+
Upcoming features that have mechanical migrations will support a migration
116114
mode, which is a new mode of building a project that will produce compiler
117115
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.
119117

120-
The action of enabling a previously disabled upcoming feature in adoption
118+
The action of enabling a previously disabled upcoming feature in migration
121119
mode must not cause any new compiler errors or behavioral changes, and the
122120
fix-its produced must preserve compatibility.
123121
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`.
131129

132130
### Interface
133131

134-
#### Compiler
135-
136132
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:
138134

139135
```
140136
-enable-upcoming-feature <feature>[:<mode>]
141137
-enable-experimental-feature <feature>[:<mode>]
142138
143-
<mode> := adoption
139+
<mode> := migrate
144140
```
145141

146142
For example:
147143

148144
```
149-
-enable-upcoming-feature InternalImportsByDefault:adoption
145+
-enable-upcoming-feature InternalImportsByDefault:migrate
150146
```
151147

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
153149
be emitted.
154150
This warning will belong to the diagnostic group `StrictLanguageFeatures`.
155151
In a series of either of these options applied to a given feature, only the
156152
last option will be honored.
157153
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.
216155

217156
### Diagnostics
218157

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
220159
belong to a diagnostic group named after the feature.
221160
The names of diagnostic groups can be displayed alongside diagnostic messages
222161
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.
232171

233172
## Implications on adoption
234173

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
236175
potentially source-breaking action.
237176

238177
## Future directions
@@ -243,14 +182,14 @@ For some features, a source change that alters the semantics of
243182
the program is a more desirable approach to addressing an error that comes
244183
from enabling the feature.
245184
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
247186
fix-its in cases where the compiler can detect that a different behavior might
248187
be more beneficial.
249188

250189
### Applications beyond mechanical migration
251190

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
254193
actionable adoption tips.
255194
Additive features are hard-enabled and become an integral part of the language
256195
as soon as they ship.
@@ -259,49 +198,112 @@ model, and their metadata is kept around either to support
259198
[feature availability checks][SE-0362-feature-detection] in conditional
260199
compilation blocks or because they started off as experimental features.
261200

262-
Another potential direction for adoption mode is promotion of best practices.
201+
Another feasible extension of migration mode is promotion of best practices.
263202

264203
### Augmented diagnostic metadata
265204

266205
The current serialization format for diagnostics does not include information
267206
about diagnostic groups or whether a particular fix-it preserves semantics.
268207
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:
270209
* The diagnostic group name can be used to, well, group diagnostics, as well as
271210
to communicate relationships between diagnostics and features and filter out
272211
relevant diagnostics.
273212
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
275214
distinct features.
276215
* Exposing the purpose of a fix-it can help developers make quicker decisions
277216
when offered multiple fix-its.
278217
Furthermore, tools can take advantage of this information by favoring and
279218
auto-applying source-compatible fix-its.
280219

281-
### `swift adopt`
220+
### `swift migrate`
282221

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,
285224
with a command-line interface similar to `git add --patch`.
286225

287226
## Alternatives considered
288227

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+
289278
### Naming
290279

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`.
294296

295297
## Acknowledgements
296298

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].
299301
Special thanks to Holly for her guidance throughout the draft stage.
300302

301303
<!-- Links -------------------------------------------------------------------->
302304

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
305307

306308
[SE-0192]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0192-non-exhaustive-enums.md
307309
[SE-0274]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0274-magic-file.md

0 commit comments

Comments
 (0)