@@ -19,6 +19,60 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
19
19
Swift 5.6
20
20
---------
21
21
22
+ * [ SE-0337] [ ] :
23
+
24
+ Swift now provides an incremental migration path to data race safety, allowing
25
+ APIs to adopt concurrency without breaking their clients that themselves have
26
+ not adopted concurrency. An existing declaration can introduce
27
+ concurrency-related annotations (such as making its closure parameters
28
+ ` @Sendable ` ) and use the ` @preconcurrency ` attribute to maintain its behavior
29
+ for clients who have not themselves adopted concurrency:
30
+
31
+ ``` swift
32
+ // module A
33
+ @preconcurrency func runOnSeparateTask (_ workItem : @Sendable () -> Void )
34
+
35
+ // module B
36
+ import A
37
+
38
+ class MyCounter {
39
+ var value = 0
40
+ }
41
+
42
+ func doesNotUseConcurrency (counter : MyCounter) {
43
+ runOnSeparateTask {
44
+ counter.value += 1 // no warning, because this code hasn't adopted concurrency
45
+ }
46
+ }
47
+
48
+ func usesConcurrency (counter : MyCounter) async {
49
+ runOnSeparateTask {
50
+ counter.value += 1 // warning: capture of non-Sendable type 'MyCounter'
51
+ }
52
+ }
53
+ ```
54
+
55
+ One can enable warnings about data race safety within a module with the
56
+ ` -warn-concurrency ` compiler option. When using a module that does not yet
57
+ provide ` Sendable ` annotations, one can suppress warnings for types from that
58
+ module by marking the import with ` @preconcurrency ` :
59
+
60
+ ``` swift
61
+ /// module C
62
+ public struct Point {
63
+ public var x, y: Double
64
+ }
65
+
66
+ // module D
67
+ @preconcurrency import C
68
+
69
+ func centerView (at location : Point) {
70
+ Task {
71
+ await mainView.center (at : location) // no warning about non-Sendable 'Point' because the @preconcurrency import suppresses it
72
+ }
73
+ }
74
+ ```
75
+
22
76
* [ SE-0302] [ ] :
23
77
24
78
Swift will now produce warnings to indicate potential data races when
@@ -8796,6 +8850,7 @@ Swift 1.0
8796
8850
[SE- 0324 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
8797
8851
[SE- 0323 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
8798
8852
[SE- 0328 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
8853
+ [SE- 0337 ]: < https: // github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
8799
8854
8800
8855
[SR- 75 ]: < https: // bugs.swift.org/browse/SR-75>
8801
8856
[SR- 106 ]: < https: // bugs.swift.org/browse/SR-106>
0 commit comments