swift 1@frozen 2public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */> 3 : _Pointer { 4 5 @inlinable 6 public var pointee: Pointee { 7 @_transparent get { 8 // The memory addressed by this pointer contains a non-owning reference, 9 // therefore we *must not* point an `UnsafePointer<AnyObject>` to10 // it---otherwise we would allow the compiler to assume it has a +111 // refcount, enabling some optimizations that wouldn't be valid.12 //13 // Instead, we need to load the pointee as a +0 unmanaged reference. For14 // an extra twist, `Pointee` is allowed (but not required) to be an15 // optional type, so we actually need to load it as an optional, and16 // explicitly handle the nil case.17 let unmanaged =18 UnsafePointer<Optional<Unmanaged<AnyObject>>>(_rawValue).pointee19 return _unsafeReferenceCast(20 unmanaged?.takeUnretainedValue(),21 to: Pointee.self)22 }23 ...24 }2526 ...27}
swift 1public mutating func walkUpDefault(value def: Value, path: Path) -> WalkResult { 2 switch def { 3 ... 4 case let urc as UncheckedRefCastInst: 5 if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential { 6 // Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of 7 // init_existential_ref and open_existential_ref). 8 // We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind. 9 return rootDef(value: urc, path: path)10 }11 return walkUp(value: urc.fromInstance, path: path)12 ...13 }14}
swift 1public mutating func walkUpDefault(value def: Value, path: Path) -> WalkResult { 2 switch def { 3 ... 4 case let urc as UncheckedRefCastInst: 5 if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential { 6 // Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of 7 // init_existential_ref and open_existential_ref). 8 // We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind. 9 return rootDef(value: urc, path: path)10 }11 switch (urc.type.isOptional, urc.fromInstance.type.isOptional) {12 case (true, false):13 if let path = path.popIfMatches(.enumCase, index: 1) {14 return walkUp(value: urc.fromInstance, path: path)15 } else {16 return unmatchedPath(value: urc.fromInstance, path: path)17 }18 case (false, true):19 return walkUp(value: urc.fromInstance, path: path.push(.enumCase, index: 1))20 default:21 return walkUp(value: urc.fromInstance, path: path)22 }23 ...24 }25}
swift 1public mutating func walkDownDefault(value operand: Operand, path: Path) -> WalkResult { 2 let instruction = operand.instruction 3 switch instruction { 4 ... 5 case let urc as UncheckedRefCastInst: 6 if urc.type.isClassExistential || urc.fromInstance.type.isClassExistential { 7 // Sometimes `unchecked_ref_cast` is misused to cast between AnyObject and a class (instead of 8 // init_existential_ref and open_existential_ref). 9 // We need to ignore this because otherwise the path wouldn't contain the right `existential` field kind.10 return leafUse(value: operand, path: path)11 }12 switch (urc.type.isOptional, urc.fromInstance.type.isOptional) {13 case (true, false):14 return walkDownUses(ofValue: operand, path: path.push(.enumCase, index: 1))15 case (false, true):16 if let path = path.popIfMatches(.enumCase, index: 1) {17 return walkDownUses(ofValue: operand, path: path)18 } else {19 return unmatchedPath(value: operand, path: path)20 }21 default:22 return walkDownUses(ofValue: operand, path: path)23 }24 ...25 }26}