mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[stdlib] add OutputSpan to backdeployment library
This commit is contained in:
@@ -10,11 +10,16 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if SPAN_COMPATIBILITY_STUB
|
||||
import Swift
|
||||
#endif
|
||||
|
||||
// OutputRawSpan is a reference to a contiguous region of memory which starts
|
||||
// some number of initialized bytes, followed by uninitialized memory.
|
||||
@safe
|
||||
@frozen
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
public struct OutputRawSpan: ~Copyable, ~Escapable {
|
||||
@usableFromInline
|
||||
internal let _pointer: UnsafeMutableRawPointer?
|
||||
@@ -34,10 +39,12 @@ public struct OutputRawSpan: ~Copyable, ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan: @unchecked Sendable {}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@@ -55,7 +62,8 @@ extension OutputRawSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
/// The number of initialized bytes in this span.
|
||||
@_alwaysEmitIntoClient
|
||||
@@ -74,7 +82,8 @@ extension OutputRawSpan {
|
||||
public var isFull: Bool { _count == capacity }
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
|
||||
@unsafe
|
||||
@@ -148,7 +157,8 @@ extension OutputRawSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
|
||||
/// Append a single byte to this span.
|
||||
@@ -193,7 +203,8 @@ extension OutputRawSpan {
|
||||
}
|
||||
|
||||
//MARK: bulk-append functions
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
/// Appends the given value's bytes to this span's bytes.
|
||||
@_alwaysEmitIntoClient
|
||||
@@ -221,7 +232,8 @@ extension OutputRawSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
/// Borrow the underlying initialized memory for read-only access.
|
||||
@_alwaysEmitIntoClient
|
||||
@@ -248,7 +260,8 @@ extension OutputRawSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
|
||||
/// Call the given closure with the unsafe buffer pointer addressed by this
|
||||
@@ -288,9 +301,15 @@ extension OutputRawSpan {
|
||||
}
|
||||
return unsafe try body(buffer, &initializedCount)
|
||||
}
|
||||
#if SPAN_COMPATIBILITY_STUB
|
||||
let buffer = unsafe UnsafeMutableRawBufferPointer(
|
||||
start: start, count: capacity
|
||||
)
|
||||
#else
|
||||
let buffer = unsafe UnsafeMutableRawBufferPointer(
|
||||
_uncheckedStart: start, count: capacity
|
||||
)
|
||||
#endif
|
||||
var initializedCount = _count
|
||||
defer {
|
||||
_precondition(
|
||||
@@ -303,7 +322,8 @@ extension OutputRawSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputRawSpan {
|
||||
/// Consume the output span (relinquishing its control over the buffer it is
|
||||
/// addressing), and return the number of initialized bytes in it.
|
||||
|
||||
@@ -10,13 +10,18 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if SPAN_COMPATIBILITY_STUB
|
||||
import Swift
|
||||
#endif
|
||||
|
||||
// `OutputSpan` is a reference to a contiguous region of memory that starts with
|
||||
// some number of initialized `Element` instances followed by uninitialized
|
||||
// memory. It provides operations to access the items it stores, as well as to
|
||||
// add new elements and to remove existing ones.
|
||||
@safe
|
||||
@frozen
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
public struct OutputSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
|
||||
@usableFromInline
|
||||
internal let _pointer: UnsafeMutableRawPointer?
|
||||
@@ -49,10 +54,12 @@ public struct OutputSpan<Element: ~Copyable>: ~Copyable, ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan: @unchecked Sendable where Element: Sendable & ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@@ -70,7 +77,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
/// The number of initialized elements in this span.
|
||||
@_alwaysEmitIntoClient
|
||||
@@ -89,7 +97,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
public var isFull: Bool { _count == capacity }
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
|
||||
@unsafe
|
||||
@@ -141,7 +150,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan {
|
||||
|
||||
/// Unsafely create an OutputSpan over partly-initialized memory.
|
||||
@@ -171,7 +181,8 @@ extension OutputSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
/// The type that represents an initialized position in an `OutputSpan`.
|
||||
public typealias Index = Int
|
||||
@@ -259,7 +270,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
/// Append a single element to this span.
|
||||
@_alwaysEmitIntoClient
|
||||
@@ -311,7 +323,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
|
||||
//MARK: bulk-append functions
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan {
|
||||
|
||||
/// Repeatedly append an element to this span.
|
||||
@@ -326,7 +339,8 @@ extension OutputSpan {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
/// Borrow the underlying initialized memory for read-only access.
|
||||
@_alwaysEmitIntoClient
|
||||
@@ -355,7 +369,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
/// Call the given closure with the unsafe buffer pointer addressed by this
|
||||
/// OutputSpan and a mutable reference to its count of initialized elements.
|
||||
@@ -399,9 +414,15 @@ extension OutputSpan where Element: ~Copyable {
|
||||
start._rawValue, capacity._builtinWordValue, Element.self
|
||||
)
|
||||
defer { Builtin.rebindMemory(start._rawValue, binding) }
|
||||
#if SPAN_COMPATIBILITY_STUB
|
||||
let buffer = unsafe UnsafeMutableBufferPointer<Element>(
|
||||
start: .init(start._rawValue), count: capacity
|
||||
)
|
||||
#else
|
||||
let buffer = unsafe UnsafeMutableBufferPointer<Element>(
|
||||
_uncheckedStart: .init(start._rawValue), count: capacity
|
||||
)
|
||||
#endif
|
||||
var initializedCount = self._count
|
||||
defer {
|
||||
_precondition(
|
||||
@@ -414,7 +435,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan where Element: ~Copyable {
|
||||
/// Consume the output span and return the number of initialized elements.
|
||||
///
|
||||
@@ -447,7 +469,8 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@_originallyDefinedIn(module: "Swift;CompatibilitySpan", SwiftCompatibilitySpan 6.2)
|
||||
extension OutputSpan {
|
||||
/// Consume the output span and return the number of initialized elements.
|
||||
///
|
||||
|
||||
@@ -6,6 +6,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND DEFINED SWIFT_STDLIB_LIBRARY_BUILD_TY
|
||||
FakeStdlib.swift
|
||||
../../public/core/Span/MutableRawSpan.swift
|
||||
../../public/core/Span/MutableSpan.swift
|
||||
../../public/core/Span/OutputRawSpan.swift
|
||||
../../public/core/Span/OutputSpan.swift
|
||||
../../public/core/Span/RawSpan.swift
|
||||
../../public/core/Span/Span.swift
|
||||
|
||||
|
||||
@@ -1065,6 +1065,21 @@ Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14M
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVN$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivM$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivs$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8_pointerSvSgvg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8capacitySivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivM$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivs$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8_pointerSvSgvg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8capacitySivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVN$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVsRi_zrlE6_countSivg$
|
||||
|
||||
@@ -1065,6 +1065,21 @@ Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14M
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss14MutableRawSpanVN$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivM$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE6_countSivs$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8_pointerSvSgvg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss10OutputSpanVsRi_zrlE8capacitySivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivM$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV6_countSivs$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8_pointerSvSgvg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanV8capacitySivg$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss13OutputRawSpanVN$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMa$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVMn$
|
||||
Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$26.0$_$ss4SpanVsRi_zrlE6_countSivg$
|
||||
|
||||
Reference in New Issue
Block a user