Skip to content

Commit 475ca65

Browse files
authored
Merge pull request #73989 from xedin/add-change-log-entries-for-0418-0423
[ChangeLog] Add entries for SE-0418 and SE-0423 implemented in Swift 6
2 parents 319f36b + 01bf742 commit 475ca65

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

CHANGELOG.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,84 @@
55
66
## Swift 6.0
77

8+
* [SE-0423][]:
9+
You can now use `@preconcurrency` attribute to replace static actor isolation
10+
checking with dynamic checks for witnesses of synchronous nonisolated protocol
11+
requirements when the witness is isolated. This is common when Swift programs
12+
need to interoperate with frameworks written in C/C++/Objective-C whose
13+
implementations cannot participate in static data race safety.
14+
15+
```swift
16+
public protocol ViewDelegateProtocol {
17+
func respondToUIEvent()
18+
}
19+
```
20+
21+
It's now possible for a `@MainActor`-isolated type to conform to
22+
`ViewDelegateProtocol` by marking conformance declaration as `@preconcurrency`:
23+
24+
```swift
25+
@MainActor
26+
class MyViewController: ViewDelegateProtocol {
27+
func respondToUIEvent() {
28+
// implementation...
29+
}
30+
}
31+
```
32+
33+
The compiler would emit dynamic checks into the `respondToUIEvent()` witness
34+
to make sure that it's always executed in `@MainActor` isolated context.
35+
36+
Additionally, the compiler would emit dynamic actor isolation checks for:
37+
38+
- `@objc` thunks of synchronous actor-isolated members of classes.
39+
40+
- Synchronous actor-isolated function values passed to APIs that
41+
erase actor isolation and haven't yet adopted strict concurrency checking.
42+
43+
- Call-sites of synchronous actor-isolated functions imported from Swift 6 libraries.
44+
45+
The dynamic actor isolation checks can be disabled using the flag
46+
`-disable-dynamic-actor-isolation`.
47+
48+
* [SE-0418][]:
49+
50+
The compiler would now automatically employ `Sendable` on functions
51+
and key path literal expressions that cannot capture non-Sendable values.
52+
53+
This includes partially-applied and unapplied instance methods of `Sendable`
54+
types, as well as non-local functions. Additionally, it is now disallowed
55+
to utilize `@Sendable` on instance methods of non-Sendable types.
56+
57+
Let's use the following type to illustrate the new inference rules:
58+
59+
```swift
60+
public struct User {
61+
var name: String
62+
63+
func getAge() -> Int { ... }
64+
}
65+
```
66+
67+
Key path `\User.name` would be inferred as `WritableKeyPath<User, String> & Sendable`
68+
because it doesn't capture any non-Sendable values.
69+
70+
The same applies to keypath-as-function conversions:
71+
72+
```swift
73+
let _: @Sendable (User) -> String = \User.name // Ok
74+
```
75+
76+
A function value produced by an un-applied reference to `getAge`
77+
would be marked as `@Sendable` because `User` is a `Sendable` struct:
78+
79+
```swift
80+
let _ = User.getAge // Inferred as `@Sendable (User) -> @Sendable () -> Int`
81+
82+
let user = User(...)
83+
user.getAge // Inferred as `@Sendable () -> Int`
84+
```
85+
886
* [SE-0432][]:
987
Noncopyable enums can be pattern-matched with switches without consuming the
1088
value you switch over:
@@ -10327,6 +10405,8 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
1032710405
[SE-0427]: https://github.com/apple/swift-evolution/blob/main/proposals/0427-noncopyable-generics.md
1032810406
[SE-0429]: https://github.com/apple/swift-evolution/blob/main/proposals/0429-partial-consumption.md
1032910407
[SE-0432]: https://github.com/apple/swift-evolution/blob/main/proposals/0432-noncopyable-switch.md
10408+
[SE-0418]: https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md
10409+
[SE-0423]: https://github.com/apple/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md
1033010410
[#64927]: <https://github.com/apple/swift/issues/64927>
1033110411
[#42697]: <https://github.com/apple/swift/issues/42697>
1033210412
[#42728]: <https://github.com/apple/swift/issues/42728>

0 commit comments

Comments
 (0)