Skip to content

Commit d974e2f

Browse files
committed
stdlib: Remove #if $TypedThrows guards.
#72612 can be reverted because it is no longer necessary for the interface of the stdlib to be compatible with compilers without `$TypedThrows` support.
1 parent 591891f commit d974e2f

17 files changed

+22
-171
lines changed

stdlib/public/Concurrency/ExecutorAssertions.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,12 @@ extension Actor {
360360
fatalError("Incorrect actor executor assumption; Expected same executor as \(self).", file: file, line: line)
361361
}
362362

363-
#if $TypedThrows
364363
// To do the unsafe cast, we have to pretend it's @escaping.
365364
return try withoutActuallyEscaping(operation) {
366365
(_ fn: @escaping YesActor) throws -> T in
367366
let rawFn = unsafeBitCast(fn, to: NoActor.self)
368367
return try rawFn(self)
369368
}
370-
#else
371-
fatalError("unsupported compiler")
372-
#endif
373369
}
374370

375371
@available(SwiftStdlib 5.9, *)

stdlib/public/Concurrency/MainActor.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,12 @@ extension MainActor {
138138
fatalError("Incorrect actor executor assumption; Expected same executor as \(self).", file: file, line: line)
139139
}
140140

141-
#if $TypedThrows
142141
// To do the unsafe cast, we have to pretend it's @escaping.
143142
return try withoutActuallyEscaping(operation) {
144143
(_ fn: @escaping YesActor) throws -> T in
145144
let rawFn = unsafeBitCast(fn, to: NoActor.self)
146145
return try rawFn()
147146
}
148-
#else
149-
fatalError("unsupported compiler")
150-
#endif
151147
}
152148

153149
@available(SwiftStdlib 5.9, *)

stdlib/public/Distributed/DistributedAssertions.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,12 @@ extension DistributedActor {
171171
fatalError("Incorrect actor executor assumption; Expected same executor as \(self).", file: file, line: line)
172172
}
173173

174-
#if $TypedThrows
175174
// To do the unsafe cast, we have to pretend it's @escaping.
176175
return try withoutActuallyEscaping(operation) {
177176
(_ fn: @escaping YesActor) throws -> T in
178177
let rawFn = unsafeBitCast(fn, to: NoActor.self)
179178
return try rawFn(self)
180179
}
181-
#else
182-
fatalError("unsupported compiler")
183-
#endif
184180
}
185181

186182
@available(SwiftStdlib 5.9, *)

stdlib/public/core/ArrayCast.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ public func _arrayForceCast<SourceElement, TargetElement>(
4949
return Array(_immutableCocoaArray: source._buffer._asCocoaArray())
5050
}
5151
#endif
52-
#if $TypedThrows
5352
return source.map { $0 as! TargetElement }
54-
#else
55-
return try! source.__rethrows_map { $0 as! TargetElement }
56-
#endif
5753
}
5854

5955
/// Called by the casting machinery.

