|
5 | 5 |
|
6 | 6 | ## Swift 6.0
|
7 | 7 |
|
| 8 | +* [SE-0418][]: |
| 9 | + |
| 10 | + The compiler would now automatically employ `Sendable` on functions |
| 11 | + and key path literal expressions that cannot capture non-Sendable values. |
| 12 | + |
| 13 | + This includes partially-applied and unapplied instance methods of `Sendable` |
| 14 | + types, as well as non-local functions. Additionally, it is now disallowed |
| 15 | + to utilize `@Sendable` on instance methods of non-Sendable types. |
| 16 | + |
| 17 | + Let's use the following type to illustrate the new inference rules: |
| 18 | + |
| 19 | + ```swift |
| 20 | + public struct User { |
| 21 | + var name: String |
| 22 | + |
| 23 | + func getAge() -> Int { ... } |
| 24 | + } |
| 25 | + ``` |
| 26 | + |
| 27 | + Key path `\User.name` would be inferred as `WritableKeyPath<User, String> & Sendable` |
| 28 | + because it doesn't capture any non-Sendable values. |
| 29 | + |
| 30 | + The same applies to keypath-as-function conversions: |
| 31 | + |
| 32 | + ```swift |
| 33 | + let _: @Sendable (User) -> String = \User.name // Ok |
| 34 | + ``` |
| 35 | + |
| 36 | + A function value produced by an un-applied reference to `getAge` |
| 37 | + would be marked as `@Sendable` because `User` is a `Sendable` struct: |
| 38 | + |
| 39 | + ```swift |
| 40 | + let _ = User.getAge // Inferred as `@Sendable (User) -> @Sendable () -> Int` |
| 41 | + |
| 42 | + let user = User(...) |
| 43 | + user.getAge // Inferred as `@Sendable () -> Int` |
| 44 | + ``` |
| 45 | + |
8 | 46 | * [SE-0432][]:
|
9 | 47 | Noncopyable enums can be pattern-matched with switches without consuming the
|
10 | 48 | value you switch over:
|
@@ -10327,6 +10365,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
|
10327 | 10365 | [SE-0427]: https://github.com/apple/swift-evolution/blob/main/proposals/0427-noncopyable-generics.md
|
10328 | 10366 | [SE-0429]: https://github.com/apple/swift-evolution/blob/main/proposals/0429-partial-consumption.md
|
10329 | 10367 | [SE-0432]: https://github.com/apple/swift-evolution/blob/main/proposals/0432-noncopyable-switch.md
|
| 10368 | +[SE-0418]: https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md |
10330 | 10369 | [#64927]: <https://github.com/apple/swift/issues/64927>
|
10331 | 10370 | [#42697]: <https://github.com/apple/swift/issues/42697>
|
10332 | 10371 | [#42728]: <https://github.com/apple/swift/issues/42728>
|
|
0 commit comments