Skip to content

Commit

Permalink
merge conflict resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
glessard committed Jan 16, 2025
1 parent c9272a2 commit 93f49a4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
79 changes: 31 additions & 48 deletions stdlib/public/core/Slab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@
//===----------------------------------------------------------------------===//

/// A fixed-size array.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@frozen
public struct Slab<let count: Int, Element: ~Copyable>: ~Copyable {
@usableFromInline
internal let _storage: Builtin.FixedArray<count, Element>
}

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab: Copyable where Element: Copyable {}

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab: BitwiseCopyable where Element: BitwiseCopyable {}

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab: @unchecked Sendable where Element: Sendable & ~Copyable {}

//===----------------------------------------------------------------------===//
// Address & Buffer
//===----------------------------------------------------------------------===//

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab where Element: ~Copyable {
/// Returns a read-only pointer to the first element in the vector.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
internal var _address: UnsafePointer<Element> {
UnsafePointer<Element>(Builtin.unprotectedAddressOfBorrow(self))
}

/// Returns a buffer pointer over the entire vector.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
internal var _buffer: UnsafeBufferPointer<Element> {
UnsafeBufferPointer<Element>(start: _address, count: count)
}

/// Returns a mutable pointer to the first element in the vector.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
internal var _mutableAddress: UnsafeMutablePointer<Element> {
Expand All @@ -60,7 +60,7 @@ extension Slab where Element: ~Copyable {
}

/// Returns a mutable buffer pointer over the entire vector.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
internal var _mutableBuffer: UnsafeMutableBufferPointer<Element> {
Expand All @@ -71,7 +71,7 @@ extension Slab where Element: ~Copyable {

/// Returns the given raw pointer, which points at an uninitialized vector
/// instance, to a mutable buffer suitable for initialization.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
internal static func _initializationBuffer(
Expand All @@ -88,7 +88,7 @@ extension Slab where Element: ~Copyable {
// Initialization APIs
//===----------------------------------------------------------------------===//

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab where Element: ~Copyable {
/// Initializes every element in this vector running the given closure value
/// that returns the element to emplace at the given index.
Expand All @@ -102,7 +102,7 @@ extension Slab where Element: ~Copyable {
///
/// - Parameter body: A closure that returns an owned `Element` to emplace at
/// the passed in index.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public init<E: Error>(_ body: (Int) throws(E) -> Element) throws(E) {
self = try Builtin.emplace { (rawPtr) throws(E) -> () in
Expand Down Expand Up @@ -141,7 +141,7 @@ extension Slab where Element: ~Copyable {
/// - Parameter next: A closure that passes in an immutable borrow reference
/// of the given first element of the vector which returns
/// an owned `Element` instance to insert into the vector.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public init<E: Error>(
first: consuming Element,
Expand Down Expand Up @@ -175,12 +175,12 @@ extension Slab where Element: ~Copyable {
}
}

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab where Element: Copyable {
/// Initializes every element in this vector to a copy of the given value.
///
/// - Parameter value: The instance to initialize this vector with.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public init(repeating value: Element) {
self = Builtin.emplace {
Expand All @@ -195,22 +195,22 @@ extension Slab where Element: Copyable {
// Collection APIs
//===----------------------------------------------------------------------===//

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab where Element: ~Copyable {
/// The type of the container's elements.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
public typealias Element = Element

/// A type that represents a position in the collection.
///
/// Valid indices consist of the position of every element and a
/// "past the end" position that's not valid for use as a subscript
/// argument.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
public typealias Index = Int

/// The number of elements in the collection.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public static var count: Int {
Expand All @@ -220,7 +220,7 @@ extension Slab where Element: ~Copyable {
/// The number of elements in the collection.
///
/// - Complexity: O(1)
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public var count: Int {
Expand All @@ -230,7 +230,7 @@ extension Slab where Element: ~Copyable {
/// The position of the first element in a nonempty collection.
///
/// If the collection is empty, `startIndex` is equal to `endIndex`.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public var startIndex: Int {
Expand All @@ -252,7 +252,7 @@ extension Slab where Element: ~Copyable {
/// // Prints "[30, 40, 50]"
///
/// If the collection is empty, `endIndex` is equal to `startIndex`.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public var endIndex: Int {
Expand All @@ -276,7 +276,7 @@ extension Slab where Element: ~Copyable {
/// i = c.index(after: i)
/// }
/// // c == MyFancyCollection([2, 4, 6, 8, 10])
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public var indices: Range<Int> {
Expand All @@ -288,7 +288,7 @@ extension Slab where Element: ~Copyable {
/// - Parameter i: A valid index of the collection. `i` must be less than
/// `endIndex`.
/// - Returns: The index immediately after `i`.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public borrowing func index(after i: Int) -> Int {
Expand All @@ -300,7 +300,7 @@ extension Slab where Element: ~Copyable {
/// - Parameter i: A valid index of the collection. `i` must be greater than
/// `startIndex`.
/// - Returns: The index value immediately before `i`.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public borrowing func index(before i: Int) -> Int {
Expand All @@ -326,7 +326,7 @@ extension Slab where Element: ~Copyable {
/// `endIndex` property.
///
/// - Complexity: O(1)
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_addressableSelf
@_alwaysEmitIntoClient
public subscript(_ i: Int) -> Element {
Expand All @@ -350,7 +350,7 @@ extension Slab where Element: ~Copyable {
// Swap
//===----------------------------------------------------------------------===//

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab where Element: ~Copyable {
/// Exchanges the values at the specified indices of the vector.
///
Expand All @@ -363,7 +363,7 @@ extension Slab where Element: ~Copyable {
/// - j: The index of the second value to swap.
///
/// - Complexity: O(1)
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public mutating func swapAt(
_ i: Int,
Expand All @@ -383,28 +383,11 @@ extension Slab where Element: ~Copyable {
}
}

//===----------------------------------------------------------------------===//
// Span
//===----------------------------------------------------------------------===//

@available(SwiftStdlib 6.1, *)
extension Slab where Element: ~Copyable {

@available(SwiftStdlib 6.1, *)
public var storage: Span<Element> {
get {
let pointer = UnsafePointer<Element>(Builtin.addressOfBorrow(self))
let span = Span(_unsafeStart: pointer, count: count)
return _overrideLifetime(span, borrowing: self)
}
}
}

//===----------------------------------------------------------------------===//
// Unsafe APIs
//===----------------------------------------------------------------------===//

@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
extension Slab where Element: ~Copyable {
/// Calls a closure with a pointer to the vector's contiguous storage.
///
Expand Down Expand Up @@ -439,7 +422,7 @@ extension Slab where Element: ~Copyable {
/// `withUnsafeBufferPointer(_:)` method. The pointer argument is valid only
/// for the duration of the method's execution.
/// - Returns: The return value, if any, of the `body` closure parameter.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public borrowing func _withUnsafeBufferPointer<Result: ~Copyable, E: Error>(
Expand Down Expand Up @@ -488,7 +471,7 @@ extension Slab where Element: ~Copyable {
/// for the `withUnsafeMutableBufferPointer(_:)` method. The pointer
/// argument is valid only for the duration of the method's execution.
/// - Returns: The return value, if any, of the `body` closure parameter.
@available(SwiftStdlib 6.1, *)
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
@_transparent
public mutating func _withUnsafeMutableBufferPointer<Result: ~Copyable, E: Error>(
Expand Down
13 changes: 13 additions & 0 deletions stdlib/public/core/Span/Properties/InlineTypeExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,16 @@ extension SIMD64 {
}
}
}

@available(SwiftStdlib 6.2, *)
extension Slab where Element: ~Copyable {

@available(SwiftStdlib 6.2, *)
public var storage: Span<Element> {
get {
let pointer = UnsafePointer<Element>(Builtin.addressOfBorrow(self))
let span = Span(_unsafeStart: pointer, count: count)
return _overrideLifetime(span, borrowing: self)
}
}
}
2 changes: 2 additions & 0 deletions utils/availability-macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.1
SwiftStdlib 6.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0
SwiftStdlib 6.1:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999
SwiftStdlib 6.2:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999
# TODO: When you add a new version, remember to tell the compiler about it
# by also adding it to include/swift/AST/RuntimeVersions.def.

# Local Variables:
# mode: conf-unix
Expand Down

0 comments on commit 93f49a4

Please sign in to comment.