|
5 | 5 |
|
6 | 6 | ## Swift 5.11
|
7 | 7 |
|
8 |
| -* [SE-0411][]: |
9 |
| - |
10 |
| - Default value expressions can now have the same isolation as the enclosing |
11 |
| - function or the corresponding stored property: |
12 |
| - |
13 |
| - ```swift |
14 |
| - @MainActor |
15 |
| - func requiresMainActor() -> Int { ... } |
16 |
| - |
17 |
| - class C { |
18 |
| - @MainActor |
19 |
| - var x: Int = requiresMainActor() |
20 |
| - } |
21 |
| - |
22 |
| - @MainActor func defaultArg(value: Int = requiresMainActor()) { ... } |
23 |
| - ``` |
24 |
| - |
25 |
| - For isolated default values of stored properties, the implicit initialization |
26 |
| - only happens in the body of an `init` with the same isolation. This closes |
27 |
| - an important data-race safety hole where global-actor-isolated default values |
28 |
| - could inadvertently run synchronously from outside the actor. |
29 |
| - |
30 | 8 | * [SE-0413][]:
|
31 | 9 |
|
32 | 10 | Functions can now specify the type of error that they throw as part of the
|
|
81 | 59 | Having been [gated](https://github.com/apple/swift/pull/28171) behind a
|
82 | 60 | compiler warning since at least Swift 5.2, this syntax is now rejected.
|
83 | 61 |
|
| 62 | +## Swift 5.10 |
| 63 | + |
| 64 | +* [SE-0412][]: |
| 65 | + |
| 66 | + Under strict concurrency checking, every global or static variable must be either isolated to a global actor or be both immutable and of `Sendable` type. |
| 67 | + |
| 68 | + ```swift |
| 69 | + var mutableGlobal = 1 |
| 70 | + // warning: var 'mutableGlobal' is not concurrency-safe because it is non-isolated global shared mutable state |
| 71 | + // (unless it is top-level code which implicitly isolates to @MainActor) |
| 72 | + |
| 73 | + final class NonsendableType { |
| 74 | + init() {} |
| 75 | + } |
| 76 | + |
| 77 | + struct S { |
| 78 | + static let immutableNonsendable = NonsendableType() |
| 79 | + // warning: static property 'immutableNonsendable' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor |
| 80 | + } |
| 81 | + ``` |
| 82 | + |
| 83 | + The attribute `nonisolated(unsafe)` can be used to annotate a global variable (or any form of storage) to disable static checking of data isolation, but note that without correct implementation of a synchronization mechanism to achieve data isolation, dynamic run-time analysis from exclusivity enforcement or tools such as Thread Sanitizer could still identify failures. |
| 84 | + |
| 85 | + ```swift |
| 86 | + nonisolated(unsafe) var global: String |
| 87 | + ``` |
| 88 | + |
| 89 | +* [SE-0411][]: |
| 90 | + |
| 91 | + Default value expressions can now have the same isolation as the enclosing |
| 92 | + function or the corresponding stored property: |
| 93 | + |
| 94 | + ```swift |
| 95 | + @MainActor |
| 96 | + func requiresMainActor() -> Int { ... } |
| 97 | + |
| 98 | + class C { |
| 99 | + @MainActor |
| 100 | + var x: Int = requiresMainActor() |
| 101 | + } |
| 102 | + |
| 103 | + @MainActor func defaultArg(value: Int = requiresMainActor()) { ... } |
| 104 | + ``` |
| 105 | + |
| 106 | + For isolated default values of stored properties, the implicit initialization |
| 107 | + only happens in the body of an `init` with the same isolation. This closes |
| 108 | + an important data-race safety hole where global-actor-isolated default values |
| 109 | + could inadvertently run synchronously from outside the actor. |
| 110 | + |
84 | 111 | ## Swift 5.9.2
|
85 | 112 |
|
86 | 113 | * [SE-0407][]:
|
@@ -9927,6 +9954,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
|
9927 | 9954 | [SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
|
9928 | 9955 | [SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
|
9929 | 9956 | [SE-0411]: https://github.com/apple/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
|
| 9957 | +[SE-0412]: https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md |
9930 | 9958 | [SE-0413]: https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md
|
9931 | 9959 | [#64927]: <https://github.com/apple/swift/issues/64927>
|
9932 | 9960 | [#42697]: <https://github.com/apple/swift/issues/42697>
|
|
0 commit comments