Skip to content

Commit 2e5817e

Browse files
authored
Merge pull request #11315 from itaiferber/fix-sr-5206-hack
Remove previous hack for SR-5206
2 parents 11254d0 + e3da1b4 commit 2e5817e

File tree

6 files changed

+51
-147
lines changed

6 files changed

+51
-147
lines changed

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,27 +1827,11 @@ extension NSData : _HasCustomAnyHashableRepresentation {
18271827

18281828
extension Data : Codable {
18291829
public init(from decoder: Decoder) throws {
1830-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
1831-
do {
1832-
let singleValueContainer = try decoder.singleValueContainer()
1833-
if let decoder = singleValueContainer as? _JSONDecoder {
1834-
switch decoder.options.dataDecodingStrategy {
1835-
case .deferredToData:
1836-
break /* fall back to default implementation below; this would recurse */
1837-
1838-
default:
1839-
// _JSONDecoder has a hook for Datas; this won't recurse since we're not going to defer back to Data in _JSONDecoder.
1840-
self = try singleValueContainer.decode(Data.self)
1841-
return
1842-
}
1843-
}
1844-
} catch { /* fall back to default implementation below */ }
1845-
18461830
var container = try decoder.unkeyedContainer()
18471831

18481832
// It's more efficient to pre-allocate the buffer if we can.
18491833
if let count = container.count {
1850-
self = Data(count: count)
1834+
self.init(count: count)
18511835

18521836
// Loop only until count, not while !container.isAtEnd, in case count is underestimated (this is misbehavior) and we haven't allocated enough space.
18531837
// We don't want to write past the end of what we allocated.
@@ -1856,7 +1840,7 @@ extension Data : Codable {
18561840
self[i] = byte
18571841
}
18581842
} else {
1859-
self = Data()
1843+
self.init()
18601844
}
18611845

18621846
while !container.isAtEnd {
@@ -1866,21 +1850,6 @@ extension Data : Codable {
18661850
}
18671851

18681852
public func encode(to encoder: Encoder) throws {
1869-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
1870-
// We are allowed to request this container as long as we don't encode anything through it when we need the unkeyed container below.
1871-
var singleValueContainer = encoder.singleValueContainer()
1872-
if let encoder = singleValueContainer as? _JSONEncoder {
1873-
switch encoder.options.dataEncodingStrategy {
1874-
case .deferredToData:
1875-
break /* fall back to default implementation below; this would recurse */
1876-
1877-
default:
1878-
// _JSONEncoder has a hook for Datas; this won't recurse since we're not going to defer back to Data in _JSONEncoder.
1879-
try singleValueContainer.encode(self)
1880-
return
1881-
}
1882-
}
1883-
18841853
var container = encoder.unkeyedContainer()
18851854

18861855
// Since enumerateBytes does not rethrow, we need to catch the error, stow it away, and rethrow if we stopped.

stdlib/public/SDK/Foundation/Date.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -287,40 +287,13 @@ extension Date : CustomPlaygroundQuickLookable {
287287

288288
extension Date : Codable {
289289
public init(from decoder: Decoder) throws {
290-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
291290
let container = try decoder.singleValueContainer()
292-
if let decoder = container as? _JSONDecoder {
293-
switch decoder.options.dateDecodingStrategy {
294-
case .deferredToDate:
295-
break /* fall back to default implementation below; this would recurse */
296-
297-
default:
298-
// _JSONDecoder has a hook for Dates; this won't recurse since we're not going to defer back to Date in _JSONDecoder.
299-
self = try container.decode(Date.self)
300-
return
301-
}
302-
}
303-
304291
let timestamp = try container.decode(Double.self)
305-
self = Date(timeIntervalSinceReferenceDate: timestamp)
292+
self.init(timeIntervalSinceReferenceDate: timestamp)
306293
}
307294

308295
public func encode(to encoder: Encoder) throws {
309-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
310-
// We are allowed to request this container as long as we don't encode anything through it when we need the keyed container below.
311296
var container = encoder.singleValueContainer()
312-
if let encoder = container as? _JSONEncoder {
313-
switch encoder.options.dateEncodingStrategy {
314-
case .deferredToDate:
315-
break /* fall back to default implementation below; this would recurse */
316-
317-
default:
318-
// _JSONEncoder has a hook for Dates; this won't recurse since we're not going to defer back to Date in _JSONEncoder.
319-
try container.encode(self)
320-
return
321-
}
322-
}
323-
324297
try container.encode(self.timeIntervalSinceReferenceDate)
325298
}
326299
}

stdlib/public/SDK/Foundation/Decimal.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -478,17 +478,6 @@ extension Decimal : Codable {
478478
}
479479

480480
public init(from decoder: Decoder) throws {
481-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
482-
do {
483-
// We are allowed to request this container as long as we don't decode anything through it when we need the keyed container below.
484-
let singleValueContainer = try decoder.singleValueContainer()
485-
if singleValueContainer is _JSONDecoder {
486-
// _JSONDecoder has a hook for Decimals; this won't recurse since we're not going to defer to Decimal in _JSONDecoder.
487-
self = try singleValueContainer.decode(Decimal.self)
488-
return
489-
}
490-
} catch { /* Fall back to default implementation below. */ }
491-
492481
let container = try decoder.container(keyedBy: CodingKeys.self)
493482
let exponent = try container.decode(CInt.self, forKey: .exponent)
494483
let length = try container.decode(CUnsignedInt.self, forKey: .length)
@@ -516,15 +505,6 @@ extension Decimal : Codable {
516505
}
517506

518507
public func encode(to encoder: Encoder) throws {
519-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
520-
// We are allowed to request this container as long as we don't encode anything through it when we need the keyed container below.
521-
var singleValueContainer = encoder.singleValueContainer()
522-
if singleValueContainer is _JSONEncoder {
523-
// _JSONEncoder has a hook for Decimals; this won't recurse since we're not going to defer to Decimal in _JSONEncoder.
524-
try singleValueContainer.encode(self)
525-
return
526-
}
527-
528508
var container = encoder.container(keyedBy: CodingKeys.self)
529509
try container.encode(_exponent, forKey: .exponent)
530510
try container.encode(_length, forKey: .length)

stdlib/public/SDK/Foundation/JSONEncoder.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ open class JSONEncoder {
9999
open var userInfo: [CodingUserInfoKey : Any] = [:]
100100

101101
/// Options set on the top-level encoder to pass down the encoding hierarchy.
102-
internal struct _Options {
102+
fileprivate struct _Options {
103103
let dateEncodingStrategy: DateEncodingStrategy
104104
let dataEncodingStrategy: DataEncodingStrategy
105105
let nonConformingFloatEncodingStrategy: NonConformingFloatEncodingStrategy
@@ -155,14 +155,14 @@ open class JSONEncoder {
155155

156156
// MARK: - _JSONEncoder
157157

158-
internal class _JSONEncoder : Encoder {
158+
fileprivate class _JSONEncoder : Encoder {
159159
// MARK: Properties
160160

161161
/// The encoder's storage.
162162
fileprivate var storage: _JSONEncodingStorage
163163

164164
/// Options set on the top-level encoder.
165-
internal let options: JSONEncoder._Options
165+
fileprivate let options: JSONEncoder._Options
166166

167167
/// The path to the current point in encoding.
168168
public var codingPath: [CodingKey]
@@ -827,7 +827,7 @@ open class JSONDecoder {
827827
open var userInfo: [CodingUserInfoKey : Any] = [:]
828828

829829
/// Options set on the top-level encoder to pass down the decoding hierarchy.
830-
internal struct _Options {
830+
fileprivate struct _Options {
831831
let dateDecodingStrategy: DateDecodingStrategy
832832
let dataDecodingStrategy: DataDecodingStrategy
833833
let nonConformingFloatDecodingStrategy: NonConformingFloatDecodingStrategy
@@ -871,14 +871,14 @@ open class JSONDecoder {
871871

872872
// MARK: - _JSONDecoder
873873

874-
internal class _JSONDecoder : Decoder {
874+
fileprivate class _JSONDecoder : Decoder {
875875
// MARK: Properties
876876

877877
/// The decoder's storage.
878878
fileprivate var storage: _JSONDecodingStorage
879879

880880
/// Options set on the top-level decoder.
881-
internal let options: JSONDecoder._Options
881+
fileprivate let options: JSONDecoder._Options
882882

883883
/// The path to the current point in encoding.
884884
fileprivate(set) public var codingPath: [CodingKey]

stdlib/public/SDK/Foundation/URL.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,17 +1214,6 @@ extension URL : Codable {
12141214
}
12151215

12161216
public init(from decoder: Decoder) throws {
1217-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
1218-
do {
1219-
// We are allowed to request this container as long as we don't decode anything through it when we need the keyed container below.
1220-
let singleValueContainer = try decoder.singleValueContainer()
1221-
if singleValueContainer is _JSONDecoder {
1222-
// _JSONDecoder has a hook for URLs; this won't recurse since we're not going to defer back to URL in _JSONDecoder.
1223-
self = try singleValueContainer.decode(URL.self)
1224-
return
1225-
}
1226-
} catch { /* Fall back to default implementation below. */ }
1227-
12281217
let container = try decoder.container(keyedBy: CodingKeys.self)
12291218
let relative = try container.decode(String.self, forKey: .relative)
12301219
let base = try container.decodeIfPresent(URL.self, forKey: .base)
@@ -1238,15 +1227,6 @@ extension URL : Codable {
12381227
}
12391228

12401229
public func encode(to encoder: Encoder) throws {
1241-
// FIXME: This is a hook for bypassing a conditional conformance implementation to apply a strategy (see SR-5206). Remove this once conditional conformance is available.
1242-
// We are allowed to request this container as long as we don't encode anything through it when we need the keyed container below.
1243-
var singleValueContainer = encoder.singleValueContainer()
1244-
if singleValueContainer is _JSONEncoder {
1245-
// _JSONEncoder has a hook for URLs; this won't recurse since we're not going to defer back to URL in _JSONEncoder.
1246-
try singleValueContainer.encode(self)
1247-
return
1248-
}
1249-
12501230
var container = encoder.container(keyedBy: CodingKeys.self)
12511231
try container.encode(self.relativeString, forKey: .relative)
12521232
if let base = self.baseURL {

0 commit comments

Comments
 (0)