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