Skip to content

stdlib: Avoid condfails resulting from typed throws adoption #71802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/public/core/ArrayCast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public func _arrayForceCast<SourceElement, TargetElement>(
return Array(_immutableCocoaArray: source._buffer._asCocoaArray())
}
#endif
#if $TypedThrows
return source.map { $0 as! TargetElement }
#else
return try! source.__rethrows_map { $0 as! TargetElement }
#endif
}

/// Called by the casting machinery.
Expand Down
16 changes: 16 additions & 0 deletions stdlib/public/core/ExistentialCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,11 @@ internal final class _SequenceBox<S: Sequence>: _AnySequenceBox<S.Element> {
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -619,7 +623,11 @@ internal final class _CollectionBox<S: Collection>: _AnyCollectionBox<S.Element>
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -814,7 +822,11 @@ internal final class _BidirectionalCollectionBox<S: BidirectionalCollection>
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -1027,7 +1039,11 @@ internal final class _RandomAccessCollectionBox<S: RandomAccessCollection>
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down
12 changes: 12 additions & 0 deletions stdlib/public/core/UnsafeRawPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
) {
_debugPrecondition(_isPOD(T.self))

#if $TypedThrows
withUnsafePointer(to: value) { source in
// FIXME: to be replaced by _memcpy when conversions are implemented.
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
Expand All @@ -1341,6 +1342,17 @@ public struct UnsafeMutableRawPointer: _Pointer {
/*volatile:*/ false._value
)
}
#else
try! __abi_withUnsafePointer(to: value) { source in
// FIXME: to be replaced by _memcpy when conversions are implemented.
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
(self + offset)._rawValue,
source._rawValue,
UInt64(MemoryLayout<T>.size)._value,
/*volatile:*/ false._value
)
}
#endif
}

// This unavailable implementation uses the expected mangled name
Expand Down