Skip to content

Commit 92b075b

Browse files
committed
[embedded] Drop several #ifs and fatalError()s by adding an unavailable ExpressibleByStringInterpolation String conformance
1 parent cba7cdf commit 92b075b

10 files changed

+11
-49
lines changed

stdlib/public/core/Availability.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,10 @@ extension _SwiftStdlibVersion {
109109
extension _SwiftStdlibVersion: CustomStringConvertible {
110110
@available(SwiftStdlib 5.7, *)
111111
public var description: String {
112-
#if $Embedded
113-
fatalError()
114-
#else
115112
let major = _value >> 16
116113
let minor = (_value >> 8) & 0xFF
117114
let patch = _value & 0xFF
118115
return "\(major).\(minor).\(patch)"
119-
#endif
120116
}
121117
}
122118

stdlib/public/core/CTypes.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,11 @@ public struct CVaListPointer {
268268
@_unavailableInEmbedded
269269
extension CVaListPointer: CustomDebugStringConvertible {
270270
public var debugDescription: String {
271-
#if !$Embedded
272271
return "(\(_value.__stack.debugDescription), " +
273272
"\(_value.__gr_top.debugDescription), " +
274273
"\(_value.__vr_top.debugDescription), " +
275274
"\(_value.__gr_off), " +
276275
"\(_value.__vr_off))"
277-
#else
278-
fatalError()
279-
#endif
280276
}
281277
}
282278

stdlib/public/core/ClosedRange.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -385,24 +385,16 @@ extension ClosedRange: CustomStringConvertible {
385385
/// A textual representation of the range.
386386
@inlinable // trivial-implementation...
387387
public var description: String {
388-
#if $Embedded
389-
fatalError()
390-
#else
391388
return "\(lowerBound)...\(upperBound)"
392-
#endif
393389
}
394390
}
395391

396392
@_unavailableInEmbedded
397393
extension ClosedRange: CustomDebugStringConvertible {
398394
/// A textual representation of the range, suitable for debugging.
399395
public var debugDescription: String {
400-
#if $Embedded
401-
fatalError()
402-
#else
403396
return "ClosedRange(\(String(reflecting: lowerBound))"
404397
+ "...\(String(reflecting: upperBound)))"
405-
#endif
406398
}
407399
}
408400

@@ -490,9 +482,6 @@ public typealias CountableClosedRange<Bound: Strideable> = ClosedRange<Bound>
490482
@_unavailableInEmbedded
491483
extension ClosedRange: Decodable where Bound: Decodable {
492484
public init(from decoder: Decoder) throws {
493-
#if $Embedded
494-
fatalError()
495-
#else
496485
var container = try decoder.unkeyedContainer()
497486
let lowerBound = try container.decode(Bound.self)
498487
let upperBound = try container.decode(Bound.self)
@@ -503,7 +492,6 @@ extension ClosedRange: Decodable where Bound: Decodable {
503492
debugDescription: "Cannot initialize \(ClosedRange.self) with a lowerBound (\(lowerBound)) greater than upperBound (\(upperBound))"))
504493
}
505494
self.init(_uncheckedBounds: (lower: lowerBound, upper: upperBound))
506-
#endif
507495
}
508496
}
509497

