Skip to content

Commit 4abdbe4

Browse files
Guidance document fix #9 (#72)
* Guidance document fix #9 * Encorporate feedback, update doc name * Wording, emphasize not a recommendation
1 parent fce55dd commit 4abdbe4

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

Guide.docc/MigrationGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ full code examples, and learn about how to contribute in the [repository][].
6363
### Swift Concurrency in Depth
6464

6565
- <doc:RuntimeBehavior>
66+
- <doc:MigrationStrategy>

Guide.docc/MigrationStrategy.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Migration Strategy
2+
3+
Get recommendations on how to proceed with migrating your project to the
4+
Swift 6 language mode.
5+
6+
Enabling complete concurrency checking in a module can yield many data-race
7+
safety issues reported by the compiler.
8+
Hundreds, possibly even thousands of warnings are not uncommon.
9+
When faced with a such a large number of problems,
10+
especially if you are just beginning to learn about Swift's data isolation
11+
model, this can feel insurmountable.
12+
13+
**Don't panic.**
14+
15+
Frequently, you'll find yourself making substantial progress with just a few
16+
changes.
17+
And as you do, your mental model of how the Swift concurrency system works
18+
will develop just as rapidly.
19+
20+
> Important: This guidance should not be interpreted as a recommendation.
21+
You should feel confident about using other approaches.
22+
23+
## Strategy
24+
25+
This document outlines a general strategy that could be a good starting point.
26+
There is no one single approach that will work for all projects.
27+
28+
The approach has three key steps:
29+
30+
- Select a module
31+
- Enable stricter checking with Swift 5
32+
- Address warnings
33+
34+
This process will be inherently _iterative_.
35+
Even a single change in one module can have a large impact on the state of the
36+
project as a whole.
37+
38+
## Begin from the Outside
39+
40+
It can be easier to start with the outer-most root module in a project.
41+
This, by definition, is not a dependency of any other module.
42+
Changes here can only have local effects, making it possible to
43+
keep work contained.
44+
45+
## Use the Swift 5 Language Mode
46+
47+
You could find it quite challenging to move a project from Swift 5 with no
48+
checking directly to the Swift 6 language mode.
49+
It is possible, instead, to incrementally enable more of the Swift 6 checking
50+
mechanisms while remaining in Swift 5 mode.
51+
This will surface issues only as warnings,
52+
keeping your build and tests functional as you progress.
53+
54+
To start, enable a single upcoming concurrency feature.
55+
This allows you to focus on one _specific type_ of problem at a time.
56+
57+
Proposal | Description | Feature Flag
58+
:-----------|-------------|-------------
59+
[SE-0401][] | Remove Actor Isolation Inference caused by Property Wrappers | `DisableOutwardActorInference`
60+
[SE-0412][] | Strict concurrency for global variables | `GlobalConcurrency`
61+
[SE-0418][] | Inferring `Sendable` for methods and key path literals | `InferSendableFromCaptures`
62+
63+
[SE-0401]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0401-remove-property-wrapper-isolation.md
64+
[SE-0412]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
65+
[SE-0418]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md
66+
67+
These can be enabled independently and in any order.
68+
69+
After you have addressed issues uncovered by upcoming feature flags,
70+
the next step is to [enable complete checking][CompleteChecking] for the module.
71+
This will turn on all of the compiler's remaining data isolation checks.
72+
73+
[CompleteChecking]: <doc:CompleteChecking>
74+
75+
## Address Warnings
76+
77+
There is one guiding principle you should use as you investigate
78+
warnings: **express what is true now**.
79+
Resist the urge to refactor your code to address issues.
80+
81+
You will find it beneficial to minimize the amount of change necessary to
82+
get to a warning-free state with complete concurrency checking.
83+
After that is done, use any unsafe opt-outs you applied as an indication of
84+
follow-on refactoring opportunities to introduce a safer isolation mechanism.
85+
86+
> Note: To learn more about addressing common problems, see <doc:CommonProblems>.
87+
88+
## Iteration
89+
90+
At first, you'll likely be employing techniques to disable or workaround
91+
data isolation problems.
92+
Once you feel like you've reached the stopping point for a higher-level module,
93+
target one of its dependencies that has required a workaround.
94+
95+
You don't have to eliminate all warnings to move on.
96+
Remember that sometimes very minor changes can have a significant impact.
97+
You can always return to a module once one of its dependencies has been
98+
updated.

0 commit comments

Comments
 (0)