Skip to content

Commit 3b42dc7

Browse files
committed
[stdlib][Foundation] Avoid coexistence conflicts with JSONEncoder/Decoder and _stdlib_AtomicInt.
JSONEcoder/Decoder get another underscore in their ObjC name, as the one with a single underscore conflicts with older Swifts that had _JSONEcoder/Decoder as internal rather than fileprivate. _JSONEncoder/Decoder get another underscore in their Swift name to avoid conflicting with the ObjC name from the ones in older overlays.
1 parent fd91e7f commit 3b42dc7

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

Darwin/Foundation-swiftoverlay/JSONEncoder.swift

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ extension Dictionary : _JSONStringDictionaryDecodableMarker where Key == String,
5353
/// `JSONEncoder` facilitates the encoding of `Encodable` values into JSON.
5454
// NOTE: older overlays had Foundation.JSONEncoder as the ObjC name.
5555
// The two must coexist, so it was renamed. The old name must not be
56-
// used in the new runtime. _TtC10Foundation12_JSONEncoder is the
57-
// mangled name for Foundation._JSONEncoder.
58-
@_objcRuntimeName(_TtC10Foundation12_JSONEncoder)
56+
// used in the new runtime. _TtC10Foundation13__JSONEncoder is the
57+
// mangled name for Foundation.__JSONEncoder.
58+
@_objcRuntimeName(_TtC10Foundation13__JSONEncoder)
5959
open class JSONEncoder {
6060
// MARK: Options
6161

@@ -1017,9 +1017,9 @@ fileprivate class __JSONReferencingEncoder : __JSONEncoder {
10171017
/// `JSONDecoder` facilitates the decoding of JSON into semantic `Decodable` types.
10181018
// NOTE: older overlays had Foundation.JSONDecoder as the ObjC name.
10191019
// The two must coexist, so it was renamed. The old name must not be
1020-
// used in the new runtime. _TtC10Foundation12_JSONDecoder is the
1021-
// mangled name for Foundation._JSONDecoder.
1022-
@_objcRuntimeName(_TtC10Foundation12_JSONDecoder)
1020+
// used in the new runtime. _TtC10Foundation13__JSONDecoder is the
1021+
// mangled name for Foundation.__JSONDecoder.
1022+
@_objcRuntimeName(_TtC10Foundation13__JSONDecoder)
10231023
open class JSONDecoder {
10241024
// MARK: Options
10251025

@@ -1190,7 +1190,7 @@ open class JSONDecoder {
11901190
throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: error))
11911191
}
11921192

1193-
let decoder = _JSONDecoder(referencing: topLevel, options: self.options)
1193+
let decoder = __JSONDecoder(referencing: topLevel, options: self.options)
11941194
guard let value = try decoder.unbox(topLevel, as: type) else {
11951195
throw DecodingError.valueNotFound(type, DecodingError.Context(codingPath: [], debugDescription: "The given data did not contain a top-level value."))
11961196
}
@@ -1199,9 +1199,12 @@ open class JSONDecoder {
11991199
}
12001200
}
12011201

1202-
// MARK: - _JSONDecoder
1202+
// MARK: - __JSONDecoder
12031203

1204-
fileprivate class _JSONDecoder : Decoder {
1204+
// NOTE: older overlays called this class _JSONDecoder. The two must
1205+
// coexist without a conflicting ObjC class name, so it was renamed.
1206+
// The old name must not be used in the new runtime.
1207+
fileprivate class __JSONDecoder : Decoder {
12051208
// MARK: Properties
12061209

12071210
/// The decoder's storage.
@@ -1307,7 +1310,7 @@ fileprivate struct _JSONKeyedDecodingContainer<K : CodingKey> : KeyedDecodingCon
13071310
// MARK: Properties
13081311

13091312
/// A reference to the decoder we're reading from.
1310-
private let decoder: _JSONDecoder
1313+
private let decoder: __JSONDecoder
13111314

13121315
/// A reference to the container we're reading from.
13131316
private let container: [String : Any]
@@ -1318,7 +1321,7 @@ fileprivate struct _JSONKeyedDecodingContainer<K : CodingKey> : KeyedDecodingCon
13181321
// MARK: - Initialization
13191322

13201323
/// Initializes `self` by referencing the given decoder and container.
1321-
fileprivate init(referencing decoder: _JSONDecoder, wrapping container: [String : Any]) {
1324+
fileprivate init(referencing decoder: __JSONDecoder, wrapping container: [String : Any]) {
13221325
self.decoder = decoder
13231326
switch decoder.options.keyDecodingStrategy {
13241327
case .useDefaultKeys:
@@ -1637,7 +1640,7 @@ fileprivate struct _JSONKeyedDecodingContainer<K : CodingKey> : KeyedDecodingCon
16371640
defer { self.decoder.codingPath.removeLast() }
16381641

16391642
let value: Any = self.container[key.stringValue] ?? NSNull()
1640-
return _JSONDecoder(referencing: value, at: self.decoder.codingPath, options: self.decoder.options)
1643+
return __JSONDecoder(referencing: value, at: self.decoder.codingPath, options: self.decoder.options)
16411644
}
16421645

16431646
public func superDecoder() throws -> Decoder {
@@ -1653,7 +1656,7 @@ fileprivate struct _JSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
16531656
// MARK: Properties
16541657

16551658
/// A reference to the decoder we're reading from.
1656-
private let decoder: _JSONDecoder
1659+
private let decoder: __JSONDecoder
16571660

16581661
/// A reference to the container we're reading from.
16591662
private let container: [Any]
@@ -1667,7 +1670,7 @@ fileprivate struct _JSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
16671670
// MARK: - Initialization
16681671

16691672
/// Initializes `self` by referencing the given decoder and container.
1670-
fileprivate init(referencing decoder: _JSONDecoder, wrapping container: [Any]) {
1673+
fileprivate init(referencing decoder: __JSONDecoder, wrapping container: [Any]) {
16711674
self.decoder = decoder
16721675
self.container = container
16731676
self.codingPath = decoder.codingPath
@@ -2000,11 +2003,11 @@ fileprivate struct _JSONUnkeyedDecodingContainer : UnkeyedDecodingContainer {
20002003

20012004
let value = self.container[self.currentIndex]
20022005
self.currentIndex += 1
2003-
return _JSONDecoder(referencing: value, at: self.decoder.codingPath, options: self.decoder.options)
2006+
return __JSONDecoder(referencing: value, at: self.decoder.codingPath, options: self.decoder.options)
20042007
}
20052008
}
20062009

2007-
extension _JSONDecoder : SingleValueDecodingContainer {
2010+
extension __JSONDecoder : SingleValueDecodingContainer {
20082011
// MARK: SingleValueDecodingContainer Methods
20092012

20102013
private func expectNonNull<T>(_ type: T.Type) throws {
@@ -2095,7 +2098,7 @@ extension _JSONDecoder : SingleValueDecodingContainer {
20952098

20962099
// MARK: - Concrete Value Representations
20972100

2098-
extension _JSONDecoder {
2101+
extension __JSONDecoder {
20992102
/// Returns the given value unboxed from a container.
21002103
fileprivate func unbox(_ value: Any, as type: Bool.Type) throws -> Bool? {
21012104
guard !(value is NSNull) else { return nil }

0 commit comments

Comments
 (0)