stdlib/public/core/CollectionOfOne.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,7 @@ extension CollectionOfOne: RandomAccessCollection, MutableCollection {
162162
extension CollectionOfOne: CustomDebugStringConvertible {
163163
/// A textual representation of the collection, suitable for debugging.
164164
public var debugDescription: String {
165-
#if !$Embedded
166165
return "CollectionOfOne(\(String(reflecting: _element)))"
167-
#else
168-
fatalError()
169-
#endif
170166
}
171167
}
172168

stdlib/public/core/EmbeddedStubs.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ extension String {
103103
public init(stringInterpolation: DefaultStringInterpolation) { fatalError() }
104104
}
105105

106+
@_unavailableInEmbedded
107+
extension String: ExpressibleByStringInterpolation { }
108+
106109
@_unavailableInEmbedded
107110
public protocol LosslessStringConvertible: CustomStringConvertible {
108111
init?(_ description: String)

stdlib/public/core/Integers.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3046,7 +3046,14 @@ extension FixedWidthInteger {
30463046
@inline(__always)
30473047
public init<T: BinaryFloatingPoint>(_ source: T) {
30483048
guard let value = Self._convert(from: source).value else {
3049-
fatalError()
3049+
#if !$Embedded
3050+
fatalError("""
3051+
\(T.self) value cannot be converted to \(Self.self) because it is \
3052+
outside the representable range
3053+
""")
3054+
#else
3055+
fatalError("value not representable")
3056+
#endif
30503057
}
30513058
self = value
30523059
}

stdlib/public/core/ObjectIdentifier.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,7 @@ public struct ObjectIdentifier: Sendable {
6868
extension ObjectIdentifier: CustomDebugStringConvertible {
6969
/// A textual representation of the identifier, suitable for debugging.
7070
public var debugDescription: String {
71-
#if !$Embedded
7271
return "ObjectIdentifier(\(_rawPointerToString(_value)))"
73-
#else
74-
fatalError()
75-
#endif
7672
}
7773
}
7874

stdlib/public/core/Range.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,24 +380,16 @@ extension Range: CustomStringConvertible {
380380
/// A textual representation of the range.
381381
@inlinable // trivial-implementation
382382
public var description: String {
383-
#if $Embedded
384-
fatalError()
385-
#else
386383
return "\(lowerBound)..<\(upperBound)"
387-
#endif
388384
}
389385
}
390386

391387
@_unavailableInEmbedded
392388
extension Range: CustomDebugStringConvertible {
393389
/// A textual representation of the range, suitable for debugging.
394390
public var debugDescription: String {
395-
#if !$Embedded
396391
return "Range(\(String(reflecting: lowerBound))"
397392
+ "..<\(String(reflecting: upperBound)))"
398-
#else
399-
fatalError()
400-
#endif
401393
}
402394
}
403395

@@ -451,7 +443,6 @@ extension Range: Hashable where Bound: Hashable {
451443
@_unavailableInEmbedded
452444
extension Range: Decodable where Bound: Decodable {
453445
public init(from decoder: Decoder) throws {
454-
#if !$Embedded
455446
var container = try decoder.unkeyedContainer()
456447
let lowerBound = try container.decode(Bound.self)
457448
let upperBound = try container.decode(Bound.self)
@@ -462,9 +453,6 @@ extension Range: Decodable where Bound: Decodable {
462453
debugDescription: "Cannot initialize \(Range.self) with a lowerBound (\(lowerBound)) greater than upperBound (\(upperBound))"))
463454
}
464455
self.init(_uncheckedBounds: (lower: lowerBound, upper: upperBound))
465-
#else
466-
fatalError()
467-
#endif
468456
}
469457
}
470458

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,12 +1194,8 @@ extension Unsafe${Mutable}BufferPointer {
11941194
extension Unsafe${Mutable}BufferPointer: CustomDebugStringConvertible {
11951195
/// A textual representation of the buffer, suitable for debugging.
11961196
public var debugDescription: String {
1197-
#if $Embedded
1198-
fatalError()
1199-
#else
12001197
return "Unsafe${Mutable}BufferPointer"
12011198
+ "(start: \(_position.map(String.init(describing:)) ?? "nil"), count: \(count))"
1202-
#endif
12031199
}
12041200
}
12051201
%end

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,12 +1147,8 @@ extension Unsafe${Mutable}RawBufferPointer {
11471147
extension Unsafe${Mutable}RawBufferPointer: CustomDebugStringConvertible {
11481148
/// A textual representation of the buffer, suitable for debugging.
11491149
public var debugDescription: String {
1150-
#if $Embedded
1151-
fatalError()
1152-
#else
11531150
return "${Self}"
11541151
+ "(start: \(_position.map(String.init(describing:)) ?? "nil"), count: \(count))"
1155-
#endif
11561152
}
11571153
}
11581154

0 commit comments

Comments
 (0)