swift
c01f551e - [transfer-non-sendable] Teach SILIsolationInfo how to handle "look through instructions" when finding actor instances.

Commit
1 year ago
[transfer-non-sendable] Teach SILIsolationInfo how to handle "look through instructions" when finding actor instances. From the perspective of the IR, we are changing SILIsolationInfo such that inferring an actor instance means looking at equivalence classes of values where we consider operands to look through instructions to be equivalent to their dest value. The result is that cases where the IR maybe puts in a copy_value or the like, we consider the copy_value to have the same isolation info as using the actor directly. This prevents a class of crashes due to merge failings. Example: ```swift actor MyActor { init() async { init(ns: NonSendableKlass) async { self.k = NonSendableKlass() self.helper(ns) } func helper(_ newK: NonSendableKlass) {} } ``` Incidently, we already had a failing test case from this behavior rather than the one that was the original genesis. Specifically: 1. If a function's SILIsolationInfo is the same as the isolation info of a SILValue, we assume that no transfer actually occurs. 2. Since we were taking too static of a view of actor instances when comparing, we would think that a SILIsolationInfo of a #isolation parameter to as an argument would be different than the ambient's function isolation which is also that same one. So we would emit a transfer non transferrable error if we pass in any parameters of the ambient function into another isolated function. Example: ```swift actor Test { @TaskLocal static var local: Int? func withTaskLocal(isolation: isolated (any Actor)? = #isolation, _ body: (consuming NonSendableValue, isolated (any Actor)?) -> Void) async { Self.$local.withValue(12) { // We used to get these errors here since we thought that body's isolation // was different than the body's isolation. // // warning: sending 'body' risks causing data races // note: actor-isolated 'body' is captured by a actor-isolated closure... body(NonSendableValue(), isolation) } } } ``` rdar://129400019
Author
Committer
Parents
Loading