Skip to content

Commit 40d7a1f

Browse files
Merge pull request #70863 from sophiapoirier/global-variable-strict-concurrency-changelog-5.10
🍒 [SE-0412] changelog note about strict concurrency for global variables
2 parents 6c75168 + 666a70d commit 40d7a1f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 26 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
@@ -9871,6 +9896,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
98719896
[SE-0397]: https://github.com/apple/swift-evolution/blob/main/proposals/0397-freestanding-declaration-macros.md
98729897
[SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
98739898
[SE-0411]: https://github.com/apple/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
9899+
[SE-0412]: https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
98749900
[#64927]: <https://github.com/apple/swift/issues/64927>
98759901
[#42697]: <https://github.com/apple/swift/issues/42697>
98769902
[#42728]: <https://github.com/apple/swift/issues/42728>

0 commit comments

Comments
 (0)