Skip to content

Commit 94cbc76

Browse files
authored
Merge pull request #59094 from kavon/se327-changelog
Describe SE-327 updates in Swift 5.7
2 parents af94916 + a2cfde2 commit 94cbc76

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
@@ -16,6 +16,43 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
1616

1717
## Swift 5.7
1818

19+
* [SE-0327][]:
20+
21+
There are a few notable changes in Swift 5.7 with respect to SE-0327.
22+
23+
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.
24+
25+
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.
26+
27+
In Swift 5.7, the compiler now checks these initializers for dangerous accesses to isolated stored properties that occur after an escape of `self`:
28+
29+
```swift
30+
actor Database {
31+
// ... other properties ...
32+
var rows: Int = 0
33+
34+
init(_ world: DataUser) {
35+
defer {
36+
print("last = \(self.rows)") // ❌ this access to 'rows' is illegal.
37+
}
38+
39+
print("before = \(self.rows)") // ✅ this access to 'rows' is OK
40+
world.publishDatabase(self) // ✅ passing 'self' is OK in Swift 5.7+
41+
print("after = \(self.rows)") // ❌ this access to 'rows' is illegal.
42+
43+
Task { [weak self] in // ✅ capturing 'self' is OK in Swift 5.7+
44+
while let db = self { await db.prune() }
45+
}
46+
}
47+
}
48+
```
49+
50+
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.
51+
52+
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.
53+
54+
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`.
55+
1956
* The Swift compiler no longer warns about redundant requirements in generic declarations. For example,
2057
the following code diagnosed a warning in Swift 5.6 about the `T.Iterator : IteratorProtocol`
2158
requirement being redundant, because it is implied by `T : Sequence`:

0 commit comments

Comments
 (0)