Skip to content

Rename various ObjC-visible classes #1696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension Array : _ObjectiveCBridgeable {
public typealias _ObjectType = NSArray
public func _bridgeToObjectiveC() -> _ObjectType {
return NSArray(array: map { (element: Element) -> AnyObject in
return _SwiftValue.store(element)
return __SwiftValue.store(element)
})
}

Expand Down
22 changes: 11 additions & 11 deletions Foundation/Bridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ internal protocol _NSBridgeable {

#if !canImport(ObjectiveC)
// The _NSSwiftValue protocol is in the stdlib, and only available on platforms without ObjC.
extension _SwiftValue: _NSSwiftValue {}
extension __SwiftValue: _NSSwiftValue {}
#endif

/// - Note: This is an internal boxing value for containing abstract structures
internal final class _SwiftValue : NSObject, NSCopying {
internal final class __SwiftValue : NSObject, NSCopying {
public private(set) var value: Any

static func fetch(_ object: AnyObject?) -> Any? {
Expand Down Expand Up @@ -115,7 +115,7 @@ internal final class _SwiftValue : NSObject, NSCopying {
return type
}

let name = "_SwiftValue"
let name = "__SwiftValue"
let maybeType = name.withCString { cString in
return objc_getClass(cString)
}
Expand All @@ -135,7 +135,7 @@ internal final class _SwiftValue : NSObject, NSCopying {
// You can pass the result of a `as AnyObject` expression to this method. This can have one of three results on Darwin:
// - It's a SwiftFoundation type. Bridging will take care of it below.
// - It's nil. The compiler is hardcoded to return [NSNull null] for nils.
// - It's some other Swift type. The compiler will box it in a native _SwiftValue.
// - It's some other Swift type. The compiler will box it in a native __SwiftValue.
// Case 1 is handled below.
// Case 2 is handled here:
if type(of: object as Any) == objCNSNullClass {
Expand All @@ -145,20 +145,20 @@ internal final class _SwiftValue : NSObject, NSCopying {
if type(of: object as Any) == swiftStdlibSwiftValueClass {
return object
// Since this returns Any, the object is casted almost immediately — e.g.:
// _SwiftValue.fetch(x) as SomeStruct
// __SwiftValue.fetch(x) as SomeStruct
// which will immediately unbox the native box. For callers, it will be exactly
// as if we returned the unboxed value directly.
}

// On Linux, case 2 is handled by the stdlib bridging machinery, and case 3 can't happen —
// the compiler will produce SwiftFoundation._SwiftValue boxes rather than ObjC ones.
// the compiler will produce SwiftFoundation.__SwiftValue boxes rather than ObjC ones.
#endif

if object === kCFBooleanTrue {
return true
} else if object === kCFBooleanFalse {
return false
} else if let container = object as? _SwiftValue {
} else if let container = object as? __SwiftValue {
return container.value
} else if let val = object as? _StructBridgeable {
return val._bridgeToAny()
Expand Down Expand Up @@ -188,10 +188,10 @@ internal final class _SwiftValue : NSObject, NSCopying {
return NSNull()
} else {
#if canImport(ObjectiveC)
// On Darwin, this can be a native (ObjC) _SwiftValue.
// On Darwin, this can be a native (ObjC) __SwiftValue.
let boxed = (value as AnyObject)
if !(boxed is NSObject) {
return _SwiftValue(value) // Do not emit native boxes — wrap them in Swift Foundation boxes instead.
return __SwiftValue(value) // Do not emit native boxes — wrap them in Swift Foundation boxes instead.
} else {
return boxed as! NSObject
}
Expand All @@ -214,7 +214,7 @@ internal final class _SwiftValue : NSObject, NSCopying {

override func isEqual(_ value: Any?) -> Bool {
switch value {
case let other as _SwiftValue:
case let other as __SwiftValue:
guard let left = other.value as? AnyHashable,
let right = self.value as? AnyHashable else { return self === other }

Expand All @@ -228,7 +228,7 @@ internal final class _SwiftValue : NSObject, NSCopying {
}

public func copy(with zone: NSZone?) -> Any {
return _SwiftValue(value)
return __SwiftValue(value)
}

public static let null: AnyObject = NSNull()
Expand Down
8 changes: 4 additions & 4 deletions Foundation/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ open class Bundle: NSObject {

open var infoDictionary: [String : Any]? {
let cfDict: CFDictionary? = CFBundleGetInfoDictionary(_bundle)
return _SwiftValue.fetch(cfDict) as? [String : Any]
return __SwiftValue.fetch(cfDict) as? [String : Any]
}

open var localizedInfoDictionary: [String : Any]? {
let cfDict: CFDictionary? = CFBundleGetLocalInfoDictionary(_bundle)
return _SwiftValue.fetch(cfDict) as? [String : Any]
return __SwiftValue.fetch(cfDict) as? [String : Any]
}

open func object(forInfoDictionaryKey key: String) -> Any? {
Expand All @@ -299,7 +299,7 @@ open class Bundle: NSObject {
}
open var localizations: [String] {
let cfLocalizations: CFArray? = CFBundleCopyBundleLocalizations(_bundle)
let nsLocalizations = _SwiftValue.fetch(cfLocalizations) as? [Any]
let nsLocalizations = __SwiftValue.fetch(cfLocalizations) as? [Any]
return nsLocalizations?.map { $0 as! String } ?? []
}

Expand All @@ -310,7 +310,7 @@ open class Bundle: NSObject {

open class func preferredLocalizations(from localizationsArray: [String]) -> [String] {
let cfLocalizations: CFArray? = CFBundleCopyPreferredLocalizationsFromArray(localizationsArray._cfObject)
let nsLocalizations = _SwiftValue.fetch(cfLocalizations) as? [Any]
let nsLocalizations = __SwiftValue.fetch(cfLocalizations) as? [Any]
return nsLocalizations?.map { $0 as! String } ?? []
}

Expand Down
10 changes: 5 additions & 5 deletions Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -908,20 +908,20 @@ public final class _DataStorage {

switch _backing {
case .swift:
return _NSSwiftData(backing: self, range: range)
return __NSSwiftData(backing: self, range: range)
case .immutable(let d):
guard range.lowerBound == 0 && range.upperBound == _length else {
return _NSSwiftData(backing: self, range: range)
return __NSSwiftData(backing: self, range: range)
}
return d
case .mutable(let d):
guard range.lowerBound == 0 && range.upperBound == _length else {
return _NSSwiftData(backing: self, range: range)
return __NSSwiftData(backing: self, range: range)
}
return d
case .customReference(let d):
guard range.lowerBound == 0 && range.upperBound == d.length else {
return _NSSwiftData(backing: self, range: range)
return __NSSwiftData(backing: self, range: range)
}
return d
case .customMutableReference(let d):
Expand All @@ -944,7 +944,7 @@ public final class _DataStorage {
}
}

internal class _NSSwiftData : NSData {
internal class __NSSwiftData : NSData {
var _backing: _DataStorage!
var _range: Range<Data.Index>!

Expand Down
8 changes: 4 additions & 4 deletions Foundation/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ extension Dictionary : _ObjectiveCBridgeable {
var idx = 0

self.forEach { (keyItem, valueItem) in
let key = _SwiftValue.store(keyItem)
let value = _SwiftValue.store(valueItem)
let key = __SwiftValue.store(keyItem)
let value = __SwiftValue.store(valueItem)
keyBuffer.advanced(by: idx).initialize(to: key)
valueBuffer.advanced(by: idx).initialize(to: value)
idx += 1
Expand Down Expand Up @@ -65,8 +65,8 @@ extension Dictionary : _ObjectiveCBridgeable {
CFDictionaryGetKeysAndValues(cf, keys, values)

for idx in 0..<cnt {
let key = _SwiftValue.fetch(nonOptional: unsafeBitCast(keys.advanced(by: idx).pointee!, to: AnyObject.self))
let value = _SwiftValue.fetch(nonOptional: unsafeBitCast(values.advanced(by: idx).pointee!, to: AnyObject.self))
let key = __SwiftValue.fetch(nonOptional: unsafeBitCast(keys.advanced(by: idx).pointee!, to: AnyObject.self))
let value = __SwiftValue.fetch(nonOptional: unsafeBitCast(values.advanced(by: idx).pointee!, to: AnyObject.self))
guard let k = key as? Key, let v = value as? Value else {
failedConversion = true
break
Expand Down
2 changes: 1 addition & 1 deletion Foundation/HTTPCookieStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ open class HTTPCookieStorage: NSObject {
persistDictionary[key] = cookie.persistableDictionary()
}

let nsdict = _SwiftValue.store(persistDictionary) as! NSDictionary
let nsdict = __SwiftValue.store(persistDictionary) as! NSDictionary
_ = nsdict.write(toFile: cookieFilePath, atomically: true)
}

Expand Down
26 changes: 13 additions & 13 deletions Foundation/JSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ extension _JSONDecoder {

#if DEPLOYMENT_RUNTIME_SWIFT
// Bridging differences require us to split implementations here
guard let number = _SwiftValue.store(value) as? NSNumber else {
guard let number = __SwiftValue.store(value) as? NSNumber else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand Down Expand Up @@ -2043,7 +2043,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Int.Type) throws -> Int? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2058,7 +2058,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Int8.Type) throws -> Int8? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2073,7 +2073,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Int16.Type) throws -> Int16? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2088,7 +2088,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Int32.Type) throws -> Int32? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2103,7 +2103,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Int64.Type) throws -> Int64? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2118,7 +2118,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: UInt.Type) throws -> UInt? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2133,7 +2133,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: UInt8.Type) throws -> UInt8? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2148,7 +2148,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: UInt16.Type) throws -> UInt16? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2163,7 +2163,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: UInt32.Type) throws -> UInt32? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2178,7 +2178,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: UInt64.Type) throws -> UInt64? {
guard !(value is NSNull) else { return nil }

guard let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
guard let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

Expand All @@ -2193,7 +2193,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Float.Type) throws -> Float? {
guard !(value is NSNull) else { return nil }

if let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse {
if let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse {
// We are willing to return a Float by losing precision:
// * If the original value was integral,
// * and the integral value was > Float.greatestFiniteMagnitude, we will fail
Expand Down Expand Up @@ -2238,7 +2238,7 @@ extension _JSONDecoder {
fileprivate func unbox(_ value: Any, as type: Double.Type) throws -> Double? {
guard !(value is NSNull) else { return nil }

if let number = _SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse {
if let number = __SwiftValue.store(value) as? NSNumber, number !== kCFBooleanTrue, number !== kCFBooleanFalse {
// We are always willing to return the number as a Double:
// * If the original value was integral, it is guaranteed to fit in a Double; we are willing to lose precision past 2^53 if you encoded a UInt64 but requested a Double
// * If it was a Float or Double, you will get back the precise value
Expand Down
6 changes: 3 additions & 3 deletions Foundation/JSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ open class JSONSerialization : NSObject {

// object is NSNumber and is not NaN or infinity
// For better performance, this (most expensive) test should be last.
if let number = _SwiftValue.store(obj) as? NSNumber {
if let number = __SwiftValue.store(obj) as? NSNumber {
if CFNumberIsFloatType(number._cfObject) {
let dv = number.doubleValue
let invalid = dv.isInfinite || dv.isNaN
Expand Down Expand Up @@ -369,8 +369,8 @@ private struct JSONWriter {
writer(num.description)
case is NSNull:
try serializeNull()
case _ where _SwiftValue.store(obj) is NSNumber:
try serializeNumber(_SwiftValue.store(obj) as! NSNumber)
case _ where __SwiftValue.store(obj) is NSNumber:
try serializeNumber(__SwiftValue.store(obj) as! NSNumber)
default:
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.propertyListReadCorrupt.rawValue, userInfo: ["NSDebugDescription" : "Invalid object cannot be serialized"])
}
Expand Down
Loading