Skip to content

Commit ba7f2ff

Browse files
committed
burp 1.0
1 parent 7d62c54 commit ba7f2ff

File tree

1 file changed

+70
-87
lines changed

1 file changed

+70
-87
lines changed

Diff for: proposals/NNNN-migration-tooling-for-upcoming-features.md renamed to proposals/NNNN-adoption-tooling-for-swift-features.md

+70-87
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,23 @@
99

1010
## Introduction
1111

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.
1515
Many upcoming features have a mechanical migration, meaning the compiler can
1616
determine the exact source changes necessary to allow the code to compile under
1717
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.
2221

2322
## Motivation
2423

25-
Adopting certain features is a time-consuming endeavor at the least.
2624
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.
3129
*Our* responsibility is to make that an easier task for everybody.
3230

3331
### User intent
@@ -38,21 +36,22 @@ intent.
3836
Is the developer expecting guidance on adopting an improvement?
3937
All the compiler knows to do when a feature is enabled is to compile code
4038
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.
4543

4644
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]:
5655

5756
> the Language Steering Group believes that separate migration tooling to
5857
> 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]:
6160
6261
### Automation
6362

64-
Many existing and prospective upcoming features come with simple and reliable
63+
Many existing and prospective upcoming features account for simple and reliable
6564
migration paths to facilitate adoption:
6665

6766
* [`NonfrozenEnumExhaustivity`][SE-0192]: Restore exhaustivity with
@@ -79,32 +78,17 @@ migration paths to facilitate adoption:
7978
* [`DisableOutwardActorInference`][SE-0401]: Specify global actor isolation
8079
explicitly.
8180
* [`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)`.
8683
* [`MemberImportVisibility`][SE-0444]: Add explicit imports appropriately.
8784
* [`InferSendableFromCaptures`][SE-0418]: Suppress inference with coercions
8885
and type annotations.
8986
* [Inherit isolation by default for async functions][async-inherit-isolation-pitch]:
9087
Mark nonisolated functions with the proposed attribute.
9188

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.
10892

10993
## Proposed solution
11094

@@ -115,39 +99,35 @@ leveraged to build better supportive adoption experiences for developers.
11599
If enabling a feature communicates an intent to *enact* rules, adoption mode
116100
communicates an intent to *adopt* them.
117101
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.
120104

121105
This proposal will support the set of existing upcoming features that
122106
have mechanical migrations, as described in the [Automation](#automation)
123107
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.
127112

128113
## Detailed design
129114

130115
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
132117
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.
136119

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.
137125
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
139127
have a mechanical migration.
140128
A corresponding warning will be emitted in this case to avoid the false
141129
impression that the impacted source code is compatible with the feature.
142130

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-
151131
### Interface
152132

153133
#### Compiler
@@ -233,22 +213,22 @@ SwiftSetting.enableUpcomingFeature("InternalImportsByDefault", mode: .adoption)
233213
### Diagnostics
234214

235215
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.
239219

240220
## Source compatibility
241221

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.
244224

245225
## ABI compatibility
246226

247227
This proposal does not affect binary compatibility or binary interfaces.
248228

249229
## Implications on adoption
250230

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
252232
potentially source-breaking action.
253233

254234
## Future directions
@@ -257,22 +237,23 @@ potentially source-breaking action.
257237

258238
For some upcoming features, a source change which alters the semantics of
259239
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 an upcoming 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.
264245

265-
### Applications beyond migration
246+
### Applications beyond mechanical migration
266247

267-
Adoption mode can be extrapolated to additive features, such as
248+
Adoption mode can also be extrapolated to additive features, such as
268249
[typed `throws`][SE-0413] or [opaque parameter types][SE-0341], by providing
269250
actionable adoption tips.
270251
Additive features are hard-enabled and become an integral part of the language
271252
as soon as they ship.
272253
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.
276257

277258
Another potential direction for adoption mode is promotion of best practices.
278259

@@ -288,22 +269,24 @@ is essential for future tools built around adoption mode:
288269
This can prove especially handy when multiple features are simultaneously
289270
enabled in adoption mode, or when similar diagnostic messages are caused by
290271
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.
293276

294277
### `swift adopt`
295278

296279
The Swift package manager could implement an `adopt` subcommand for interactive
297280
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`.
299282

300283
## Alternatives considered
301284

302285
### Naming
303286

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.
307290

308291
## Acknowledgements
309292

@@ -326,9 +309,10 @@ Special thanks to Holly for her guidance throughout the draft stage.
326309
[SE-0352]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md
327310
[SE-0354]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0354-regex-literals.md
328311
[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
330313
[SE-0383]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0383-deprecate-uiapplicationmain-and-nsapplicationmain.md
331314
[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
332316
[SE-0409]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md
333317
[SE-0411]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
334318
[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.
338322
[SE-0434]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0434-global-actor-isolated-types-usability.md
339323
[SE-0444]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md
340324
[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

Comments
 (0)