Skip to content

Commit 4ef9e50

Browse files
committed
[SE-0412] changelog note about strict concurrency for global variables
1 parent 5ae4b57 commit 4ef9e50

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55
66
## Swift 5.10
77

8+
* [SE-0412][]:
9+
10+
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.
11+
12+
```swift
13+
var mutableGlobal = 1
14+
// warning: var 'mutableGlobal' is not concurrency-safe because it is non-isolated global shared mutable state
15+
// (unless it is top-level code which implicitly isolates to @MainActor)
16+
17+
final class NonsendableType {
18+
init() {}
19+
}
20+
21+
struct S {
22+
static let immutableNonsendable = NonsendableType()
23+
// warning: static property 'immutableNonsendable' is not concurrency-safe because it is not either conforming to 'Sendable' or isolated to a global actor
24+
}
25+
```
26+
27+
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.
28+
29+
```swift
30+
nonisolated(unsafe) var global: String
31+
```
32+
833
* [SE-0411][]:
934

1035
Default value expressions can now have the same isolation as the enclosing

0 commit comments

Comments
 (0)