Skip to content

Commit 75fb2a6

Browse files
committed
[SE-0412] changelog note about strict concurrency for global variables
1 parent feae5f1 commit 75fb2a6

File tree

1 file changed

+50
-22
lines changed

1 file changed

+50
-22
lines changed

CHANGELOG.md

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,6 @@
55
66
## Swift 5.11
77

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-
308
* [SE-0413][]:
319

3210
Functions can now specify the type of error that they throw as part of the
@@ -81,6 +59,55 @@
8159
Having been [gated](https://github.com/apple/swift/pull/28171) behind a
8260
compiler warning since at least Swift 5.2, this syntax is now rejected.
8361

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+
84111
## Swift 5.9.2
85112

86113
* [SE-0407][]:
@@ -9927,6 +9954,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
99279954
[SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
99289955
[SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
99299956
[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
99309958
[SE-0413]: https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md
99319959
[#64927]: <https://github.com/apple/swift/issues/64927>
99329960
[#42697]: <https://github.com/apple/swift/issues/42697>

0 commit comments

Comments
 (0)