From 942cfbfd68126875e91bce86d7973cbf67e364c8 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Wed, 28 Jan 2026 17:28:15 -0800 Subject: [PATCH] Add temporary workaround for broken OutputSpan.wUMBP in current toolchain snapshots (cherry picked from commit 0b1ff87d6773fe568945d8af86a236dbbf9157d9) --- .../RigidArray+Insertions.swift | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Sources/BasicContainers/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray+Insertions.swift index 856aebd4..80d08c8f 100644 --- a/Sources/BasicContainers/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray+Insertions.swift @@ -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( + _ body: ( + UnsafeMutableBufferPointer, + _ 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.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