Skip to content

Commit e097464

Browse files
itaiferberItai Ferber
authored andcommitted
Merge pull request swiftlang#11315 from itaiferber/fix-sr-5206-hack
Remove previous hack for SR-5206
1 parent b878d3b commit e097464

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
@@ -1926,27 +1926,11 @@ extension NSData : _HasCustomAnyHashableRepresentation {
19261926

19271927
extension Data : Codable {
19281928
public init(from decoder: Decoder) throws {
1929-
// 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.
1930-
do {
1931-
let singleValueContainer = try decoder.singleValueContainer()
1932-
if let decoder = singleValueContainer as? _JSONDecoder {
1933-
switch decoder.options.dataDecodingStrategy {
1934-
case .deferredToData:
1935-
break /* fall back to default implementation below; this would recurse */
1936-
1937-
default:
1938-
// _JSONDecoder has a hook for Datas; this won't recurse since we're not going to defer back to Data in _JSONDecoder.
1939-
self = try singleValueContainer.decode(Data.self)
1940-
return
1941-
}
1942-
}
1943-
} catch { /* fall back to default implementation below */ }
1944-
19451929
var container = try decoder.unkeyedContainer()
19461930

19471931
// It's more efficient to pre-allocate the buffer if we can.
19481932
if let count = container.count {
1949-
self = Data(count: count)
1933+
self.init(count: count)
19501934

19511935
// Loop only until count, not while !container.isAtEnd, in case count is underestimated (this is misbehavior) and we haven't allocated enough space.
19521936
// We don't want to write past the end of what we allocated.
@@ -1955,7 +1939,7 @@ extension Data : Codable {
19551939
self[i] = byte
19561940
}
19571941
} else {
1958-
self = Data()
1942+
self.init()
19591943
}
19601944

19611945
while !container.isAtEnd {
@@ -1965,21 +1949,6 @@ extension Data : Codable {
19651949
}
19661950

19671951
public func encode(to encoder: Encoder) throws {
1968-
// 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.
1969-
// We are allowed to request this container as long as we don't encode anything through it when we need the unkeyed container below.
1970-
var singleValueContainer = encoder.singleValueContainer()
1971-
if let encoder = singleValueContainer as? _JSONEncoder {
1972-
switch encoder.options.dataEncodingStrategy {
1973-
case .deferredToData:
1974-
break /* fall back to default implementation below; this would recurse */
1975-
1976-
default:
1977-
// _JSONEncoder has a hook for Datas; this won't recurse since we're not going to defer back to Data in _JSONEncoder.
1978-
try singleValueContainer.encode(self)
1979-
return
1980-
}
1981-
}
1982-
19831952
var container = encoder.unkeyedContainer()
19841953

19851954
// 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
@@ -471,17 +471,6 @@ extension Decimal : Codable {
471471
}
472472

473473
public init(from decoder: Decoder) throws {
474-
// 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.
475-
do {
476-
// We are allowed to request this container as long as we don't decode anything through it when we need the keyed container below.
477-
let singleValueContainer = try decoder.singleValueContainer()
478-
if singleValueContainer is _JSONDecoder {
479-
// _JSONDecoder has a hook for Decimals; this won't recurse since we're not going to defer to Decimal in _JSONDecoder.
480-
self = try singleValueContainer.decode(Decimal.self)
481-
return
482-
}
483-
} catch { /* Fall back to default implementation below. */ }
484-
485474
let container = try decoder.container(keyedBy: CodingKeys.self)
486475
let exponent = try container.decode(CInt.self, forKey: .exponent)
487476
let length = try container.decode(CUnsignedInt.self, forKey: .length)
@@ -509,15 +498,6 @@ extension Decimal : Codable {
509498
}
510499

511500
public func encode(to encoder: Encoder) throws {
512-
// 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.
513-
// We are allowed to request this container as long as we don't encode anything through it when we need the keyed container below.
514-
var singleValueContainer = encoder.singleValueContainer()
515-
if singleValueContainer is _JSONEncoder {
516-
// _JSONEncoder has a hook for Decimals; this won't recurse since we're not going to defer to Decimal in _JSONEncoder.
517-
try singleValueContainer.encode(self)
518-
return
519-
}
520-
521501
var container = encoder.container(keyedBy: CodingKeys.self)
522502
try container.encode(_exponent, forKey: .exponent)
523503
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)