Skip to content

Commit 6226993

Browse files
committed
[Release Notes] Swift 5.10 closes all known holes in compile-time strict
concurrency checking.
1 parent 2a18edc commit 6226993

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

CHANGELOG.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,54 @@
6161

6262
## Swift 5.10
6363

64+
* Swift 5.10 closes all known static data-race safey holes in complete strict
65+
concurrency checking.
66+
67+
When writing code against `-strict-concurrency=complete`, Swift 5.10 will
68+
diagnose all potential for data races at compile time unless an explicit unsafe
69+
opt out, such as `nonisolated(unsafe)` or `@unchecked Sendable`, is used.
70+
71+
For example, in Swift 5.9, the following code crashes at runtime due to a
72+
`@MainActor`-isolated initializer being evaluated outside the actor, but it was
73+
not diagnosed under `-strict-concurrency=complete`:
74+
75+
```swift
76+
@MainActor
77+
class MyModel {
78+
init() {
79+
MainActor.assertIsolated()
80+
}
81+
82+
static let shared = MyModel()
83+
}
84+
85+
func useShared() async {
86+
let model = MyModel.shared
87+
}
88+
89+
await useShared()
90+
```
91+
92+
The above code admits data races because a `@MainActor`-isolated static
93+
variable, which evaluates a `@MainActor`-isolated initial value upon first
94+
access, is accessed synchronously from a `nonisolated` context. In Swift 5.10,
95+
compiling the code with `-strict-concurrency=complete` produces a warning that
96+
the access must be done asynchronously:
97+
98+
```
99+
warning: expression is 'async' but is not marked with 'await'
100+
let model = MyModel.shared
101+
^~~~~~~~~~~~~~
102+
await
103+
```
104+
105+
Swift 5.10 fixed numerous other bugs in `Sendable` and actor isolation checking
106+
to strengthen the guarantees of complete concurrency checking.
107+
108+
Note that the complete concurrency model in Swift 5.10 is conservative. Several
109+
Swift Evolution proposals are in active development to improve the usability of
110+
strict concurrency checking ahead of Swift 6.
111+
64112
* [SE-0412][]:
65113

66114
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.
@@ -9998,4 +10046,4 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
999810046
[#57225]: <https://github.com/apple/swift/issues/57225>
999910047
[#56139]: <https://github.com/apple/swift/issues/56139>
1000010048
[#70065]: <https://github.com/apple/swift/pull/70065>
10001-
[swift-syntax]: https://github.com/apple/swift-syntax
10049+
[swift-syntax]: https://github.com/apple/swift-syntax

0 commit comments

Comments
 (0)