|
32 | 32 | }
|
33 | 33 | ```
|
34 | 34 |
|
| 35 | +* [SE-0471][]: |
| 36 | + Actor and global actor annotated types may now declare a synchronous `isolated deinit`, which allows such deinitializer |
| 37 | + to access actor isolated state while deinitializing the actor. This enables actor deinitializers to safely access |
| 38 | + and shut down or close resources during an actors deinitialization, without explicitly resorting to unstructured |
| 39 | + concurrency tasks. |
| 40 | + |
| 41 | + ```swift |
| 42 | + class NonSendableAhmed { |
| 43 | + var state: Int = 0 |
| 44 | + } |
| 45 | + |
| 46 | + @MainActor |
| 47 | + class Maria { |
| 48 | + let friend: NonSendableAhmed |
| 49 | + |
| 50 | + init() { |
| 51 | + self.friend = NonSendableAhmed() |
| 52 | + } |
| 53 | + |
| 54 | + init(sharingFriendOf otherMaria: Maria) { |
| 55 | + // While the friend is non-Sendable, this initializer and |
| 56 | + // and the otherMaria are isolated to the MainActor. That is, |
| 57 | + // they share the same executor. So, it's OK for the non-Sendable value |
| 58 | + // to cross between otherMaria and self. |
| 59 | + self.friend = otherMaria.friend |
| 60 | + } |
| 61 | + |
| 62 | + isolated deinit { |
| 63 | + // Used to be a potential data race. Now, deinit is also |
| 64 | + // isolated on the MainActor, so this code is perfectly |
| 65 | + // correct. |
| 66 | + friend.state += 1 |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + func example() async { |
| 71 | + let m1 = await Maria() |
| 72 | + let m2 = await Maria(sharingFriendOf: m1) |
| 73 | + doSomething(m1, m2) |
| 74 | + } |
| 75 | + ``` |
| 76 | + |
35 | 77 | * [SE-0469][]:
|
36 | 78 | Swift concurrency tasks (both unstructured and structured, via the TaskGroup `addTask` APIs) may now be given
|
37 | 79 | human-readable names, which can be used to support debugging and identifying tasks.
|
@@ -10868,6 +10910,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
|
10868 | 10910 | [SE-0462]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0462-task-priority-escalation-apis.md
|
10869 | 10911 | [SE-0469]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0469-task-names.md
|
10870 | 10912 | [SE-0470]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0470-isolated-conformances.md
|
| 10913 | +[SE-0471]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0371-isolated-synchronous-deinit.md |
10871 | 10914 | [SE-0472]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0472-task-start-synchronously-on-caller-context.md
|
10872 | 10915 | [#64927]: <https://github.com/apple/swift/issues/64927>
|
10873 | 10916 | [#42697]: <https://github.com/apple/swift/issues/42697>
|
|
0 commit comments