swift123456789101112131415161718192021222324252627@frozenpublic struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */> : _Pointer { @inlinable public var pointee: Pointee { @_transparent get { // The memory addressed by this pointer contains a non-owning reference, // therefore we *must not* point an `UnsafePointer<AnyObject>` to // it---otherwise we would allow the compiler to assume it has a +1 // refcount, enabling some optimizations that wouldn't be valid. // // Instead, we need to load the pointee as a +0 unmanaged reference. For // an extra twist, `Pointee` is allowed (but not required) to be an // optional type, so we actually need to load it as an optional, and // explicitly handle the nil case. let unmanaged = UnsafePointer<Optional<Unmanaged<AnyObject>>>(_rawValue).pointee return _unsafeReferenceCast( unmanaged?.takeUnretainedValue(), to: Pointee.self) } ... } ...}
swift1234567891011121314public mutating func walkUpDefault(value def: Value, path: Path) -> WalkResult { switch def { ... case let urc as UncheckedRefCastInst: if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential { // Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of // init_existential_ref and open_existential_ref). // We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind. return rootDef(value: urc, path: path) } return walkUp(value: urc.fromInstance, path: path) ... }}
swift12345678910111213141516171819202122232425public mutating func walkUpDefault(value def: Value, path: Path) -> WalkResult { switch def { ... case let urc as UncheckedRefCastInst: if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential { // Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of // init_existential_ref and open_existential_ref). // We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind. return rootDef(value: urc, path: path) } switch (urc.type.isOptional, urc.fromInstance.type.isOptional) { case (true, false): if let path = path.popIfMatches(.enumCase, index: 1) { return walkUp(value: urc.fromInstance, path: path) } else { return unmatchedPath(value: urc.fromInstance, path: path) } case (false, true): return walkUp(value: urc.fromInstance, path: path.push(.enumCase, index: 1)) default: return walkUp(value: urc.fromInstance, path: path) } ... }}
swift1234567891011121314151617181920212223242526public mutating func walkDownDefault(value operand: Operand, path: Path) -> WalkResult { let instruction = operand.instruction switch instruction { ... case let urc as UncheckedRefCastInst: if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential { // Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of // init_existential_ref and open_existential_ref). // We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind. return leafUse(value: operand, path: path) } switch (urc.type.isOptional, urc.fromInstance.type.isOptional) { case (true, false): return walkDownUses(ofValue: operand, path: path.push(.enumCase, index: 1)) case (false, true): if let path = path.popIfMatches(.enumCase, index: 1) { return walkDownUses(ofValue: operand, path: path) } else { return unmatchedPath(value: operand, path: path) } default: return walkDownUses(ofValue: operand, path: path) } ... }}