Avatar
SEで該当するサンプルコードはこれですかね disconnected->task-isolated->disconnected https://github.com/swiftlang/swift-evolution/blob/main/proposals/0414-region-based-isolation.md#weak-transfers-nonisolated-functions-and-disconnected-isolation-regions func nonIsolatedCallee(_ x: NonSendable) async { ... } func useValue(_ x: NonSendable) { ... } @MainActor func transferToMainActor<T>(_ t: T) { ... } actor MyActor { var state: NonSendable func example() async { // Regions: [{(), self}] let x = NonSendable() // Regions: [(x), {(), self}] // While nonIsolatedCallee executes the regions are: // Regions: [{(x), Task}, {(), self}] await nonIsolatedCallee(x) // Once it has finished executing, 'x' is disconnected again // Regions: [(x), {(), self}] // 'x' can be used since it is disconnected again. useValue(x) // (1) // 'x' can be transferred since it is disconnected again. await transferToMainActor(x) // (2) // Error! After transferring to main actor, permanently // in main actor, so we can't use it. useValue(x) // (3) } }
This maintains proposals for changes and user-visible enhancements to the Swift Programming Language. - swiftlang/swift-evolution
👀 1
10:46 AM
Repository.doSomething内でselfがtask-isolatedになっていて task-isolatedは他のtask-isolatedにもactor-isolatedにも結合できないルールによって守られているので、呼び出し終了後にdisconnectedに戻せる、って感じでしょうか