Skip to content

Commit 3a7df14

Browse files
committed
[Release Notes] Swift 5.10 closes all known holes in compile-time strict
concurrency checking. (cherry picked from commit fad88f3)
1 parent 99e9db8 commit 3a7df14

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

CHANGELOG.md

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

8+
* Swift 5.10 closes all known static data-race safey holes in complete strict
9+
concurrency checking.
10+
11+
When writing code against `-strict-concurrency=complete`, Swift 5.10 will
12+
diagnose all potential for data races at compile time unless an explicit
13+
unsafe opt out, such as `nonisolated(unsafe)` or `@unchecked Sendable`, is
14+
used.
15+
16+
For example, in Swift 5.9, the following code crashes at runtime due to a
17+
`@MainActor`-isolated initializer being evaluated outside the actor, but it
18+
was not diagnosed under `-strict-concurrency=complete`:
19+
20+
```swift
21+
@MainActor
22+
class MyModel {
23+
init() {
24+
MainActor.assertIsolated()
25+
}
26+
27+
static let shared = MyModel()
28+
}
29+
30+
func useShared() async {
31+
let model = MyModel.shared
32+
}
33+
34+
await useShared()
35+
```
36+
37+
The above code admits data races because a `@MainActor`-isolated static
38+
variable, which evaluates a `@MainActor`-isolated initial value upon first
39+
access, is accessed synchronously from a `nonisolated` context. In Swift
40+
5.10, compiling the code with `-strict-concurrency=complete` produces a
41+
warning that the access must be done asynchronously:
42+
43+
```
44+
warning: expression is 'async' but is not marked with 'await'
45+
let model = MyModel.shared
46+
^~~~~~~~~~~~~~
47+
await
48+
```
49+
50+
Swift 5.10 fixed numerous other bugs in `Sendable` and actor isolation
51+
checking to strengthen the guarantees of complete concurrency checking.
52+
53+
Note that the complete concurrency model in Swift 5.10 is conservative.
54+
Several Swift Evolution proposals are in active development to improve the
55+
usability of strict concurrency checking ahead of Swift 6.
56+
857
* [SE-0412][]:
958

1059
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.

0 commit comments

Comments
 (0)