Skip to content

Commit 726f8b8

Browse files
committed
describe SE-327 updates for Swift 5.7
1 parent e45a29c commit 726f8b8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,44 @@ _**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+
45+
846
* [SE-0329][]:
947
New types representing time and clocks were introduced. This includes a protocol `Clock` defining clocks which allow for defining a concept of now and a way to wake up after a given instant. Additionally a new protocol `InstantProtocol` for defining instants in time was added. Furthermore a new protocol `DurationProtocol` was added to define an elapsed duration between two given `InstantProtocol` types. Most commonly the `Clock` types for general use are the `SuspendingClock` and `ContinuousClock` which represent the most fundamental clocks for the system. The `SuspendingClock` type does not progress while the machine is suspended whereas the `ContinuousClock` progresses no matter the state of the machine.
1048

0 commit comments

Comments
 (0)