diff --git a/stdlib/public/core/UnsafeBufferPointer.swift.gyb b/stdlib/public/core/UnsafeBufferPointer.swift.gyb index 94897c6afd15b..e552db2438004 100644 --- a/stdlib/public/core/UnsafeBufferPointer.swift.gyb +++ b/stdlib/public/core/UnsafeBufferPointer.swift.gyb @@ -583,6 +583,18 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable { return unsafe _overrideLifetime(span, borrowing: self) } } +%if Mutable: + + @unsafe + @available(SwiftStdlib 6.2, *) + public var mutableSpan: MutableSpan { + @lifetime(borrow self) + @_alwaysEmitIntoClient + get { + unsafe MutableSpan(_unsafeElements: self) + } + } +%end } extension Unsafe${Mutable}BufferPointer { diff --git a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb index 2ee50c1b77af2..c9aba12ce1113 100644 --- a/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb +++ b/stdlib/public/core/UnsafeRawBufferPointer.swift.gyb @@ -1162,6 +1162,16 @@ extension Unsafe${Mutable}RawBufferPointer { } } + @unsafe + @available(SwiftStdlib 6.2, *) + public var mutableBytes: MutableRawSpan { + @lifetime(borrow self) + @_alwaysEmitIntoClient + get { + unsafe MutableRawSpan(_unsafeBytes: self) + } + } + % end @_alwaysEmitIntoClient public func withContiguousStorageIfAvailable( diff --git a/test/abi/macOS/arm64/stdlib.swift b/test/abi/macOS/arm64/stdlib.swift index 4850646c74890..c90a3038778e4 100644 --- a/test/abi/macOS/arm64/stdlib.swift +++ b/test/abi/macOS/arm64/stdlib.swift @@ -933,6 +933,8 @@ Added: _$ss10ArraySliceV11mutableSpans07MutableD0VyxGvr Added: _$ss15ContiguousArrayV11mutableSpans07MutableD0VyxGvr Added: _$ss11InlineArrayVsRi__rlE11mutableSpans07MutableD0Vyq_Gvr Added: _$ss15CollectionOfOneV11mutableSpans07MutableE0VyxGvr +Added: _$sSrsRi_zrlE11mutableSpans07MutableB0VyxGvr +Added: _$sSw12mutableBytess14MutableRawSpanVvr // _SwiftifyInfo enum for _SwiftifyImports macro Added: _$ss13_SwiftifyExprO5paramyABSicABmFWC diff --git a/test/abi/macOS/x86_64/stdlib.swift b/test/abi/macOS/x86_64/stdlib.swift index dca1157ee9a5b..7319c348e4db4 100644 --- a/test/abi/macOS/x86_64/stdlib.swift +++ b/test/abi/macOS/x86_64/stdlib.swift @@ -934,6 +934,8 @@ Added: _$ss10ArraySliceV11mutableSpans07MutableD0VyxGvr Added: _$ss15ContiguousArrayV11mutableSpans07MutableD0VyxGvr Added: _$ss11InlineArrayVsRi__rlE11mutableSpans07MutableD0Vyq_Gvr Added: _$ss15CollectionOfOneV11mutableSpans07MutableE0VyxGvr +Added: _$sSrsRi_zrlE11mutableSpans07MutableB0VyxGvr +Added: _$sSw12mutableBytess14MutableRawSpanVvr // _SwiftifyInfo enum for _SwiftifyImports macro Added: _$ss13_SwiftifyExprO5paramyABSicABmFWC diff --git a/test/stdlib/Span/MutableRawSpanTests.swift b/test/stdlib/Span/MutableRawSpanTests.swift index e64558bd0ef3b..993977e6bcd33 100644 --- a/test/stdlib/Span/MutableRawSpanTests.swift +++ b/test/stdlib/Span/MutableRawSpanTests.swift @@ -514,3 +514,26 @@ suite.test("extracting suffixes") expectEqual(span.extracting(droppingFirst: 1).byteCount, b.count) } } + +suite.test("MutableRawSpan from UnsafeMutableRawBufferPointer") +.require(.stdlib_6_2).code { + guard #available(SwiftStdlib 6.2, *) else { return } + + let capacity = 4 + let b = UnsafeMutableRawBufferPointer.allocate( + byteCount: capacity*MemoryLayout.stride, + alignment: MemoryLayout.alignment + ) + defer { + b.deallocate() + } + _ = b.initializeMemory(as: Int64.self, fromContentsOf: 0...allocate(capacity: capacity) + defer { + b.deallocate() + } + _ = b.initialize(fromContentsOf: 0..