Skip to content

Commit 25c0ed6

Browse files
committed
stdlib: Avoid condfails resulting from typed throws adoption.
The standard library's swiftinterface must temporarily remain buildable when `$TypedThrows` evaluates to false since there are still supported Swift 5.11 compilers that did not have the feature enabled by default. Declarations using typed throws in their signatures are guarded in printed swiftinterface files with `#if $TypedThrows` and therefore `@inlinable` code that uses those declarations must also be conditionalized on `$TypedThrows`.
1 parent 898c024 commit 25c0ed6

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

stdlib/public/core/ArrayCast.swift

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

5559
/// Called by the casting machinery.

stdlib/public/core/ExistentialCollection.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ internal final class _SequenceBox<S: Sequence>: _AnySequenceBox<S.Element> {
526526
internal override func _map<T>(
527527
_ transform: (Element) throws -> T
528528
) throws -> [T] {
529+
#if $TypedThrows
529530
try _base.map(transform)
531+
#else
532+
try _base.__rethrows_map(transform)
533+
#endif
530534
}
531535
@inlinable
532536
internal override func _filter(
@@ -619,7 +623,11 @@ internal final class _CollectionBox<S: Collection>: _AnyCollectionBox<S.Element>
619623
internal override func _map<T>(
620624
_ transform: (Element) throws -> T
621625
) throws -> [T] {
626+
#if $TypedThrows
622627
try _base.map(transform)
628+
#else
629+
try _base.__rethrows_map(transform)
630+
#endif
623631
}
624632
@inlinable
625633
internal override func _filter(
@@ -814,7 +822,11 @@ internal final class _BidirectionalCollectionBox<S: BidirectionalCollection>
814822
internal override func _map<T>(
815823
_ transform: (Element) throws -> T
816824
) throws -> [T] {
825+
#if $TypedThrows
817826
try _base.map(transform)
827+
#else
828+
try _base.__rethrows_map(transform)
829+
#endif
818830
}
819831
@inlinable
820832
internal override func _filter(
@@ -1027,7 +1039,11 @@ internal final class _RandomAccessCollectionBox<S: RandomAccessCollection>
10271039
internal override func _map<T>(
10281040
_ transform: (Element) throws -> T
10291041
) throws -> [T] {
1042+
#if $TypedThrows
10301043
try _base.map(transform)
1044+
#else
1045+
try _base.__rethrows_map(transform)
1046+
#endif
10311047
}
10321048
@inlinable
10331049
internal override func _filter(

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
13321332
) {
13331333
_debugPrecondition(_isPOD(T.self))
13341334

1335+
#if $TypedThrows
13351336
withUnsafePointer(to: value) { source in
13361337
// FIXME: to be replaced by _memcpy when conversions are implemented.
13371338
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
@@ -1341,6 +1342,17 @@ public struct UnsafeMutableRawPointer: _Pointer {
13411342
/*volatile:*/ false._value
13421343
)
13431344
}
1345+
#else
1346+
try! __abi_withUnsafePointer(to: value) { source in
1347+
// FIXME: to be replaced by _memcpy when conversions are implemented.
1348+
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
1349+
(self + offset)._rawValue,
1350+
source._rawValue,
1351+
UInt64(MemoryLayout<T>.size)._value,
1352+
/*volatile:*/ false._value
1353+
)
1354+
}
1355+
#endif
13441356
}
13451357

13461358
// This unavailable implementation uses the expected mangled name

0 commit comments

Comments
 (0)