stdlib/public/core/Collection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ extension Collection {
12161216
// ABI-only entrypoint for the rethrows version of map, which has been
12171217
// superseded by the typed-throws version. Expressed as "throws", which is
12181218
// ABI-compatible with "rethrows".
1219+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
12191220
@usableFromInline
12201221
@_silgen_name("$sSlsE3mapySayqd__Gqd__7ElementQzKXEKlF")
12211222
func __rethrows_map<T>(

stdlib/public/core/ExistentialCollection.swift

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,7 @@ internal final class _SequenceBox<S: Sequence>: _AnySequenceBox<S.Element> {
550550
internal override func _map<T>(
551551
_ transform: (Element) throws -> T
552552
) throws -> [T] {
553-
#if $TypedThrows
554553
try _base.map(transform)
555-
#else
556-
try _base.__rethrows_map(transform)
557-
#endif
558554
}
559555
@inlinable
560556
internal override func _filter(
@@ -650,11 +646,7 @@ internal final class _CollectionBox<S: Collection>: _AnyCollectionBox<S.Element>
650646
internal override func _map<T>(
651647
_ transform: (Element) throws -> T
652648
) throws -> [T] {
653-
#if $TypedThrows
654649
try _base.map(transform)
655-
#else
656-
try _base.__rethrows_map(transform)
657-
#endif
658650
}
659651
@inlinable
660652
internal override func _filter(
@@ -852,11 +844,7 @@ internal final class _BidirectionalCollectionBox<S: BidirectionalCollection>
852844
internal override func _map<T>(
853845
_ transform: (Element) throws -> T
854846
) throws -> [T] {
855-
#if $TypedThrows
856847
try _base.map(transform)
857-
#else
858-
try _base.__rethrows_map(transform)
859-
#endif
860848
}
861849
@inlinable
862850
internal override func _filter(
@@ -1072,11 +1060,7 @@ internal final class _RandomAccessCollectionBox<S: RandomAccessCollection>
10721060
internal override func _map<T>(
10731061
_ transform: (Element) throws -> T
10741062
) throws -> [T] {
1075-
#if $TypedThrows
10761063
try _base.map(transform)
1077-
#else
1078-
try _base.__rethrows_map(transform)
1079-
#endif
10801064
}
10811065
@inlinable
10821066
internal override func _filter(
@@ -1380,6 +1364,7 @@ extension AnySequence {
13801364
// ABI-only entrypoint for the rethrows version of map, which has been
13811365
// superseded by the typed-throws version. Expressed as "throws", which is
13821366
// ABI-compatible with "rethrows".
1367+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
13831368
@usableFromInline
13841369
@_silgen_name("$ss11AnySequenceV3mapySayqd__Gqd__xKXEKlF")
13851370
func __rethrows_map<T>(
@@ -1483,6 +1468,7 @@ extension AnyCollection {
14831468
// ABI-only entrypoint for the rethrows version of map, which has been
14841469
// superseded by the typed-throws version. Expressed as "throws", which is
14851470
// ABI-compatible with "rethrows".
1471+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
14861472
@usableFromInline
14871473
@_silgen_name("$ss13AnyCollectionV3mapySayqd__Gqd__xKXEKlF")
14881474
func __rethrows_map<T>(
@@ -1592,6 +1578,7 @@ extension AnyBidirectionalCollection {
15921578
// ABI-only entrypoint for the rethrows version of map, which has been
15931579
// superseded by the typed-throws version. Expressed as "throws", which is
15941580
// ABI-compatible with "rethrows".
1581+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
15951582
@usableFromInline
15961583
@_silgen_name("$ss26AnyBidirectionalCollectionV3mapySayqd__Gqd__xKXEKlF")
15971584
func __rethrows_map<T>(
@@ -1703,6 +1690,7 @@ extension AnyRandomAccessCollection {
17031690
// ABI-only entrypoint for the rethrows version of map, which has been
17041691
// superseded by the typed-throws version. Expressed as "throws", which is
17051692
// ABI-compatible with "rethrows".
1693+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
17061694
@usableFromInline
17071695
@_silgen_name("$ss25AnyRandomAccessCollectionV3mapySayqd__Gqd__xKXEKlF")
17081696
func __rethrows_map<T>(

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ extension ${Self}: LosslessStringConvertible {
169169
self.init(Substring(text))
170170
} else {
171171
self = 0.0
172-
#if $TypedThrows
173172
let success = _withUnprotectedUnsafeMutablePointer(to: &self) { p -> Bool in
174173
text.withCString { chars -> Bool in
175174
switch chars[0] {
@@ -185,23 +184,6 @@ extension ${Self}: LosslessStringConvertible {
185184
return endPtr != nil && endPtr![0] == 0
186185
}
187186
}
188-
#else
189-
let success = __abi_se0413_withUnsafeMutablePointer(to: &self) { p -> Bool in
190-
text.withCString { chars -> Bool in
191-
switch chars[0] {
192-
case 9, 10, 11, 12, 13, 32:
193-
return false // Reject leading whitespace
194-
case 0:
195-
return false // Reject empty string
196-
default:
197-
break
198-
}
199-
let endPtr = _swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(chars, p)
200-
// Succeed only if endPtr points to end of C string
201-
return endPtr != nil && endPtr![0] == 0
202-
}
203-
}
204-
#endif
205187
if !success {
206188
return nil
207189
}
@@ -216,7 +198,6 @@ extension ${Self}: LosslessStringConvertible {
216198
@available(SwiftStdlib 5.3, *)
217199
public init?(_ text: Substring) {
218200
self = 0.0
219-
#if $TypedThrows
220201
let success = _withUnprotectedUnsafeMutablePointer(to: &self) { p -> Bool in
221202
text.withCString { chars -> Bool in
222203
switch chars[0] {
@@ -232,23 +213,6 @@ extension ${Self}: LosslessStringConvertible {
232213
return endPtr != nil && endPtr![0] == 0
233214
}
234215
}
235-
#else
236-
let success = __abi_se0413_withUnsafeMutablePointer(to: &self) { p -> Bool in
237-
text.withCString { chars -> Bool in
238-
switch chars[0] {
239-
case 9, 10, 11, 12, 13, 32:
240-
return false // Reject leading whitespace
241-
case 0:
242-
return false // Reject empty string
243-
default:
244-
break
245-
}
246-
let endPtr = _swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(chars, p)
247-
// Succeed only if endPtr points to end of C string
248-
return endPtr != nil && endPtr![0] == 0
249-
}
250-
}
251-
#endif
252216
if !success {
253217
return nil
254218
}

stdlib/public/core/LifetimeManager.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,13 @@ public func withUnsafeMutablePointer<
106106
try body(UnsafeMutablePointer<T>(Builtin.addressof(&value)))
107107
}
108108

109-
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
110-
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
109+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
111110
@_silgen_name("$ss24withUnsafeMutablePointer2to_q_xz_q_SpyxGKXEtKr0_lF")
112111
@usableFromInline
113112
internal func __abi_se0413_withUnsafeMutablePointer<T, Result>(
114113
to value: inout T,
115114
_ body: (UnsafeMutablePointer<T>) throws -> Result
116-
) rethrows -> Result {
115+
) throws -> Result {
117116
return try body(UnsafeMutablePointer<T>(Builtin.addressof(&value)))
118117
}
119118

@@ -167,14 +166,13 @@ public func withUnsafePointer<T: ~Copyable, E: Error, Result: ~Copyable>(
167166

168167
/// ABI: Historical withUnsafePointer(to:_:) rethrows, expressed as "throws",
169168
/// which is ABI-compatible with "rethrows".
170-
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
171-
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
169+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
172170
@_silgen_name("$ss17withUnsafePointer2to_q_x_q_SPyxGKXEtKr0_lF")
173171
@usableFromInline
174172
internal func __abi_withUnsafePointer<T, Result>(
175173
to value: T,
176174
_ body: (UnsafePointer<T>) throws -> Result
177-
) rethrows -> Result
175+
) throws -> Result
178176
{
179177
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
180178
}
@@ -213,14 +211,13 @@ public func withUnsafePointer<T: ~Copyable, E: Error, Result: ~Copyable>(
213211

214212
/// ABI: Historical withUnsafePointer(to:_:) rethrows,
215213
/// expressed as "throws", which is ABI-compatible with "rethrows".
216-
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
217-
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
214+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
218215
@_silgen_name("$ss17withUnsafePointer2to_q_xz_q_SPyxGKXEtKr0_lF")
219216
@usableFromInline
220217
internal func __abi_se0413_withUnsafePointer<T, Result>(
221218
to value: inout T,
222219
_ body: (UnsafePointer<T>) throws -> Result
223-
) rethrows -> Result {
220+
) throws -> Result {
224221
return try body(UnsafePointer<T>(Builtin.addressof(&value)))
225222
}
226223

stdlib/public/core/Random.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,9 @@ public struct SystemRandomNumberGenerator: RandomNumberGenerator, Sendable {
158158
@inlinable
159159
public mutating func next() -> UInt64 {
160160
var random: UInt64 = 0
161-
#if $TypedThrows
162161
_withUnprotectedUnsafeMutablePointer(to: &random) {
163162
swift_stdlib_random($0, MemoryLayout<UInt64>.size)
164163
}
165-
#else
166-
__abi_se0413_withUnsafeMutablePointer(to: &random) {
167-
swift_stdlib_random($0, MemoryLayout<UInt64>.size)
168-
}
169-
#endif
170164
return random
171165
}
172166
}

stdlib/public/core/Runtime.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,11 @@ func _stdlib_atomicInitializeARCRef(
139139
let desiredPtr = unmanaged.toOpaque()
140140
let rawTarget = UnsafeMutableRawPointer(target).assumingMemoryBound(
141141
to: Optional<UnsafeRawPointer>.self)
142-
#if $TypedThrows
143142
let wonRace = withUnsafeMutablePointer(to: &expected) {
144143
_stdlib_atomicCompareExchangeStrongPtr(
145144
object: rawTarget, expected: $0, desired: desiredPtr
146145
)
147146
}
148-
#else
149-
let wonRace = __abi_se0413_withUnsafeMutablePointer(to: &expected) {
150-
_stdlib_atomicCompareExchangeStrongPtr(
151-
object: rawTarget, expected: $0, desired: desiredPtr
152-
)
153-
}
154-
#endif
155147
if !wonRace {
156148
// Some other thread initialized the value. Balance the retain that we
157149
// performed on 'desired'.

stdlib/public/core/Sequence.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ extension Sequence {
706706
// ABI-only entrypoint for the rethrows version of map, which has been
707707
// superseded by the typed-throws version. Expressed as "throws", which is
708708
// ABI-compatible with "rethrows".
709+
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
709710
@usableFromInline
710711
@_silgen_name("$sSTsE3mapySayqd__Gqd__7ElementQzKXEKlF")
711712
func __rethrows_map<T>(

stdlib/public/core/SmallString.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ extension _SmallString {
223223
) rethrows -> Result {
224224
let count = self.count
225225
var raw = self.zeroTerminatedRawCodeUnits
226-
#if $TypedThrows
227226
return try Swift._withUnprotectedUnsafeBytes(of: &raw) {
228227
let rawPtr = $0.baseAddress._unsafelyUnwrappedUnchecked
229228
// Rebind the underlying (UInt64, UInt64) tuple to UInt8 for the
@@ -235,19 +234,6 @@ extension _SmallString {
235234
}
236235
return try f(UnsafeBufferPointer(_uncheckedStart: ptr, count: count))
237236
}
238-
#else
239-
return try Swift.__abi_se0413_withUnsafeBytes(of: &raw) {
240-
let rawPtr = $0.baseAddress._unsafelyUnwrappedUnchecked
241-
// Rebind the underlying (UInt64, UInt64) tuple to UInt8 for the
242-
// duration of the closure. Accessing self after this rebind is undefined.
243-
let ptr = rawPtr.bindMemory(to: UInt8.self, capacity: count)
244-
defer {
245-
// Restore the memory type of self._storage
246-
_ = rawPtr.bindMemory(to: RawBitPattern.self, capacity: 1)
247-
}
248-
return try f(UnsafeBufferPointer(_uncheckedStart: ptr, count: count))
249-
}
250-
#endif
251237
}
252238

253239
// Overwrite stored code units, including uninitialized. `f` should return the

stdlib/public/core/UnicodeScalar.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,10 @@ extension Unicode.Scalar {
528528

529529
// The first code unit is in the least significant byte of codeUnits.
530530
codeUnits = codeUnits.littleEndian
531-
#if $TypedThrows
532531
return try Swift._withUnprotectedUnsafePointer(to: &codeUnits) {
533532
return try $0.withMemoryRebound(to: UInt8.self, capacity: 4) {
534533
return try body(UnsafeBufferPointer(start: $0, count: utf8Count))
535534
}
536535
}
537-
#else
538-
return try Swift.__abi_se0413_withUnsafePointer(to: &codeUnits) {
539-
return try $0.withMemoryRebound(to: UInt8.self, capacity: 4) {
540-
return try body(UnsafeBufferPointer(start: $0, count: utf8Count))
541-
}
542-
}
543-
#endif
544536
}
545537
}

0 commit comments

Comments
 (0)