Skip to content

Commit fad88f3

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

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

CHANGELOG.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,55 @@
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
69+
unsafe opt out, such as `nonisolated(unsafe)` or `@unchecked Sendable`, is
70+
used.
71+
72+
For example, in Swift 5.9, the following code crashes at runtime due to a
73+
`@MainActor`-isolated initializer being evaluated outside the actor, but it
74+
was not diagnosed under `-strict-concurrency=complete`:
75+
76+
```swift
77+
@MainActor
78+
class MyModel {
79+
init() {
80+
MainActor.assertIsolated()
81+
}
82+
83+
static let shared = MyModel()
84+
}
85+
86+
func useShared() async {
87+
let model = MyModel.shared
88+
}
89+
90+
await useShared()
91+
```
92+
93+
The above code admits data races because a `@MainActor`-isolated static
94+
variable, which evaluates a `@MainActor`-isolated initial value upon first
95+
access, is accessed synchronously from a `nonisolated` context. In Swift
96+
5.10, compiling the code with `-strict-concurrency=complete` produces a
97+
warning that the access must be done asynchronously:
98+
99+
```
100+
warning: expression is 'async' but is not marked with 'await'
101+
let model = MyModel.shared
102+
^~~~~~~~~~~~~~
103+
await
104+
```
105+
106+
Swift 5.10 fixed numerous other bugs in `Sendable` and actor isolation
107+
checking to strengthen the guarantees of complete concurrency checking.
108+
109+
Note that the complete concurrency model in Swift 5.10 is conservative.
110+
Several Swift Evolution proposals are in active development to improve the
111+
usability of strict concurrency checking ahead of Swift 6.
112+
64113
* [SE-0412][]:
65114

66115
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 +10047,4 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
999810047
[#57225]: <https://github.com/apple/swift/issues/57225>
999910048
[#56139]: <https://github.com/apple/swift/issues/56139>
1000010049
[#70065]: <https://github.com/apple/swift/pull/70065>
10001-
[swift-syntax]: https://github.com/apple/swift-syntax
10050+
[swift-syntax]: https://github.com/apple/swift-syntax

0 commit comments

Comments
 (0)