You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+37Lines changed: 37 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,43 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
16
16
17
17
## Swift 5.7
18
18
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
+
actorDatabase {
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 { [weakself] in// ✅ capturing 'self' is OK in Swift 5.7+
44
+
whilelet 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
+
19
56
* The Swift compiler no longer warns about redundant requirements in generic declarations. For example,
20
57
the following code diagnosed a warning in Swift 5.6 about the `T.Iterator : IteratorProtocol`
21
58
requirement being redundant, because it is implied by `T : Sequence`:
0 commit comments