mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Stdlib][Overlays] Rename various classes to avoid conflicting ObjC names.
Old Swift and new Swift runtimes and overlays need to coexist in the same process. This means there must not be any classes which have the same ObjC runtime name in old and new, because the ObjC runtime doesn't like name collisions. When possible without breaking source compatibility, classes were renamed in Swift, which results in a different ObjC name. Public classes were renamed only on the ObjC side using the @_objcRuntimeName attribute. This is similar to the work done in pull request #19295. That only renamed @objc classes. This renames all of the others, since even pure Swift classes still get an ObjC name. rdar://problem/46646438
This commit is contained in:
@@ -51,6 +51,11 @@ extension Dictionary : _JSONStringDictionaryDecodableMarker where Key == String,
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// `JSONEncoder` facilitates the encoding of `Encodable` values into JSON.
|
||||
// NOTE: older overlays had Foundation.JSONEncoder as the ObjC name.
|
||||
// The two must coexist, so it was renamed. The old name must not be
|
||||
// used in the new runtime. _TtC10Foundation12_JSONEncoder is the
|
||||
// mangled name for Foundation._JSONEncoder.
|
||||
@_objcRuntimeName(_TtC10Foundation12_JSONEncoder)
|
||||
open class JSONEncoder {
|
||||
// MARK: Options
|
||||
|
||||
@@ -245,7 +250,7 @@ open class JSONEncoder {
|
||||
/// - throws: `EncodingError.invalidValue` if a non-conforming floating-point value is encountered during encoding, and the encoding strategy is `.throw`.
|
||||
/// - throws: An error if any value throws an error during encoding.
|
||||
open func encode<T : Encodable>(_ value: T) throws -> Data {
|
||||
let encoder = _JSONEncoder(options: self.options)
|
||||
let encoder = __JSONEncoder(options: self.options)
|
||||
|
||||
guard let topLevel = try encoder.box_(value) else {
|
||||
throw EncodingError.invalidValue(value,
|
||||
@@ -273,9 +278,12 @@ open class JSONEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - _JSONEncoder
|
||||
// MARK: - __JSONEncoder
|
||||
|
||||
fileprivate class _JSONEncoder : Encoder {
|
||||
// NOTE: older overlays called this class _JSONEncoder.
|
||||
// The two must coexist without a conflicting ObjC class name, so it
|
||||
// was renamed. The old name must not be used in the new runtime.
|
||||
fileprivate class __JSONEncoder : Encoder {
|
||||
// MARK: Properties
|
||||
|
||||
/// The encoder's storage.
|
||||
@@ -405,7 +413,7 @@ fileprivate struct _JSONKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCon
|
||||
// MARK: Properties
|
||||
|
||||
/// A reference to the encoder we're writing to.
|
||||
private let encoder: _JSONEncoder
|
||||
private let encoder: __JSONEncoder
|
||||
|
||||
/// A reference to the container we're writing to.
|
||||
private let container: NSMutableDictionary
|
||||
@@ -416,7 +424,7 @@ fileprivate struct _JSONKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCon
|
||||
// MARK: - Initialization
|
||||
|
||||
/// Initializes `self` with the given references.
|
||||
fileprivate init(referencing encoder: _JSONEncoder, codingPath: [CodingKey], wrapping container: NSMutableDictionary) {
|
||||
fileprivate init(referencing encoder: __JSONEncoder, codingPath: [CodingKey], wrapping container: NSMutableDictionary) {
|
||||
self.encoder = encoder
|
||||
self.codingPath = codingPath
|
||||
self.container = container
|
||||
@@ -519,11 +527,11 @@ fileprivate struct _JSONKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCon
|
||||
}
|
||||
|
||||
public mutating func superEncoder() -> Encoder {
|
||||
return _JSONReferencingEncoder(referencing: self.encoder, key: _JSONKey.super, convertedKey: _converted(_JSONKey.super), wrapping: self.container)
|
||||
return __JSONReferencingEncoder(referencing: self.encoder, key: _JSONKey.super, convertedKey: _converted(_JSONKey.super), wrapping: self.container)
|
||||
}
|
||||
|
||||
public mutating func superEncoder(forKey key: Key) -> Encoder {
|
||||
return _JSONReferencingEncoder(referencing: self.encoder, key: key, convertedKey: _converted(key), wrapping: self.container)
|
||||
return __JSONReferencingEncoder(referencing: self.encoder, key: key, convertedKey: _converted(key), wrapping: self.container)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,7 +539,7 @@ fileprivate struct _JSONUnkeyedEncodingContainer : UnkeyedEncodingContainer {
|
||||
// MARK: Properties
|
||||
|
||||
/// A reference to the encoder we're writing to.
|
||||
private let encoder: _JSONEncoder
|
||||
private let encoder: __JSONEncoder
|
||||
|
||||
/// A reference to the container we're writing to.
|
||||
private let container: NSMutableArray
|
||||
@@ -547,7 +555,7 @@ fileprivate struct _JSONUnkeyedEncodingContainer : UnkeyedEncodingContainer {
|
||||
// MARK: - Initialization
|
||||
|
||||
/// Initializes `self` with the given references.
|
||||
fileprivate init(referencing encoder: _JSONEncoder, codingPath: [CodingKey], wrapping container: NSMutableArray) {
|
||||
fileprivate init(referencing encoder: __JSONEncoder, codingPath: [CodingKey], wrapping container: NSMutableArray) {
|
||||
self.encoder = encoder
|
||||
self.codingPath = codingPath
|
||||
self.container = container
|
||||
@@ -610,11 +618,11 @@ fileprivate struct _JSONUnkeyedEncodingContainer : UnkeyedEncodingContainer {
|
||||
}
|
||||
|
||||
public mutating func superEncoder() -> Encoder {
|
||||
return _JSONReferencingEncoder(referencing: self.encoder, at: self.container.count, wrapping: self.container)
|
||||
return __JSONReferencingEncoder(referencing: self.encoder, at: self.container.count, wrapping: self.container)
|
||||
}
|
||||
}
|
||||
|
||||
extension _JSONEncoder : SingleValueEncodingContainer {
|
||||
extension __JSONEncoder : SingleValueEncodingContainer {
|
||||
// MARK: - SingleValueEncodingContainer Methods
|
||||
|
||||
fileprivate func assertCanEncodeNewValue() {
|
||||
@@ -704,7 +712,7 @@ extension _JSONEncoder : SingleValueEncodingContainer {
|
||||
|
||||
// MARK: - Concrete Value Representations
|
||||
|
||||
extension _JSONEncoder {
|
||||
extension __JSONEncoder {
|
||||
/// Returns the given value boxed in a container appropriate for pushing onto the container stack.
|
||||
fileprivate func box(_ value: Bool) -> NSObject { return NSNumber(value: value) }
|
||||
fileprivate func box(_ value: Int) -> NSObject { return NSNumber(value: value) }
|
||||
@@ -902,7 +910,7 @@ extension _JSONEncoder {
|
||||
return try self.box(value as! [String : Encodable])
|
||||
}
|
||||
|
||||
// The value should request a container from the _JSONEncoder.
|
||||
// The value should request a container from the __JSONEncoder.
|
||||
let depth = self.storage.count
|
||||
do {
|
||||
try value.encode(to: self)
|
||||
@@ -924,11 +932,14 @@ extension _JSONEncoder {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - _JSONReferencingEncoder
|
||||
// MARK: - __JSONReferencingEncoder
|
||||
|
||||
/// _JSONReferencingEncoder is a special subclass of _JSONEncoder which has its own storage, but references the contents of a different encoder.
|
||||
/// __JSONReferencingEncoder is a special subclass of __JSONEncoder which has its own storage, but references the contents of a different encoder.
|
||||
/// It's used in superEncoder(), which returns a new encoder for encoding a superclass -- the lifetime of the encoder should not escape the scope it's created in, but it doesn't necessarily know when it's done being used (to write to the original container).
|
||||
fileprivate class _JSONReferencingEncoder : _JSONEncoder {
|
||||
// NOTE: older overlays called this class _JSONReferencingEncoder.
|
||||
// The two must coexist without a conflicting ObjC class name, so it
|
||||
// was renamed. The old name must not be used in the new runtime.
|
||||
fileprivate class __JSONReferencingEncoder : __JSONEncoder {
|
||||
// MARK: Reference types.
|
||||
|
||||
/// The type of container we're referencing.
|
||||
@@ -943,7 +954,7 @@ fileprivate class _JSONReferencingEncoder : _JSONEncoder {
|
||||
// MARK: - Properties
|
||||
|
||||
/// The encoder we're referencing.
|
||||
fileprivate let encoder: _JSONEncoder
|
||||
fileprivate let encoder: __JSONEncoder
|
||||
|
||||
/// The container reference itself.
|
||||
private let reference: Reference
|
||||
@@ -951,7 +962,7 @@ fileprivate class _JSONReferencingEncoder : _JSONEncoder {
|
||||
// MARK: - Initialization
|
||||
|
||||
/// Initializes `self` by referencing the given array container in the given encoder.
|
||||
fileprivate init(referencing encoder: _JSONEncoder, at index: Int, wrapping array: NSMutableArray) {
|
||||
fileprivate init(referencing encoder: __JSONEncoder, at index: Int, wrapping array: NSMutableArray) {
|
||||
self.encoder = encoder
|
||||
self.reference = .array(array, index)
|
||||
super.init(options: encoder.options, codingPath: encoder.codingPath)
|
||||
@@ -960,7 +971,7 @@ fileprivate class _JSONReferencingEncoder : _JSONEncoder {
|
||||
}
|
||||
|
||||
/// Initializes `self` by referencing the given dictionary container in the given encoder.
|
||||
fileprivate init(referencing encoder: _JSONEncoder,
|
||||
fileprivate init(referencing encoder: __JSONEncoder,
|
||||
key: CodingKey, convertedKey: __shared CodingKey, wrapping dictionary: NSMutableDictionary) {
|
||||
self.encoder = encoder
|
||||
self.reference = .dictionary(dictionary, convertedKey.stringValue)
|
||||
@@ -1004,6 +1015,11 @@ fileprivate class _JSONReferencingEncoder : _JSONEncoder {
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// `JSONDecoder` facilitates the decoding of JSON into semantic `Decodable` types.
|
||||
// NOTE: older overlays had Foundation.JSONDecoder as the ObjC name.
|
||||
// The two must coexist, so it was renamed. The old name must not be
|
||||
// used in the new runtime. _TtC10Foundation12_JSONDecoder is the
|
||||
// mangled name for Foundation._JSONDecoder.
|
||||
@_objcRuntimeName(_TtC10Foundation12_JSONDecoder)
|
||||
open class JSONDecoder {
|
||||
// MARK: Options
|
||||
|
||||
|
||||
Reference in New Issue
Block a user