mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
Drop support for Swift 6.0 and 6.1
This allows the use of Span types without `#if compiler` guards.
This commit is contained in:
145 files changed
+342
-1047
No files matched your search
@@ -11,8 +11,6 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if compiler(>=6.2)
|
||||
|
||||
/// Represents memory containing a header value followed by some extra padding
|
||||
/// following it. Values of this type own the underlying memory, and are
|
||||
/// non-copyable to ensure that ownership of that memory is unique. Memory
|
||||
@@ -33,7 +31,7 @@ public struct TrailingPadding<Header: ~Copyable>: ~Copyable {
|
||||
/// Pointer to the header, followed by the padding.
|
||||
@usableFromInline
|
||||
let _pointer: UnsafeMutablePointer<Header>
|
||||
|
||||
|
||||
/// Create a new instance with the given header and total size. The total
|
||||
/// size includes the storage for the header itself, so it must be at least
|
||||
/// as large as the header.
|
||||
@@ -46,7 +44,7 @@ public struct TrailingPadding<Header: ~Copyable>: ~Copyable {
|
||||
.assumingMemoryBound(to: Header.self)
|
||||
_pointer.initialize(to: header)
|
||||
}
|
||||
|
||||
|
||||
/// Take ownership over a pointer to memory containing the header followed
|
||||
/// by the trailing elements.
|
||||
///
|
||||
@@ -56,26 +54,26 @@ public struct TrailingPadding<Header: ~Copyable>: ~Copyable {
|
||||
public init(consuming pointer: UnsafeMutablePointer<Header>) {
|
||||
self._pointer = pointer
|
||||
}
|
||||
|
||||
|
||||
/// Deinitializes the header, then deallocates the underlying memory.
|
||||
@_alwaysEmitIntoClient
|
||||
deinit {
|
||||
_pointer.deinitialize(count: 1)
|
||||
_pointer.deallocate()
|
||||
}
|
||||
|
||||
|
||||
/// Access the header portion of the value.
|
||||
@_alwaysEmitIntoClient
|
||||
public var header: Header {
|
||||
unsafeAddress {
|
||||
UnsafePointer(_pointer)
|
||||
}
|
||||
|
||||
|
||||
unsafeMutableAddress {
|
||||
_pointer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Executes the given closure with the pointer to the header itself.
|
||||
@_alwaysEmitIntoClient
|
||||
public func withUnsafeMutablePointerToHeader<R: ~Copyable, E>(
|
||||
@@ -83,7 +81,7 @@ public struct TrailingPadding<Header: ~Copyable>: ~Copyable {
|
||||
) throws(E) -> R {
|
||||
return try body(_pointer)
|
||||
}
|
||||
|
||||
|
||||
/// Take ownership over the stored memory, returning its pointer. The
|
||||
/// underlying storage will not be freed by the `TrailingPadding` instance,
|
||||
/// as it is the responsibility of the caller.
|
||||
@@ -112,7 +110,7 @@ extension TrailingPadding where Header: Copyable {
|
||||
) throws(E) -> R {
|
||||
precondition(size >= MemoryLayout<Header>.size,
|
||||
"must allocate enough storage for the underlying stored type")
|
||||
|
||||
|
||||
// Allocate temporary storage large enough for the value we need.
|
||||
let result: Result<R, E> = withUnsafeTemporaryAllocation(
|
||||
byteCount: size,
|
||||
@@ -122,26 +120,24 @@ extension TrailingPadding where Header: Copyable {
|
||||
let pointer = buffer.baseAddress!.assumingMemoryBound(to: Header.self)
|
||||
pointer.initialize(to: header)
|
||||
var tailAllocated = TrailingPadding(consuming: pointer)
|
||||
|
||||
|
||||
do throws(E) {
|
||||
let result = try body(&tailAllocated)
|
||||
|
||||
|
||||
// Tell the tail-allocated buffer not to free the storage.
|
||||
let finalPointer = tailAllocated.leakStorage()
|
||||
precondition(finalPointer == pointer)
|
||||
|
||||
|
||||
return .success(result)
|
||||
} catch {
|
||||
// Tell the tail-allocated buffer not to free the storage.
|
||||
let finalPointer = tailAllocated.leakStorage()
|
||||
precondition(finalPointer == pointer)
|
||||
|
||||
|
||||
return .failure(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return try result.get()
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user