Add temporary workaround for broken OutputSpan.wUMBP in current toolchain snapshots

(cherry picked from commit 0b1ff87d6773fe568945d8af86a236dbbf9157d9)
This commit is contained in:
Guillaume Lessard authored and Karoy Lorentey committed 2026-01-29 11:26:13 -08:00
1 parent ead06d8983
commit 942cfbfd68
1 file changed
+25
@@ -250,6 +250,31 @@ extension RigidArray where Element: ~Copyable {
#endif
}
@available(SwiftStdlib 5.0, *)
extension OutputSpan where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
mutating func _withUnsafeMutableBufferPointer<E: Error, R: ~Copyable>(
_ body: (
UnsafeMutableBufferPointer<Element>,
_ initializedCount: inout Int
) throws(E) -> R
) throws(E) -> R {
// FIXME: Work around rdar://169036911
let capacity = self.capacity
let baseAddress = self.span.withUnsafeBufferPointer { $0.baseAddress } // Wow.
return try withUnsafeMutableBufferPointer { buffer, count throws(E) in
let correctedBuffer = UnsafeMutableRawBufferPointer(
start: .init(mutating: baseAddress), // Wow, wow.
count: capacity &* MemoryLayout<Element>.stride)
return try correctedBuffer.withMemoryRebound(to: Element.self) {
correctBuffer throws(E) in
try body(correctBuffer, &count)
}
}
}
}
@available(SwiftStdlib 5.0, *)
extension RigidArray {
/// Copies the elements of a fully initialized buffer pointer into this