Skip to content

Commit fe62f0f

Browse files
committed
describe SE-327 updates for Swift 5.7
1 parent 0eafd08 commit fe62f0f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* [SE-0327][]:
9+
10+
There are a few notable changes in Swift 5.7 with respect to SE-0327.
11+
12+
First, the deinitializer and most kinds of initializers for `actor` types, and types constrained by a global actor like the `@MainActor`, have revised rules about what expressions are permitted in their body. The goal of these revisions has been to improve language expressivity and safety. In particular, many more programming patterns are now permitted in these initializers.
13+
14+
For example, a non-async initializer of an `actor` prior to Swift 5.7 would raise a diagnostic any time `self` escapes the initializer before returning. That diagnostic's purpose was to protect against a possible data race when accessing isolated stored proeprties. But, that diagnostic was emitted even if there was no dangerous racy access.
15+
16+
In Swift 5.7, the compiler now checks these initializers for dangerous accesses to isolated stored properties that occur after an escape of `self`:
17+
18+
```swift
19+
actor Database {
20+
// ... other properties ...
21+
var rows: Int = 0
22+
23+
init(_ world: DataUser) {
24+
defer {
25+
print("last = \(self.rows)") // ❌ this access to 'rows' is illegal.
26+
}
27+
28+
print("before = \(self.rows)") // ✅ this access to 'rows' is OK
29+
world.publishDatabase(self) // ✅ passing 'self' is OK in Swift 5.7+
30+
print("after = \(self.rows)") // ❌ this access to 'rows' is illegal.
31+
32+
Task { [weak self] in // ✅ capturing 'self' is OK in Swift 5.7+
33+
while let db = self { await db.prune() }
34+
}
35+
}
36+
}
37+
```
38+
39+
This is a control-flow sensitive check, meaning an illegal access does not necessarily appear on a source line after an escape of `self` (in the example above, consider _when_ the `defer` is executed). The compiler will always point out one of the escapes of `self` that is causing an access to become illegal.
40+
41+
Next, delegating initializers of an actor are no longer always non-isolated. This means an `async` delegating initializer can do the same things as a non-delegating one.
42+
43+
Finally, the diagnostic about non-isolated default-value expressions introduced for Swift 5.6 in the Xcode 13.3 release has been removed. The proposed rule was not precise enough to avoid flagging an innocuous yet common pattern in SwiftUI code involving `@StateObject` properties and `@MainActor`.
44+
845
* [SE-0350][]:
946

1047
The standard library has a new `Regex<Output>` type.

0 commit comments

Comments
 (0)