Avatar
omochimetaru 9/24/2021 7:32 AM
> **Rationale**: In theory, `@escaping` is completely orthogonal to `@Sendable`, and a Swift program built entirely with `@Sendable` from the ground up would not have the rule that `@escaping` closures be non-isolated. However, the existing Swift ecosystem is built without `@Sendable`, which leaves us with an unfortunate choice. We can assume that the lack of `@Sendable` on a function type means that the closure won't escape the concurrency domain, and where existing code (i.e., all Swift code that's been written so far) breaks this assumption, we'll have a data race. Or, we can conservatively assume that all existing function types are `@Sendable`, which will prevent all data races, but at the cost of being unable to use even the most basic facilities (such as `Sequence.map`, above). Therefore, we employ an heuristic: `@escaping` is a good (but imperfect) indicator in Swift today that the closure can be executed concurrently, so we don't permit escaping closures to be actor-isolated. This eliminates a significant proportion of the data races that would affect actor state, and the cost of (1) admitting some data races with existing code that manages to execute a closure concurrently without escaping it, and (2) prohibiting some safe patterns where a closure escapes but does not cross concurrency domains. This is a pragmatic, temporarily solution to the problem of rolling out data-race prevention throughout an existing ecosystem. Our approach will ratchet up the safety as code opts in to more concurrency safety in future language versions.
7:35 AM
「理論上は、escapingとsendableは直行する概念だけど、まだsendableが普及してないから妥協をする必要があって、実際escapingはコールバックに使ってることが多いし、escapingならnon-isolated(=sendable)にするヒューリスティックにしようと思うよ」
7:35 AM
みたいな事が書いてあって
7:35 AM
それに対してラトナーが↑で
7:35 AM
「いやいやそれだとマズイでしょ理論上直行するわけで・・・(以下説明)」みたいなツッコミをした結果
7:36 AM
第二回レビューのタイミングでは、escapingに関するヒューリスティック(=sendable)が取り除かれた?
7:37 AM
ラトナー
and it makes perfect sense for a closure to be @escaping without being @Sendable.
7:37 AM
Sendableじゃないけどescapingなクロージャは完全に正しい(ありえる)