diff --git a/Package.swift b/Package.swift index 21754b2c..93325e1d 100644 --- a/Package.swift +++ b/Package.swift @@ -244,7 +244,7 @@ let targets: [CustomTarget] = [ .target( kind: .exported, name: "DequeModule", - dependencies: ["InternalCollectionsUtilities"], + dependencies: ["InternalCollectionsUtilities", "Future"], exclude: ["CMakeLists.txt"]), .target( kind: .test, diff --git a/Sources/DequeModule/CMakeLists.txt b/Sources/DequeModule/CMakeLists.txt index 07364b66..f85a23d0 100644 --- a/Sources/DequeModule/CMakeLists.txt +++ b/Sources/DequeModule/CMakeLists.txt @@ -14,7 +14,8 @@ else() add_library(DequeModule ${COLLECTIONS_DEQUE_SOURCES}) target_link_libraries(DequeModule PRIVATE - InternalCollectionsUtilities) + InternalCollectionsUtilities + Future) set_target_properties(DequeModule PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) @@ -31,13 +32,12 @@ target_sources(${module_name} PRIVATE "Deque+ExpressibleByArrayLiteral.swift" "Deque+Extras.swift" "Deque+Hashable.swift" - "Deque+Sendable.swift" "Deque+Testing.swift" "Deque._Storage.swift" - "Deque._UnsafeHandle.swift" "Deque.swift" - "_DequeBuffer.swift" - "_DequeBufferHeader.swift" + "DynamicDeque.swift" + "RigidDeque.swift" "_DequeSlot.swift" + "_UnsafeDequeHandle.swift" "_UnsafeWrappedBuffer.swift" ) diff --git a/Sources/DequeModule/Deque+Codable.swift b/Sources/DequeModule/Deque+Codable.swift index abef341e..7e9e8d57 100644 --- a/Sources/DequeModule/Deque+Codable.swift +++ b/Sources/DequeModule/Deque+Codable.swift @@ -35,11 +35,12 @@ extension Deque: Decodable where Element: Decodable { /// - Parameter decoder: The decoder to read data from. @inlinable public init(from decoder: Decoder) throws { - self.init() var container = try decoder.unkeyedContainer() if let count = container.count { - self.reserveCapacity(count) + self.init(minimumCapacity: count) + } else { + self.init() } while !container.isAtEnd { let element = try container.decode(Element.self) diff --git a/Sources/DequeModule/Deque+Collection.swift b/Sources/DequeModule/Deque+Collection.swift index b56772cb..ef528253 100644 --- a/Sources/DequeModule/Deque+Collection.swift +++ b/Sources/DequeModule/Deque+Collection.swift @@ -23,7 +23,7 @@ extension Deque: Sequence { @frozen public struct Iterator: IteratorProtocol { @usableFromInline - internal var _storage: Deque._Storage + internal var _base: Deque @usableFromInline internal var _nextSlot: _Slot @@ -32,32 +32,32 @@ extension Deque: Sequence { internal var _endSlot: _Slot @inlinable - internal init(_storage: Deque._Storage, start: _Slot, end: _Slot) { - self._storage = _storage + internal init(_base: Deque, start: _Slot, end: _Slot) { + self._base = _base self._nextSlot = start self._endSlot = end } @inlinable internal init(_base: Deque) { - self = _base._storage.read { handle in + self = _base._read { handle in let start = handle.startSlot let end = Swift.min(start.advanced(by: handle.count), handle.limSlot) - return Self(_storage: _base._storage, start: start, end: end) + return Self(_base: _base, start: start, end: end) } } @inlinable internal init(_base: Deque, from index: Int) { - self = _base._storage.read { handle in + self = _base._read { handle in assert(index >= 0 && index <= handle.count) let start = handle.slot(forOffset: index) if index == handle.count { - return Self(_storage: _base._storage, start: start, end: start) + return Self(_base: _base, start: start, end: start) } var end = handle.endSlot if start >= end { end = handle.limSlot } - return Self(_storage: _base._storage, start: start, end: end) + return Self(_base: _base, start: start, end: end) } } @@ -65,7 +65,7 @@ extension Deque: Sequence { @inline(never) internal mutating func _swapSegment() -> Bool { assert(_nextSlot == _endSlot) - return _storage.read { handle in + return _base._read { handle in let end = handle.endSlot if end == .zero || end == _nextSlot { return false @@ -88,7 +88,7 @@ extension Deque: Sequence { assert(_nextSlot < _endSlot) let slot = _nextSlot _nextSlot = _nextSlot.advanced(by: 1) - return _storage.read { handle in + return _base._read { handle in return handle.ptr(at: slot).pointee } } @@ -104,8 +104,8 @@ extension Deque: Sequence { @inlinable public __consuming func _copyToContiguousArray() -> ContiguousArray { - ContiguousArray(unsafeUninitializedCapacity: _storage.count) { target, count in - _storage.read { source in + ContiguousArray(unsafeUninitializedCapacity: count) { target, count in + _read { source in let segments = source.segments() let c = segments.first.count target[.. ) -> (Iterator, UnsafeMutableBufferPointer.Index) { - _storage.read { source in + _read { source in let segments = source.segments() let c1 = Swift.min(segments.first.count, target.count) target[..( _ body: (UnsafeBufferPointer) throws -> R ) rethrows -> R? { - return try _storage.read { handle in + return try _read { handle in + guard handle.count > 0 else { return nil } let endSlot = handle.startSlot.advanced(by: handle.count) guard endSlot.position <= handle.capacity else { return nil } return try body(handle.buffer(for: handle.startSlot ..< endSlot)) @@ -176,7 +177,7 @@ extension Deque: RandomAccessCollection { /// - Complexity: O(1) @inlinable @inline(__always) - public var count: Int { _storage.count } + public var count: Int { _storage._value.count } /// The position of the first element in a nonempty deque. /// @@ -355,14 +356,14 @@ extension Deque: RandomAccessCollection { public subscript(index: Int) -> Element { get { precondition(index >= 0 && index < count, "Index out of bounds") - return _storage.read { $0.ptr(at: $0.slot(forOffset: index)).pointee } + return _read { $0.ptr(at: $0.slot(forOffset: index)).pointee } } set { precondition(index >= 0 && index < count, "Index out of bounds") - _storage.ensureUnique() - _storage.update { handle in + _ensureUnique() + _update { handle in let slot = handle.slot(forOffset: index) - handle.ptr(at: slot).pointee = newValue + handle.mutablePtr(at: slot).pointee = newValue } } @inline(__always) // https://github.com/apple/swift-collections/issues/164 @@ -378,20 +379,20 @@ extension Deque: RandomAccessCollection { @inlinable internal mutating func _prepareForModify(at index: Int) -> (_Slot, Element) { - _storage.ensureUnique() + _ensureUnique() // We technically aren't supposed to escape storage pointers out of a // managed buffer, so we escape a `(slot, value)` pair instead, leaving // the corresponding slot temporarily uninitialized. - return _storage.update { handle in + return _update { handle in let slot = handle.slot(forOffset: index) - return (slot, handle.ptr(at: slot).move()) + return (slot, handle.mutablePtr(at: slot).move()) } } @inlinable internal mutating func _finalizeModify(_ slot: _Slot, _ value: Element) { - _storage.update { handle in - handle.ptr(at: slot).initialize(to: value) + _update { handle in + handle.mutablePtr(at: slot).initialize(to: value) } } @@ -434,8 +435,8 @@ extension Deque: MutableCollection { public mutating func swapAt(_ i: Int, _ j: Int) { precondition(i >= 0 && i < count, "Index out of bounds") precondition(j >= 0 && j < count, "Index out of bounds") - _storage.ensureUnique() - _storage.update { handle in + _ensureUnique() + _update { handle in let slot1 = handle.slot(forOffset: i) let slot2 = handle.slot(forOffset: j) handle.mutableBuffer.swapAt(slot1.position, slot2.position) @@ -466,8 +467,8 @@ extension Deque: MutableCollection { public mutating func withContiguousMutableStorageIfAvailable( _ body: (inout UnsafeMutableBufferPointer) throws -> R ) rethrows -> R? { - _storage.ensureUnique() - return try _storage.update { handle in + _ensureUnique() + return try _update { handle in let endSlot = handle.startSlot.advanced(by: handle.count) guard endSlot.position <= handle.capacity else { // FIXME: Rotate storage such that it becomes contiguous. @@ -506,7 +507,8 @@ extension Deque: RangeReplaceableCollection { /// - Complexity: O(1) @inlinable public init() { - _storage = _Storage() + // FIXME: Can we do empty singletons in this world? Should _storage become optional? + _storage = _Storage(capacity: 0) } /// Reserves enough space to store the specified number of elements. @@ -522,7 +524,7 @@ extension Deque: RangeReplaceableCollection { /// - Complexity: O(`count`) @inlinable public mutating func reserveCapacity(_ minimumCapacity: Int) { - _storage.ensureUnique(minimumCapacity: minimumCapacity, linearGrowth: true) + _ensureUnique(minimumCapacity: minimumCapacity, linearGrowth: true) } /// Replaces a range of elements with the elements in the specified @@ -552,13 +554,13 @@ extension Deque: RangeReplaceableCollection { let removalCount = subrange.count let insertionCount = newElements.count let deltaCount = insertionCount - removalCount - _storage.ensureUnique(minimumCapacity: count + deltaCount) let replacementCount = Swift.min(removalCount, insertionCount) let targetCut = subrange.lowerBound + replacementCount let sourceCut = newElements.index(newElements.startIndex, offsetBy: replacementCount) - _storage.update { target in + _ensureUnique(minimumCapacity: count + deltaCount) + _update { target in target.uncheckedReplaceInPlace( inOffsets: subrange.lowerBound ..< targetCut, with: newElements[..= 0) self.init(minimumCapacity: count) - _storage.update { handle in + _update { handle in assert(handle.startSlot == .zero) if count > 0 { - handle.ptr(at: .zero).initialize(repeating: repeatedValue, count: count) + handle.mutablePtr(at: .zero).initialize( + repeating: repeatedValue, count: count) } handle.count = count } @@ -605,7 +608,7 @@ extension Deque: RangeReplaceableCollection { /// - Complexity: O(*n*), where *n* is the number of elements in the sequence. @inlinable public init(_ elements: some Sequence) { - self.init() + self.init(minimumCapacity: elements.underestimatedCount) self.append(contentsOf: elements) } @@ -618,9 +621,9 @@ extension Deque: RangeReplaceableCollection { @inlinable public init(_ elements: some Collection) { let c = elements.count - guard c > 0 else { _storage = _Storage(); return } - self._storage = _Storage(minimumCapacity: c) - _storage.update { handle in + guard c > 0 else { self.init(); return } + self.init(minimumCapacity: c) + _update { handle in assert(handle.startSlot == .zero) let target = handle.mutableBuffer(for: .zero ..< _Slot(at: c)) let done: Void? = elements.withContiguousStorageIfAvailable { source in @@ -658,8 +661,8 @@ extension Deque: RangeReplaceableCollection { /// - SeeAlso: `prepend(_:)` @inlinable public mutating func append(_ newElement: Element) { - _storage.ensureUnique(minimumCapacity: count + 1) - _storage.update { + _ensureUnique(minimumCapacity: count + 1) + _update { $0.uncheckedAppend(newElement) } } @@ -681,24 +684,24 @@ extension Deque: RangeReplaceableCollection { @inlinable public mutating func append(contentsOf newElements: some Sequence) { let done: Void? = newElements.withContiguousStorageIfAvailable { source in - _storage.ensureUnique(minimumCapacity: count + source.count) - _storage.update { $0.uncheckedAppend(contentsOf: source) } + _ensureUnique(minimumCapacity: count + source.count) + _update { $0.uncheckedAppend(contentsOf: source) } } if done != nil { return } let underestimatedCount = newElements.underestimatedCount - _storage.ensureUnique(minimumCapacity: count + underestimatedCount) - var it = _storage.update { target in + _ensureUnique(minimumCapacity: count + underestimatedCount) + var it = _update { target in let gaps = target.availableSegments() let (it, copied) = gaps.initialize(fromSequencePrefix: newElements) target.count += copied return it } while let next = it.next() { - _storage.ensureUnique(minimumCapacity: count + 1) - _storage.update { target in + _ensureUnique(minimumCapacity: count + 1) + _update { target in target.uncheckedAppend(next) let gaps = target.availableSegments() target.count += gaps.initialize(fromPrefixOf: &it) @@ -725,15 +728,15 @@ extension Deque: RangeReplaceableCollection { contentsOf newElements: some Collection ) { let done: Void? = newElements.withContiguousStorageIfAvailable { source in - _storage.ensureUnique(minimumCapacity: count + source.count) - _storage.update { $0.uncheckedAppend(contentsOf: source) } + _ensureUnique(minimumCapacity: count + source.count) + _update { $0.uncheckedAppend(contentsOf: source) } } guard done == nil else { return } let c = newElements.count guard c > 0 else { return } - _storage.ensureUnique(minimumCapacity: count + c) - _storage.update { target in + _ensureUnique(minimumCapacity: count + c) + _update { target in let gaps = target.availableSegments().prefix(c) gaps.initialize(from: newElements) target.count += c @@ -759,19 +762,9 @@ extension Deque: RangeReplaceableCollection { public mutating func insert(_ newElement: Element, at index: Int) { precondition(index >= 0 && index <= count, "Can't insert element at invalid index") - _storage.ensureUnique(minimumCapacity: count + 1) - _storage.update { target in - if index == 0 { - target.uncheckedPrepend(newElement) - return - } - if index == count { - target.uncheckedAppend(newElement) - return - } - let gap = target.openGap(ofSize: 1, atOffset: index) - assert(gap.first.count == 1) - gap.first.baseAddress!.initialize(to: newElement) + _ensureUnique(minimumCapacity: count + 1) + _update { target in + target.uncheckedInsert(newElement, at: index) } } @@ -800,8 +793,8 @@ extension Deque: RangeReplaceableCollection { precondition(index >= 0 && index <= count, "Can't insert elements at an invalid index") let newCount = newElements.count - _storage.ensureUnique(minimumCapacity: count + newCount) - _storage.update { target in + _ensureUnique(minimumCapacity: count + newCount) + _update { target in target.uncheckedInsert(contentsOf: newElements, count: newCount, atOffset: index) } } @@ -826,11 +819,10 @@ extension Deque: RangeReplaceableCollection { public mutating func remove(at index: Int) -> Element { precondition(index >= 0 && index < self.count, "Index out of bounds") // FIXME: Implement storage shrinking - _storage.ensureUnique() - return _storage.update { target in - // FIXME: Add direct implementation & see if it makes a difference - let result = self[index] - target.uncheckedRemove(offsets: index ..< index + 1) + _ensureUnique() + return _update { target in + let result = target.mutablePtr(at: target.slot(forOffset: index)).move() + target.closeGap(offsets: index ..< index + 1) return result } } @@ -852,23 +844,23 @@ extension Deque: RangeReplaceableCollection { public mutating func removeSubrange(_ bounds: Range) { precondition(bounds.lowerBound >= 0 && bounds.upperBound <= self.count, "Index range out of bounds") - _storage.ensureUnique() - _storage.update { $0.uncheckedRemove(offsets: bounds) } + _ensureUnique() + _update { $0.uncheckedRemove(offsets: bounds) } } @inlinable public mutating func _customRemoveLast() -> Element? { precondition(!isEmpty, "Cannot remove last element of an empty Deque") - _storage.ensureUnique() - return _storage.update { $0.uncheckedRemoveLast() } + _ensureUnique() + return _update { $0.uncheckedRemoveLast() } } @inlinable public mutating func _customRemoveLast(_ n: Int) -> Bool { precondition(n >= 0, "Can't remove a negative number of elements") precondition(n <= count, "Can't remove more elements than there are in the Collection") - _storage.ensureUnique() - _storage.update { $0.uncheckedRemoveLast(n) } + _ensureUnique() + _update { $0.uncheckedRemoveLast(n) } return true } @@ -884,8 +876,8 @@ extension Deque: RangeReplaceableCollection { @discardableResult public mutating func removeFirst() -> Element { precondition(!isEmpty, "Cannot remove first element of an empty Deque") - _storage.ensureUnique() - return _storage.update { $0.uncheckedRemoveFirst() } + _ensureUnique() + return _update { $0.uncheckedRemoveFirst() } } /// Removes the specified number of elements from the beginning of the deque. @@ -900,8 +892,8 @@ extension Deque: RangeReplaceableCollection { public mutating func removeFirst(_ n: Int) { precondition(n >= 0, "Can't remove a negative number of elements") precondition(n <= count, "Can't remove more elements than there are in the Collection") - _storage.ensureUnique() - return _storage.update { $0.uncheckedRemoveFirst(n) } + _ensureUnique() + return _update { $0.uncheckedRemoveFirst(n) } } /// Removes all elements from the deque. @@ -913,8 +905,8 @@ extension Deque: RangeReplaceableCollection { @inlinable public mutating func removeAll(keepingCapacity keepCapacity: Bool = false) { if keepCapacity { - _storage.ensureUnique() - _storage.update { $0.uncheckedRemoveAll() } + _ensureUnique() + _update { $0.uncheckedRemoveAll() } } else { self = Deque() } diff --git a/Sources/DequeModule/Deque+Equatable.swift b/Sources/DequeModule/Deque+Equatable.swift index 4a068d7f..6906b9d7 100644 --- a/Sources/DequeModule/Deque+Equatable.swift +++ b/Sources/DequeModule/Deque+Equatable.swift @@ -23,7 +23,7 @@ extension Deque: Equatable where Element: Equatable { } // Test referential equality. - if lhsCount == 0 || left._storage.isIdentical(to: right._storage) { + if lhsCount == 0 || left._isIdentical(to: right) { return true } diff --git a/Sources/DequeModule/Deque+Extras.swift b/Sources/DequeModule/Deque+Extras.swift index 850e493f..28d5abec 100644 --- a/Sources/DequeModule/Deque+Extras.swift +++ b/Sources/DequeModule/Deque+Extras.swift @@ -45,8 +45,8 @@ extension Deque { initializingWith initializer: (inout UnsafeMutableBufferPointer, inout Int) throws -> Void ) rethrows { - self._storage = .init(minimumCapacity: capacity) - try _storage.update { handle in + self._storage = .init(capacity: capacity) + try _update { handle in handle.startSlot = .zero var count = 0 var buffer = handle.mutableBuffer(for: .zero ..< _Slot(at: capacity)) @@ -76,8 +76,8 @@ extension Deque { // FIXME: Add this to the stdlib on BidirectionalCollection // where Self == Self.SubSequence guard count > 0 else { return nil } - _storage.ensureUnique() - return _storage.update { + _ensureUnique() + return _update { $0.uncheckedRemoveFirst() } } @@ -111,8 +111,8 @@ extension Deque { /// - SeeAlso: `append(_:)` @inlinable public mutating func prepend(_ newElement: Element) { - _storage.ensureUnique(minimumCapacity: count + 1) - return _storage.update { + _ensureUnique(minimumCapacity: count + 1) + return _update { $0.uncheckedPrepend(newElement) } } @@ -138,15 +138,15 @@ extension Deque { contentsOf newElements: some Collection ) { let done: Void? = newElements.withContiguousStorageIfAvailable { source in - _storage.ensureUnique(minimumCapacity: count + source.count) - _storage.update { $0.uncheckedPrepend(contentsOf: source) } + _ensureUnique(minimumCapacity: count + source.count) + _update { $0.uncheckedPrepend(contentsOf: source) } } guard done == nil else { return } let c = newElements.count guard c > 0 else { return } - _storage.ensureUnique(minimumCapacity: count + c) - _storage.update { target in + _ensureUnique(minimumCapacity: count + c) + _update { target in let gaps = target.availableSegments().suffix(c) gaps.initialize(from: newElements) target.count += c @@ -173,8 +173,8 @@ extension Deque { @inlinable public mutating func prepend(contentsOf newElements: some Sequence) { let done: Void? = newElements.withContiguousStorageIfAvailable { source in - _storage.ensureUnique(minimumCapacity: count + source.count) - _storage.update { $0.uncheckedPrepend(contentsOf: source) } + _ensureUnique(minimumCapacity: count + source.count) + _update { $0.uncheckedPrepend(contentsOf: source) } } guard done == nil else { return } @@ -182,7 +182,7 @@ extension Deque { self.append(contentsOf: newElements) let newCount = self.count let c = newCount - originalCount - _storage.update { target in + _update { target in target.startSlot = target.slot(forOffset: originalCount) target.count = target.capacity target.closeGap(offsets: c ..< c + (target.capacity - newCount)) diff --git a/Sources/DequeModule/Deque+Sendable.swift b/Sources/DequeModule/Deque+Sendable.swift deleted file mode 100644 index 882e921e..00000000 --- a/Sources/DequeModule/Deque+Sendable.swift +++ /dev/null @@ -1,12 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2022 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -extension Deque: @unchecked Sendable where Element: Sendable {} diff --git a/Sources/DequeModule/Deque+Testing.swift b/Sources/DequeModule/Deque+Testing.swift index 0136886b..bb5cf3be 100644 --- a/Sources/DequeModule/Deque+Testing.swift +++ b/Sources/DequeModule/Deque+Testing.swift @@ -65,24 +65,23 @@ extension Deque { precondition(capacity >= 0) precondition(startSlot >= 0 && (startSlot < capacity || (capacity == 0 && startSlot == 0))) precondition(contents.count <= capacity) + let startSlot = _Slot(at: startSlot) - let buffer = _DequeBuffer.create(minimumCapacity: capacity) { _ in - _DequeBufferHeader(capacity: capacity, count: contents.count, startSlot: startSlot) - } - let storage = Deque._Storage(unsafeDowncast(buffer, to: _DequeBuffer.self)) - if contents.count > 0 { + + var hd = RigidDeque(capacity: capacity) + hd._handle.count = contents.count + hd._handle.startSlot = startSlot + if hd._handle.count > 0 { contents.withUnsafeBufferPointer { source in - storage.update { target in - let segments = target.mutableSegments() - let c = segments.first.count - segments.first.initializeAll(fromContentsOf: source.prefix(c)) - if let second = segments.second { - second.initializeAll(fromContentsOf: source.dropFirst(c)) - } + let segments = hd._handle.mutableSegments() + let c = segments.first.count + segments.first.initializeAll(fromContentsOf: source.prefix(c)) + if let second = segments.second { + second.initializeAll(fromContentsOf: source.dropFirst(c)) } } } - self.init(_storage: storage) + self.init(_storage: _Storage(hd)) assert(self._capacity == capacity) assert(self._startSlot == startSlot.position) assert(self.count == contents.count) diff --git a/Sources/DequeModule/Deque._Storage.swift b/Sources/DequeModule/Deque._Storage.swift index 30780180..4c4a2648 100644 --- a/Sources/DequeModule/Deque._Storage.swift +++ b/Sources/DequeModule/Deque._Storage.swift @@ -10,19 +10,21 @@ //===----------------------------------------------------------------------===// extension Deque { - @frozen @usableFromInline - struct _Storage { + internal final class _Storage { @usableFromInline - internal typealias _Buffer = ManagedBufferPointer<_DequeBufferHeader, Element> - - @usableFromInline - internal var _buffer: _Buffer + @exclusivity(unchecked) + internal var _value: RigidDeque @inlinable @inline(__always) - internal init(_buffer: _Buffer) { - self._buffer = _buffer + internal init(_ value: consuming RigidDeque) { + self._value = value + } + + @inlinable + internal convenience init(capacity: Int) { + self.init(RigidDeque(capacity: capacity)) } } } @@ -30,197 +32,26 @@ extension Deque { extension Deque._Storage: CustomStringConvertible { @usableFromInline internal var description: String { - "Deque<\(Element.self)>._Storage\(_buffer.header)" + "Deque<\(Element.self)>._Storage\(_value._handle.description)" } } extension Deque._Storage { - @inlinable - internal init() { - self.init(_buffer: _Buffer(unsafeBufferObject: _emptyDequeStorage)) - } - - @inlinable - internal init(_ object: _DequeBuffer) { - self.init(_buffer: _Buffer(unsafeBufferObject: object)) - } - - @inlinable - internal init(minimumCapacity: Int) { - let object = _DequeBuffer.create( - minimumCapacity: minimumCapacity, - makingHeaderWith: { - #if os(OpenBSD) - let capacity = minimumCapacity - #else - let capacity = $0.capacity - #endif - return _DequeBufferHeader(capacity: capacity, count: 0, startSlot: .zero) - }) - self.init(_buffer: _Buffer(unsafeBufferObject: object)) - } -} - -extension Deque._Storage { - #if COLLECTIONS_INTERNAL_CHECKS +#if COLLECTIONS_INTERNAL_CHECKS @usableFromInline @inline(never) @_effects(releasenone) internal func _checkInvariants() { - _buffer.withUnsafeMutablePointerToHeader { $0.pointee._checkInvariants() } + _value._checkInvariants() } - #else +#else @inlinable @inline(__always) internal func _checkInvariants() {} - #endif // COLLECTIONS_INTERNAL_CHECKS +#endif // COLLECTIONS_INTERNAL_CHECKS } extension Deque._Storage { @inlinable - @inline(__always) - internal var identity: AnyObject { _buffer.buffer } - + internal var capacity: Int { _value.capacity } @inlinable - @inline(__always) - internal var capacity: Int { - _buffer.withUnsafeMutablePointerToHeader { $0.pointee.capacity } - } - - @inlinable - @inline(__always) - internal var count: Int { - _buffer.withUnsafeMutablePointerToHeader { $0.pointee.count } - } - - @inlinable - @inline(__always) - internal var startSlot: _DequeSlot { - _buffer.withUnsafeMutablePointerToHeader { $0.pointee.startSlot - } - } -} - -extension Deque._Storage { - @usableFromInline - internal typealias Index = Int - - @usableFromInline - internal typealias _UnsafeHandle = Deque._UnsafeHandle - - @inlinable - @inline(__always) - internal func read(_ body: (_UnsafeHandle) throws -> R) rethrows -> R { - try _buffer.withUnsafeMutablePointers { header, elements in - let handle = _UnsafeHandle(header: header, - elements: elements, - isMutable: false) - return try body(handle) - } - } - - @inlinable - @inline(__always) - internal func update(_ body: (_UnsafeHandle) throws -> R) rethrows -> R { - try _buffer.withUnsafeMutablePointers { header, elements in - let handle = _UnsafeHandle(header: header, - elements: elements, - isMutable: true) - return try body(handle) - } - } -} - -extension Deque._Storage { - /// Return a boolean indicating whether this storage instance is known to have - /// a single unique reference. If this method returns true, then it is safe to - /// perform in-place mutations on the deque. - @inlinable - @inline(__always) - internal mutating func isUnique() -> Bool { - _buffer.isUniqueReference() - } - - /// Ensure that this storage refers to a uniquely held buffer by copying - /// elements if necessary. - @inlinable - @inline(__always) - internal mutating func ensureUnique() { - if isUnique() { return } - self._makeUniqueCopy() - } - - @inlinable - @inline(never) - internal mutating func _makeUniqueCopy() { - self = self.read { $0.copyElements() } - } - - /// The growth factor to use to increase storage size to make place for an - /// insertion. - @inlinable - @inline(__always) - internal static var growthFactor: Double { 1.5 } - - @usableFromInline - internal func _growCapacity( - to minimumCapacity: Int, - linearly: Bool - ) -> Int { - if linearly { return Swift.max(capacity, minimumCapacity) } - return Swift.max(Int((Self.growthFactor * Double(capacity)).rounded(.up)), - minimumCapacity) - } - - /// Ensure that we have a uniquely referenced buffer with enough space to - /// store at least `minimumCapacity` elements. - /// - /// - Parameter minimumCapacity: The minimum number of elements the buffer - /// needs to be able to hold on return. - /// - /// - Parameter linearGrowth: If true, then don't use an exponential growth - /// factor when reallocating the buffer -- just allocate space for the - /// requested number of elements - @inlinable - @inline(__always) - internal mutating func ensureUnique( - minimumCapacity: Int, - linearGrowth: Bool = false - ) { - let unique = isUnique() - if _slowPath(capacity < minimumCapacity || !unique) { - _ensureUnique(isUnique: unique, minimumCapacity: minimumCapacity, linearGrowth: linearGrowth) - } - } - - @inlinable - @inline(never) - internal mutating func _ensureUnique( - isUnique: Bool, - minimumCapacity: Int, - linearGrowth: Bool - ) { - if capacity >= minimumCapacity { - assert(!isUnique) - self = self.read { $0.copyElements() } - return - } - - let minimumCapacity = _growCapacity(to: minimumCapacity, linearly: linearGrowth) - if isUnique { - self = self.update { source in - source.moveElements(minimumCapacity: minimumCapacity) - } - } else { - self = self.read { source in - source.copyElements(minimumCapacity: minimumCapacity) - } - } - } -} - -extension Deque._Storage { - @inlinable - @inline(__always) - internal func isIdentical(to other: Self) -> Bool { - self._buffer.buffer === other._buffer.buffer - } + internal var startSlot: _DequeSlot { _value._handle.startSlot } } diff --git a/Sources/DequeModule/Deque.swift b/Sources/DequeModule/Deque.swift index 9d6667a3..096dccf4 100644 --- a/Sources/DequeModule/Deque.swift +++ b/Sources/DequeModule/Deque.swift @@ -100,6 +100,128 @@ public struct Deque { /// storage buffer. @inlinable public init(minimumCapacity: Int) { - self._storage = _Storage(minimumCapacity: minimumCapacity) + self._storage = _Storage(capacity: minimumCapacity) } } + +extension Deque: @unchecked Sendable where Element: Sendable {} + +extension Deque { + @usableFromInline + internal typealias _UnsafeHandle = _UnsafeDequeHandle + + @inlinable + @inline(__always) + internal func _read( + _ body: (borrowing _UnsafeHandle) throws(E) -> R + ) throws(E) -> R { + try body(_storage._value._handle) + } + + @inlinable + @inline(__always) + internal mutating func _update( + _ body: (inout _UnsafeHandle) throws(E) -> R + ) throws(E) -> R { + defer { _fixLifetime(self) } + assert(_isUnique()) + return try body(&_storage._value._handle) + } + + /// Return a boolean indicating whether this storage instance is known to have + /// a single unique reference. If this method returns true, then it is safe to + /// perform in-place mutations on the deque. + @inlinable + internal mutating func _isUnique() -> Bool { + isKnownUniquelyReferenced(&_storage) + } + + /// Ensure that this storage refers to a uniquely held buffer by copying + /// elements if necessary. + @inlinable + @inline(__always) + internal mutating func _ensureUnique() { + if _isUnique() { return } + self = _makeUniqueCopy() + } + + /// Copy elements into a new storage instance without changing capacity or + /// layout. + @inlinable + @inline(never) + internal func _makeUniqueCopy() -> Self { + Deque(_storage: _Storage(_storage._value._copy())) + } + + @inlinable + @inline(never) + internal func _makeUniqueCopy(capacity: Int) -> Self { + Deque(_storage: _Storage(_storage._value._copy(capacity: capacity))) + } + + @usableFromInline + internal func _growCapacity( + to minimumCapacity: Int, + linearly: Bool + ) -> Int { + if linearly { + return Swift.max(_capacity, minimumCapacity) + } + let next = (3 * _capacity + 1) / 2 + return Swift.max(next, minimumCapacity) + } + + /// Ensure that we have a uniquely referenced buffer with enough space to + /// store at least `minimumCapacity` elements. + /// + /// - Parameter minimumCapacity: The minimum number of elements the buffer + /// needs to be able to hold on return. + /// + /// - Parameter linearGrowth: If true, then don't use an exponential growth + /// factor when reallocating the buffer -- just allocate space for the + /// requested number of elements + @inlinable + @inline(__always) + internal mutating func _ensureUnique( + minimumCapacity: Int, + linearGrowth: Bool = false + ) { + let unique = _isUnique() + if _slowPath(_storage.capacity < minimumCapacity || !unique) { + __ensureUnique( + isUnique: unique, + minimumCapacity: minimumCapacity, + linearGrowth: linearGrowth) + } + } + + @inlinable + @inline(never) + internal mutating func __ensureUnique( + isUnique: Bool, + minimumCapacity: Int, + linearGrowth: Bool + ) { + if _storage.capacity >= minimumCapacity { + assert(!isUnique) + self = self._makeUniqueCopy() + return + } + + let c = _growCapacity(to: minimumCapacity, linearly: linearGrowth) + if isUnique { + self._storage._value.resize(to: c) + } else { + self = self._makeUniqueCopy(capacity: c) + } + } +} + +extension Deque { + @inlinable + @inline(__always) + internal func _isIdentical(to other: Self) -> Bool { + self._storage === other._storage + } +} + diff --git a/Sources/DequeModule/DynamicDeque.swift b/Sources/DequeModule/DynamicDeque.swift new file mode 100644 index 00000000..c4ad8ef1 --- /dev/null +++ b/Sources/DequeModule/DynamicDeque.swift @@ -0,0 +1,167 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import Future +#endif + +@frozen +public struct DynamicDeque: ~Copyable { + @usableFromInline + internal var _storage: RigidDeque + + @inlinable + public init() { + _storage = .init(capacity: 0) + } + + @inlinable + public init(capacity: Int) { + _storage = .init(capacity: capacity) + } +} + +extension DynamicDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} + +extension DynamicDeque: RandomAccessContainer where Element: ~Copyable { + public typealias BorrowingIterator = RigidDeque.BorrowingIterator + public typealias Index = Int + + public func startBorrowingIteration() -> BorrowingIterator { + _storage.startBorrowingIteration() + } + + public func startBorrowingIteration(from start: Int) -> BorrowingIterator { + _storage.startBorrowingIteration(from: start) + } + + @inlinable + public var isEmpty: Bool { _storage.isEmpty } + + @inlinable + public var count: Int { _storage.count } + + @inlinable + public var startIndex: Int { _storage.startIndex } + + @inlinable + public var endIndex: Int { _storage.endIndex } + + @inlinable + public subscript(position: Int) -> Element { + @inline(__always) + _read { + yield _storage[position] + } + @inline(__always) + _modify { + yield &_storage[position] + } + } + + public func index(at position: borrowing BorrowingIterator) -> Int { + _storage.index(at: position) + } +} + +extension DynamicDeque where Element: ~Copyable { + @inlinable + internal var _capacity: Int { _storage.capacity } + + @inlinable + internal var _freeCapacity: Int { _storage.freeCapacity } + + @inlinable + internal var _isFull: Bool { _storage.isFull } + + @inlinable + internal mutating func _grow(to minimumCapacity: Int) { + guard minimumCapacity > _capacity else { return } + let c = Swift.max(minimumCapacity, 2 * _capacity) + _storage.resize(to: c) + } + + @inlinable + internal mutating func _ensureFreeCapacity(_ freeCapacity: Int) { + _grow(to: count + freeCapacity) + } +} + +extension DynamicDeque where Element: ~Copyable { + @inlinable + public mutating func append(_ newElement: consuming Element) { + _ensureFreeCapacity(1) + _storage.append(newElement) + } + + @inlinable + public mutating func prepend(_ newElement: consuming Element) { + _ensureFreeCapacity(1) + _storage.prepend(newElement) + } + + @inlinable + public mutating func insert(_ newElement: consuming Element, at index: Int) { + _ensureFreeCapacity(1) + _storage.insert(newElement, at: index) + } +} + +extension DynamicDeque where Element: ~Copyable { + @inlinable + @discardableResult + public mutating func remove(at index: Int) -> Element { + _storage.remove(at: index) + } + + @inlinable + public mutating func removeSubrange(_ bounds: Range) { + _storage.removeSubrange(bounds) + } + + @inlinable + @discardableResult + public mutating func removeFirst() -> Element { + _storage.removeFirst() + } + + @inlinable + @discardableResult + public mutating func removeLast() -> Element { + _storage.removeLast() + } + + @inlinable + public mutating func removeFirst(_ n: Int) { + _storage.removeFirst(n) + } + + @inlinable + public mutating func removeLast(_ n: Int) { + _storage.removeLast(n) + } + + @inlinable + public mutating func removeAll() { + _storage.removeAll() + } + + @inlinable + public mutating func popFirst() -> Element? { + _storage.popFirst() + } + + @inlinable + public mutating func popLast() -> Element? { + _storage.popLast() + } +} diff --git a/Sources/DequeModule/RigidDeque.swift b/Sources/DequeModule/RigidDeque.swift new file mode 100644 index 00000000..06c409d5 --- /dev/null +++ b/Sources/DequeModule/RigidDeque.swift @@ -0,0 +1,248 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +import Future +#endif + +@frozen +public struct RigidDeque: ~Copyable { + @usableFromInline + internal typealias _Slot = _DequeSlot + + @usableFromInline + internal typealias _Handle = _UnsafeDequeHandle + + @usableFromInline + var _handle: _Handle + + @inlinable + internal init(_handle: consuming _Handle) { + self._handle = _handle + } + + @inlinable + public init(capacity: Int) { + self.init(_handle: .allocate(capacity: capacity)) + } + + deinit { + _handle.dispose() + } +} + +extension RigidDeque: @unchecked Sendable where Element: Sendable & ~Copyable {} + +extension RigidDeque where Element: ~Copyable { +#if COLLECTIONS_INTERNAL_CHECKS + @usableFromInline @inline(never) @_effects(releasenone) + internal func _checkInvariants() { + _handle._checkInvariants() + } +#else + @inlinable @inline(__always) + internal func _checkInvariants() {} +#endif // COLLECTIONS_INTERNAL_CHECKS +} + +extension RigidDeque: RandomAccessContainer where Element: ~Copyable { + @frozen + public struct BorrowingIterator: BorrowingIteratorProtocol, ~Escapable { + @usableFromInline + internal let _segments: _UnsafeWrappedBuffer + + @usableFromInline + internal var _offset: Int + + @inlinable + internal init(_for handle: borrowing _Handle, startOffset: Int) { + self._segments = handle.segments() + self._offset = startOffset + } + + @inlinable + public mutating func nextChunk( + maximumCount: Int + ) -> dependsOn(scoped self) Span { + precondition(maximumCount > 0) + if _offset < _segments.first.count { + let d = Swift.min(maximumCount, _segments.first.count - _offset) + let slice = _segments.first.extracting(_offset ..< _offset + d) + _offset += d + return Span(unsafeElements: slice, owner: self) + } + guard let second = _segments.second else { + return Span(unsafeElements: UnsafeBufferPointer._empty, owner: self) + } + let o = _offset - _segments.first.count + let d = Swift.min(maximumCount, second.count - o) + let slice = second.extracting(o ..< o + d) + _offset += d + return Span(unsafeElements: slice, owner: self) + } + } + + public func startBorrowingIteration() -> BorrowingIterator { + BorrowingIterator(_for: _handle, startOffset: 0) + } + + public func startBorrowingIteration(from start: Int) -> BorrowingIterator { + BorrowingIterator(_for: _handle, startOffset: start) + } + + public typealias Index = Int + + @inlinable + public var isEmpty: Bool { _handle.count == 0 } + + @inlinable + public var count: Int { _handle.count } + + @inlinable + public var startIndex: Int { 0 } + + @inlinable + public var endIndex: Int { count } + + @inlinable + public subscript(position: Int) -> Element { + @inline(__always) + _read { + precondition(position >= 0 && position < count) + let slot = _handle.slot(forOffset: position) + yield _handle.ptr(at: slot).pointee + } + @inline(__always) + _modify { + precondition(position >= 0 && position < count) + let slot = _handle.slot(forOffset: position) + yield &_handle.mutablePtr(at: slot).pointee + } + } + + public func index(at position: borrowing BorrowingIterator) -> Int { + precondition(_handle.segments().isIdentical(to: position._segments)) + return position._offset + } +} + +extension RigidDeque where Element: ~Copyable { + @inlinable + public var capacity: Int { _handle.capacity } + + @inlinable + public var freeCapacity: Int { capacity - count } + + @inlinable + public var isFull: Bool { count == capacity } + + @inlinable + public mutating func resize(to newCapacity: Int) { + _handle.reallocate(capacity: newCapacity) + } +} + +extension RigidDeque where Element: ~Copyable { + @inlinable + public mutating func append(_ newElement: consuming Element) { + precondition(!isFull, "RigidDeque is full") + _handle.uncheckedAppend(newElement) + } + + @inlinable + public mutating func prepend(_ newElement: consuming Element) { + precondition(!isFull, "RigidDeque is full") + _handle.uncheckedPrepend(newElement) + } + + @inlinable + public mutating func insert(_ newElement: consuming Element, at index: Int) { + precondition(!isFull, "RigidDeque is full") + precondition(index >= 0 && index <= count, + "Can't insert element at invalid index") + _handle.uncheckedInsert(newElement, at: index) + } +} + +extension RigidDeque where Element: ~Copyable { + @inlinable + @discardableResult + public mutating func remove(at index: Int) -> Element { + precondition(index >= 0 && index < count, + "Can't remove element at invalid index") + return _handle.uncheckedRemove(at: index) + } + + @inlinable + public mutating func removeSubrange(_ bounds: Range) { + precondition(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index range out of bounds") + _handle.uncheckedRemove(offsets: bounds) + } + + @inlinable + @discardableResult + public mutating func removeFirst() -> Element { + precondition(!isEmpty, "Cannot remove first element of an empty RigidDeque") + return _handle.uncheckedRemoveFirst() + } + + @inlinable + @discardableResult + public mutating func removeLast() -> Element { + precondition(!isEmpty, "Cannot remove last element of an empty RigidDeque") + return _handle.uncheckedRemoveLast() + } + + @inlinable + public mutating func removeFirst(_ n: Int) { + precondition(n >= 0, "Can't remove a negative number of elements") + precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") + _handle.uncheckedRemoveFirst(n) + } + + @inlinable + public mutating func removeLast(_ n: Int) { + precondition(n >= 0, "Can't remove a negative number of elements") + precondition(n <= count, "Can't remove more elements than there are in a RigidDeque") + _handle.uncheckedRemoveLast(n) + } + + @inlinable + public mutating func removeAll() { + _handle.uncheckedRemoveAll() + } + + @inlinable + public mutating func popFirst() -> Element? { + guard !isEmpty else { return nil } + return _handle.uncheckedRemoveFirst() + } + + @inlinable + public mutating func popLast() -> Element? { + guard !isEmpty else { return nil } + return _handle.uncheckedRemoveLast() + } +} + +extension RigidDeque { + @inlinable + internal func _copy() -> Self { + RigidDeque(_handle: _handle.allocateCopy()) + } + + @inlinable + internal func _copy(capacity: Int) -> Self { + RigidDeque(_handle: _handle.allocateCopy(capacity: capacity)) + } +} diff --git a/Sources/DequeModule/_DequeBuffer.swift b/Sources/DequeModule/_DequeBuffer.swift deleted file mode 100644 index 337df1fd..00000000 --- a/Sources/DequeModule/_DequeBuffer.swift +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -@_fixed_layout -@usableFromInline -internal final class _DequeBuffer: ManagedBuffer<_DequeBufferHeader, Element> { - @inlinable - deinit { - self.withUnsafeMutablePointers { header, elements in - header.pointee._checkInvariants() - - let capacity = header.pointee.capacity - let count = header.pointee.count - let startSlot = header.pointee.startSlot - - if startSlot.position + count <= capacity { - (elements + startSlot.position).deinitialize(count: count) - } else { - let firstRegion = capacity - startSlot.position - (elements + startSlot.position).deinitialize(count: firstRegion) - elements.deinitialize(count: count - firstRegion) - } - } - } -} - -extension _DequeBuffer: CustomStringConvertible { - @usableFromInline - internal var description: String { - withUnsafeMutablePointerToHeader { "_DequeStorage<\(Element.self)>\($0.pointee)" } - } -} - -/// The type-punned empty singleton storage instance. -@usableFromInline -nonisolated(unsafe) internal let _emptyDequeStorage - = _DequeBuffer.create( - minimumCapacity: 0, - makingHeaderWith: { _ in - _DequeBufferHeader(capacity: 0, count: 0, startSlot: .init(at: 0)) - }) diff --git a/Sources/DequeModule/_DequeBufferHeader.swift b/Sources/DequeModule/_DequeBufferHeader.swift deleted file mode 100644 index c45f756d..00000000 --- a/Sources/DequeModule/_DequeBufferHeader.swift +++ /dev/null @@ -1,49 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift Collections open source project -// -// Copyright (c) 2021 - 2024 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// -//===----------------------------------------------------------------------===// - -@usableFromInline -internal struct _DequeBufferHeader { - @usableFromInline - var capacity: Int - - @usableFromInline - var count: Int - - @usableFromInline - var startSlot: _DequeSlot - - @usableFromInline - init(capacity: Int, count: Int, startSlot: _DequeSlot) { - self.capacity = capacity - self.count = count - self.startSlot = startSlot - _checkInvariants() - } - - #if COLLECTIONS_INTERNAL_CHECKS - @usableFromInline @inline(never) @_effects(releasenone) - internal func _checkInvariants() { - precondition(capacity >= 0) - precondition(count >= 0 && count <= capacity) - precondition(startSlot.position >= 0 && startSlot.position <= capacity) - } - #else - @inlinable @inline(__always) - internal func _checkInvariants() {} - #endif // COLLECTIONS_INTERNAL_CHECKS -} - -extension _DequeBufferHeader: CustomStringConvertible { - @usableFromInline - internal var description: String { - "(capacity: \(capacity), count: \(count), startSlot: \(startSlot))" - } -} diff --git a/Sources/DequeModule/_DequeSlot.swift b/Sources/DequeModule/_DequeSlot.swift index 2d281cb9..d1d8d5f4 100644 --- a/Sources/DequeModule/_DequeSlot.swift +++ b/Sources/DequeModule/_DequeSlot.swift @@ -69,4 +69,10 @@ extension Range where Bound == _DequeSlot { @inlinable @inline(__always) internal var _count: Int { upperBound.position - lowerBound.position } + + @inlinable + @inline(__always) + internal var _offsets: Range { + Range(uncheckedBounds: (lowerBound.position, upperBound.position)) + } } diff --git a/Sources/DequeModule/Deque._UnsafeHandle.swift b/Sources/DequeModule/_UnsafeDequeHandle.swift similarity index 73% rename from Sources/DequeModule/Deque._UnsafeHandle.swift rename to Sources/DequeModule/_UnsafeDequeHandle.swift index 8302b635..51722656 100644 --- a/Sources/DequeModule/Deque._UnsafeHandle.swift +++ b/Sources/DequeModule/_UnsafeDequeHandle.swift @@ -9,106 +9,123 @@ // //===----------------------------------------------------------------------===// -extension Deque { - @frozen +#if !COLLECTIONS_SINGLE_MODULE +import InternalCollectionsUtilities +#endif + +@frozen +@usableFromInline +internal struct _UnsafeDequeHandle: ~Copyable { @usableFromInline - internal struct _UnsafeHandle { - @usableFromInline - let _header: UnsafeMutablePointer<_DequeBufferHeader> - @usableFromInline - let _elements: UnsafeMutablePointer - #if DEBUG - @usableFromInline - let _isMutable: Bool - #endif + internal let _buffer: UnsafeMutableBufferPointer - @inlinable - @inline(__always) - init( - header: UnsafeMutablePointer<_DequeBufferHeader>, - elements: UnsafeMutablePointer, - isMutable: Bool - ) { - self._header = header - self._elements = elements - #if DEBUG - self._isMutable = isMutable - #endif - } - } -} + @usableFromInline + internal var count: Int + + @usableFromInline + internal var startSlot: _DequeSlot -extension Deque._UnsafeHandle { @inlinable - @inline(__always) - func assertMutable() { - #if DEBUG - assert(_isMutable) - #endif + internal static func allocate( + capacity: Int + ) -> Self { + Self( + _storage: capacity > 0 ? .allocate(capacity: capacity) : ._empty, + count: 0, + startSlot: .zero) + } + + @inlinable + internal init( + _storage: UnsafeMutableBufferPointer, + count: Int, + startSlot: _DequeSlot + ) { + self._buffer = _storage + self.count = count + self.startSlot = startSlot + } + + @inlinable + internal consuming func dispose() { + _checkInvariants() + self.mutableSegments().deinitialize() + _buffer.deallocate() } } -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { + @inlinable @inline(__always) + internal var _baseAddress: UnsafeMutablePointer { + _buffer.baseAddress.unsafelyUnwrapped + } + + @inlinable + internal var capacity: Int { + _buffer.count + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @usableFromInline + internal var description: String { + "(capacity: \(capacity), count: \(count), startSlot: \(startSlot))" + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { +#if COLLECTIONS_INTERNAL_CHECKS + @usableFromInline @inline(never) @_effects(releasenone) + internal func _checkInvariants() { + precondition(capacity >= 0) + precondition(count >= 0 && count <= capacity) + precondition(startSlot.position >= 0 && startSlot.position <= capacity) + } +#else + @inlinable @inline(__always) + internal func _checkInvariants() {} +#endif // COLLECTIONS_INTERNAL_CHECKS +} + +extension _UnsafeDequeHandle where Element: ~Copyable { @usableFromInline internal typealias Slot = _DequeSlot - @inlinable - @inline(__always) - var header: _DequeBufferHeader { - _header.pointee - } - - @inlinable - @inline(__always) - var capacity: Int { - _header.pointee.capacity - } - - @inlinable - @inline(__always) - var count: Int { - get { _header.pointee.count } - nonmutating set { _header.pointee.count = newValue } - } - - @inlinable - @inline(__always) - var startSlot: Slot { - get { _header.pointee.startSlot } - nonmutating set { _header.pointee.startSlot = newValue } - } - - @inlinable - @inline(__always) - func ptr(at slot: Slot) -> UnsafeMutablePointer { + @inlinable @inline(__always) + internal func ptr(at slot: Slot) -> UnsafePointer { assert(slot.position >= 0 && slot.position <= capacity) - return _elements + slot.position + return UnsafePointer(_baseAddress + slot.position) } -} -extension Deque._UnsafeHandle { - @inlinable - @inline(__always) - var mutableBuffer: UnsafeMutableBufferPointer { - assertMutable() - return .init(start: _elements, count: _header.pointee.capacity) + @inlinable @inline(__always) + internal mutating func mutablePtr( + at slot: Slot + ) -> UnsafeMutablePointer { + assert(slot.position >= 0 && slot.position <= capacity) + return _baseAddress + slot.position + } + + @inlinable @inline(__always) + internal var mutableBuffer: UnsafeMutableBufferPointer { + mutating get { + _buffer + } } @inlinable internal func buffer(for range: Range) -> UnsafeBufferPointer { assert(range.upperBound.position <= capacity) - return .init(start: _elements + range.lowerBound.position, count: range._count) + return .init(_buffer._extracting(unchecked: range._offsets)) } - @inlinable - @inline(__always) - internal func mutableBuffer(for range: Range) -> UnsafeMutableBufferPointer { - assertMutable() - return .init(mutating: buffer(for: range)) + @inlinable @inline(__always) + internal mutating func mutableBuffer(for range: Range) -> UnsafeMutableBufferPointer { + assert(range.upperBound.position <= capacity) + return _buffer._extracting(unchecked: range._offsets) } } -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { /// The slot immediately following the last valid one. (`endSlot` refers to /// the valid slot corresponding to `endIndex`, which is a different thing /// entirely.) @@ -170,9 +187,12 @@ extension Deque._UnsafeHandle { } } -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable internal func segments() -> _UnsafeWrappedBuffer { + guard _buffer.baseAddress != nil else { + return .init(._empty) + } let wrap = capacity - startSlot.position if count <= wrap { return .init(start: ptr(at: startSlot), count: count) @@ -186,6 +206,9 @@ extension Deque._UnsafeHandle { forOffsets offsets: Range ) -> _UnsafeWrappedBuffer { assert(offsets.lowerBound >= 0 && offsets.upperBound <= count) + guard _buffer.baseAddress != nil else { + return .init(._empty) + } let lower = slot(forOffset: offsets.lowerBound) let upper = slot(forOffset: offsets.upperBound) if offsets.count == 0 || lower < upper { @@ -197,65 +220,66 @@ extension Deque._UnsafeHandle { @inlinable @inline(__always) - internal func mutableSegments() -> _UnsafeMutableWrappedBuffer { - assertMutable() - return .init(mutating: segments()) + internal mutating func mutableSegments() -> _UnsafeMutableWrappedBuffer { + .init(mutating: segments()) } @inlinable @inline(__always) - internal func mutableSegments( + internal mutating func mutableSegments( forOffsets range: Range ) -> _UnsafeMutableWrappedBuffer { - assertMutable() - return .init(mutating: segments(forOffsets: range)) + .init(mutating: segments(forOffsets: range)) } } -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable - internal func availableSegments() -> _UnsafeMutableWrappedBuffer { - assertMutable() + internal mutating func availableSegments() -> _UnsafeMutableWrappedBuffer { + guard _buffer.baseAddress != nil else { + return .init(._empty) + } let endSlot = self.endSlot - guard count < capacity else { return .init(start: ptr(at: endSlot), count: 0) } + guard count < capacity else { return .init(start: mutablePtr(at: endSlot), count: 0) } if endSlot < startSlot { return .init(mutableBuffer(for: endSlot ..< startSlot)) } return .init(mutableBuffer(for: endSlot ..< limSlot), mutableBuffer(for: .zero ..< startSlot)) } } - - -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle { @inlinable @discardableResult - func initialize( + internal mutating func initialize( at start: Slot, from source: UnsafeBufferPointer ) -> Slot { assert(start.position + source.count <= capacity) guard source.count > 0 else { return start } - ptr(at: start).initialize(from: source.baseAddress!, count: source.count) + mutablePtr(at: start).initialize(from: source.baseAddress!, count: source.count) return Slot(at: start.position + source.count) } +} +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable @inline(__always) @discardableResult - func moveInitialize( + internal mutating func moveInitialize( at start: Slot, from source: UnsafeMutableBufferPointer ) -> Slot { assert(start.position + source.count <= capacity) guard source.count > 0 else { return start } - ptr(at: start).moveInitialize(from: source.baseAddress!, count: source.count) + mutablePtr(at: start) + .moveInitialize(from: source.baseAddress!, count: source.count) return Slot(at: start.position + source.count) } @inlinable @inline(__always) @discardableResult - public func move( + internal mutating func move( from source: Slot, to target: Slot, count: Int @@ -264,100 +288,15 @@ extension Deque._UnsafeHandle { assert(source.position + count <= self.capacity) assert(target.position + count <= self.capacity) guard count > 0 else { return (source, target) } - ptr(at: target).moveInitialize(from: ptr(at: source), count: count) + mutablePtr(at: target) + .moveInitialize(from: mutablePtr(at: source), count: count) return (slot(source, offsetBy: count), slot(target, offsetBy: count)) } } -extension Deque._UnsafeHandle { - /// Copy elements into a new storage instance without changing capacity or - /// layout. - @inlinable - internal func copyElements() -> Deque._Storage { - let object = _DequeBuffer.create( - minimumCapacity: capacity, - makingHeaderWith: { _ in header }) - let result = Deque._Storage(_buffer: ManagedBufferPointer(unsafeBufferObject: object)) - guard self.count > 0 else { return result } - result.update { target in - let source = self.segments() - target.initialize(at: startSlot, from: source.first) - if let second = source.second { - target.initialize(at: .zero, from: second) - } - } - return result - } - - /// Copy elements into a new storage instance with the specified minimum - /// capacity. - @inlinable - internal func copyElements(minimumCapacity: Int) -> Deque._Storage { - assert(minimumCapacity >= count) - let object = _DequeBuffer.create( - minimumCapacity: minimumCapacity, - makingHeaderWith: { - #if os(OpenBSD) - let capacity = minimumCapacity - #else - let capacity = $0.capacity - #endif - return _DequeBufferHeader( - capacity: capacity, - count: count, - startSlot: .zero) - }) - let result = Deque._Storage(_buffer: ManagedBufferPointer(unsafeBufferObject: object)) - guard count > 0 else { return result } - result.update { target in - assert(target.count == count && target.startSlot.position == 0) - let source = self.segments() - let next = target.initialize(at: .zero, from: source.first) - if let second = source.second { - target.initialize(at: next, from: second) - } - } - return result - } - - /// Move elements into a new storage instance with the specified minimum - /// capacity. Existing indices in `self` won't necessarily be valid in the - /// result. `self` is left empty. - @inlinable - internal func moveElements(minimumCapacity: Int) -> Deque._Storage { - assertMutable() - let count = self.count - assert(minimumCapacity >= count) - let object = _DequeBuffer.create( - minimumCapacity: minimumCapacity, - makingHeaderWith: { - #if os(OpenBSD) - let capacity = minimumCapacity - #else - let capacity = $0.capacity - #endif - return _DequeBufferHeader( - capacity: capacity, - count: count, - startSlot: .zero) - }) - let result = Deque._Storage(_buffer: ManagedBufferPointer(unsafeBufferObject: object)) - guard count > 0 else { return result } - result.update { target in - let source = self.mutableSegments() - let next = target.moveInitialize(at: .zero, from: source.first) - if let second = source.second { - target.moveInitialize(at: next, from: second) - } - } - self.count = 0 - return result - } -} - -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable internal func withUnsafeSegment( startingAt start: Int, @@ -380,18 +319,17 @@ extension Deque._UnsafeHandle { // MARK: Replacement -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { /// Replace the elements in `range` with `newElements`. The deque's count must /// not change as a result of calling this function. /// /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @inlinable - internal func uncheckedReplaceInPlace( + internal mutating func uncheckedReplaceInPlace( inOffsets range: Range, with newElements: C ) where C.Element == Element { - assertMutable() assert(range.upperBound <= count) assert(newElements.count == range.count) guard !range.isEmpty else { return } @@ -402,28 +340,28 @@ extension Deque._UnsafeHandle { // MARK: Appending -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { /// Append `element` to this buffer. The buffer must have enough free capacity /// to insert one new element. /// /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @inlinable - internal func uncheckedAppend(_ element: Element) { - assertMutable() + internal mutating func uncheckedAppend(_ element: consuming Element) { assert(count < capacity) - ptr(at: endSlot).initialize(to: element) + mutablePtr(at: endSlot).initialize(to: element) count += 1 } +} +extension _UnsafeDequeHandle { /// Append the contents of `source` to this buffer. The buffer must have /// enough free capacity to insert the new elements. /// /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @inlinable - internal func uncheckedAppend(contentsOf source: UnsafeBufferPointer) { - assertMutable() + internal mutating func uncheckedAppend(contentsOf source: UnsafeBufferPointer) { assert(count + source.count <= capacity) guard source.count > 0 else { return } let c = self.count @@ -435,25 +373,25 @@ extension Deque._UnsafeHandle { // MARK: Prepending -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable - internal func uncheckedPrepend(_ element: Element) { - assertMutable() + internal mutating func uncheckedPrepend(_ element: consuming Element) { assert(count < capacity) let slot = self.slot(before: startSlot) - ptr(at: slot).initialize(to: element) + mutablePtr(at: slot).initialize(to: element) startSlot = slot count += 1 } +} +extension _UnsafeDequeHandle { /// Prepend the contents of `source` to this buffer. The buffer must have /// enough free capacity to insert the new elements. /// /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @inlinable - internal func uncheckedPrepend(contentsOf source: UnsafeBufferPointer) { - assertMutable() + internal mutating func uncheckedPrepend(contentsOf source: UnsafeBufferPointer) { assert(count + source.count <= capacity) guard source.count > 0 else { return } let oldStart = startSlot @@ -468,7 +406,27 @@ extension Deque._UnsafeHandle { // MARK: Insertion -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { + @inlinable + internal mutating func uncheckedInsert( + _ newElement: consuming Element, at offset: Int + ) { + assert(count < capacity) + if offset == 0 { + uncheckedPrepend(newElement) + return + } + if offset == count { + uncheckedAppend(newElement) + return + } + let gap = openGap(ofSize: 1, atOffset: offset) + assert(gap.first.count == 1) + gap.first.baseAddress!.initialize(to: newElement) + } +} + +extension _UnsafeDequeHandle { /// Insert all elements from `newElements` into this deque, starting at /// `offset`. /// @@ -481,32 +439,35 @@ extension Deque._UnsafeHandle { /// - Parameter offset: The desired offset from the start at which to place /// the first element. @inlinable - internal func uncheckedInsert( + internal mutating func uncheckedInsert( contentsOf newElements: __owned C, count newCount: Int, atOffset offset: Int ) where C.Element == Element { - assertMutable() assert(offset <= count) assert(newElements.count == newCount) guard newCount > 0 else { return } let gap = openGap(ofSize: newCount, atOffset: offset) gap.initialize(from: newElements) } +} +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable - internal func mutableWrappedBuffer( + internal mutating func mutableWrappedBuffer( between start: Slot, and end: Slot ) -> _UnsafeMutableWrappedBuffer { assert(start.position <= capacity) assert(end.position <= capacity) if start < end { - return .init(start: ptr(at: start), count: end.position - start.position) + return .init( + start: mutablePtr(at: start), + count: end.position - start.position) } return .init( - first: ptr(at: start), count: capacity - start.position, - second: ptr(at: .zero), count: end.position) + first: mutablePtr(at: start), count: capacity - start.position, + second: mutablePtr(at: .zero), count: end.position) } /// Slide elements around so that there is a gap of uninitialized slots of @@ -520,11 +481,10 @@ extension Deque._UnsafeHandle { /// - Parameter offset: The offset from the start at which the uninitialized /// slots should start. @inlinable - internal func openGap( + internal mutating func openGap( ofSize gapSize: Int, atOffset offset: Int ) -> _UnsafeMutableWrappedBuffer { - assertMutable() assert(offset >= 0 && offset <= self.count) assert(self.count + gapSize <= capacity) assert(gapSize > 0) @@ -648,30 +608,35 @@ extension Deque._UnsafeHandle { // MARK: Removal -extension Deque._UnsafeHandle { +extension _UnsafeDequeHandle where Element: ~Copyable { @inlinable - internal func uncheckedRemoveFirst() -> Element { - assertMutable() + internal mutating func uncheckedRemove(at offset: Int) -> Element { + let slot = self.slot(forOffset: offset) + let result = mutablePtr(at: slot).move() + closeGap(offsets: Range(uncheckedBounds: (offset, offset + 1))) + return result + } + + @inlinable + internal mutating func uncheckedRemoveFirst() -> Element { assert(count > 0) - let result = ptr(at: startSlot).move() + let result = mutablePtr(at: startSlot).move() startSlot = slot(after: startSlot) count -= 1 return result } @inlinable - internal func uncheckedRemoveLast() -> Element { - assertMutable() + internal mutating func uncheckedRemoveLast() -> Element { assert(count > 0) let slot = self.slot(forOffset: count - 1) - let result = ptr(at: slot).move() + let result = mutablePtr(at: slot).move() count -= 1 return result } @inlinable - internal func uncheckedRemoveFirst(_ n: Int) { - assertMutable() + internal mutating func uncheckedRemoveFirst(_ n: Int) { assert(count >= n) guard n > 0 else { return } let target = mutableSegments(forOffsets: 0 ..< n) @@ -681,8 +646,7 @@ extension Deque._UnsafeHandle { } @inlinable - internal func uncheckedRemoveLast(_ n: Int) { - assertMutable() + internal mutating func uncheckedRemoveLast(_ n: Int) { assert(count >= n) guard n > 0 else { return } let target = mutableSegments(forOffsets: count - n ..< count) @@ -695,8 +659,7 @@ extension Deque._UnsafeHandle { /// This method does not ensure that the storage buffer is uniquely /// referenced. @inlinable - internal func uncheckedRemoveAll() { - assertMutable() + internal mutating func uncheckedRemoveAll() { guard count > 0 else { return } let target = mutableSegments() target.deinitialize() @@ -710,8 +673,7 @@ extension Deque._UnsafeHandle { /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @inlinable - internal func uncheckedRemove(offsets bounds: Range) { - assertMutable() + internal mutating func uncheckedRemove(offsets bounds: Range) { assert(bounds.lowerBound >= 0 && bounds.upperBound <= self.count) // Deinitialize elements in `bounds`. @@ -720,13 +682,13 @@ extension Deque._UnsafeHandle { } /// Close the gap of already uninitialized elements in `bounds`, sliding - /// elements outside of the gap to eliminate it. + /// elements outside of the gap to eliminate it, and updating `count` to + /// reflect the removal. /// /// This function does not validate its input arguments in release builds. Nor /// does it ensure that the storage buffer is uniquely referenced. @inlinable - internal func closeGap(offsets bounds: Range) { - assertMutable() + internal mutating func closeGap(offsets bounds: Range) { assert(bounds.lowerBound >= 0 && bounds.upperBound <= self.count) let gapSize = bounds.count guard gapSize > 0 else { return } @@ -831,3 +793,53 @@ extension Deque._UnsafeHandle { } } } + +extension _UnsafeDequeHandle { + /// Copy elements into a newly allocated handle without changing capacity or + /// layout. + @inlinable + internal func allocateCopy() -> Self { + var handle: Self = .allocate(capacity: self.capacity) + handle.count = self.count + handle.startSlot = self.startSlot + let src = self.segments() + handle.initialize(at: self.startSlot, from: src.first) + if let second = src.second { + handle.initialize(at: .zero, from: second) + } + return handle + } + + /// Copy elements into a new storage instance with the specified minimum + /// capacity. This operation does not preserve layout. + @inlinable + internal func allocateCopy(capacity: Int) -> Self { + assert(capacity >= count) + var handle: Self = .allocate(capacity: capacity) + handle.count = self.count + let src = self.segments() + let next = handle.initialize(at: .zero, from: src.first) + if let second = src.second { + handle.initialize(at: next, from: second) + } + return handle + } +} + +extension _UnsafeDequeHandle where Element: ~Copyable { + @inlinable + internal mutating func reallocate(capacity newCapacity: Int) { + precondition(newCapacity >= count) + guard newCapacity != capacity else { return } + var newHandle = Self.allocate(capacity: newCapacity) + newHandle.startSlot = .zero + newHandle.count = self.count + let source = self.mutableSegments() + let next = newHandle.moveInitialize(at: .zero, from: source.first) + if let second = source.second { + newHandle.moveInitialize(at: next, from: second) + } + self._buffer.deallocate() + self = newHandle + } +} diff --git a/Sources/DequeModule/_UnsafeWrappedBuffer.swift b/Sources/DequeModule/_UnsafeWrappedBuffer.swift index 1faefacc..71c2da76 100644 --- a/Sources/DequeModule/_UnsafeWrappedBuffer.swift +++ b/Sources/DequeModule/_UnsafeWrappedBuffer.swift @@ -11,11 +11,12 @@ #if !COLLECTIONS_SINGLE_MODULE import InternalCollectionsUtilities +import Future #endif @frozen @usableFromInline -internal struct _UnsafeWrappedBuffer { +internal struct _UnsafeWrappedBuffer { @usableFromInline internal let first: UnsafeBufferPointer @@ -54,11 +55,21 @@ internal struct _UnsafeWrappedBuffer { @inlinable internal var count: Int { first.count + (second?.count ?? 0) } + + @inlinable + internal func isIdentical(to other: Self) -> Bool { + guard self.first === other.first else { return false } + switch (self.second, other.second) { + case (nil, nil): return true + case let (a?, b?): return a === b + default: return false + } + } } @frozen @usableFromInline -internal struct _UnsafeMutableWrappedBuffer { +internal struct _UnsafeMutableWrappedBuffer { @usableFromInline internal let first: UnsafeMutableBufferPointer @@ -76,24 +87,6 @@ internal struct _UnsafeMutableWrappedBuffer { assert(first.count > 0 || second == nil) } - @inlinable - @inline(__always) - internal init( - _ first: UnsafeMutableBufferPointer.SubSequence, - _ second: UnsafeMutableBufferPointer? = nil - ) { - self.init(UnsafeMutableBufferPointer(rebasing: first), second) - } - - @inlinable - @inline(__always) - internal init( - _ first: UnsafeMutableBufferPointer, - _ second: UnsafeMutableBufferPointer.SubSequence - ) { - self.init(first, UnsafeMutableBufferPointer(rebasing: second)) - } - @inlinable @inline(__always) internal init( @@ -124,6 +117,26 @@ internal struct _UnsafeMutableWrappedBuffer { } extension _UnsafeMutableWrappedBuffer { + @inlinable + @inline(__always) + internal init( + _ first: UnsafeMutableBufferPointer.SubSequence, + _ second: UnsafeMutableBufferPointer? = nil + ) { + self.init(UnsafeMutableBufferPointer(rebasing: first), second) + } + + @inlinable + @inline(__always) + internal init( + _ first: UnsafeMutableBufferPointer, + _ second: UnsafeMutableBufferPointer.SubSequence + ) { + self.init(first, UnsafeMutableBufferPointer(rebasing: second)) + } +} + +extension _UnsafeMutableWrappedBuffer where Element: ~Copyable { @inlinable @inline(__always) internal var count: Int { first.count + (second?.count ?? 0) } @@ -135,9 +148,9 @@ extension _UnsafeMutableWrappedBuffer { return self } if n <= first.count { - return Self(first.prefix(n)) + return Self(first._extracting(first: n)) } - return Self(first, second!.prefix(n - first.count)) + return Self(first, second!._extracting(first: n - first.count)) } @inlinable @@ -147,22 +160,24 @@ extension _UnsafeMutableWrappedBuffer { return self } guard let second = second else { - return Self(first.suffix(n)) + return Self(first._extracting(last: n)) } if n <= second.count { - return Self(second.suffix(n)) + return Self(second._extracting(last: n)) } - return Self(first.suffix(n - second.count), second) + return Self(first._extracting(last: n - second.count), second) } } -extension _UnsafeMutableWrappedBuffer { +extension _UnsafeMutableWrappedBuffer where Element: ~Copyable { @inlinable internal func deinitialize() { first.deinitialize() second?.deinitialize() } +} +extension _UnsafeMutableWrappedBuffer { @inlinable @discardableResult internal func initialize( diff --git a/Sources/Future/CMakeLists.txt b/Sources/Future/CMakeLists.txt index fdd305f7..63b1192f 100644 --- a/Sources/Future/CMakeLists.txt +++ b/Sources/Future/CMakeLists.txt @@ -14,10 +14,13 @@ add_library(Future "Inout.swift" "RawSpan.swift" "Span.swift" + "Containers/Container.swift" + "Containers/DynamicArray.swift" + "Containers/RigidArray.swift" ) target_link_libraries(Future PRIVATE - _CollectionsUtilities) + InternalCollectionsUtilities) set_target_properties(Future PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) diff --git a/Sources/Future/Containers/Container.swift b/Sources/Future/Containers/Container.swift new file mode 100644 index 00000000..40867983 --- /dev/null +++ b/Sources/Future/Containers/Container.swift @@ -0,0 +1,138 @@ +public protocol BorrowingIteratorProtocol: ~Escapable { + associatedtype Element: ~Copyable + + mutating func nextChunk(maximumCount: Int) -> dependsOn(scoped self) Span +} + +public protocol Container: ~Copyable, ~Escapable { + associatedtype Element: ~Copyable + + associatedtype BorrowingIterator: BorrowingIteratorProtocol, ~Escapable + where BorrowingIterator.Element == Element + + borrowing func startBorrowingIteration() -> BorrowingIterator + borrowing func startBorrowingIteration(from start: Index) -> BorrowingIterator + + associatedtype Index: Comparable + + var isEmpty: Bool { get } + var count: Int { get } + + var startIndex: Index { get } + var endIndex: Index { get } + + // FIXME: Replace `@_borrowed` with proper `read`/`modify` accessor requirements + @_borrowed subscript(index: Index) -> Element { get } + + func index(after index: Index) -> Index + func formIndex(after i: inout Index) + + func index(at position: borrowing BorrowingIterator) -> Index + + func distance(from start: Index, to end: Index) -> Int + + func index(_ index: Index, offsetBy n: Int) -> Index + + func formIndex( + _ i: inout Index, offsetBy distance: inout Int, limitedBy limit: Index + ) +} + +public protocol BidirectionalContainer: Container, ~Copyable, ~Escapable { + override associatedtype Element: ~Copyable + + func index(before i: Index) -> Index + func formIndex(before i: inout Index) + + @_nonoverride func index(_ i: Index, offsetBy distance: Int) -> Index + @_nonoverride func formIndex( + _ i: inout Index, offsetBy distance: inout Int, limitedBy limit: Index + ) +} + +public protocol RandomAccessContainer: BidirectionalContainer, ~Copyable, ~Escapable { + override associatedtype Element: ~Copyable +} + + +extension RandomAccessContainer where Index == Int, Self: ~Copyable { + @inlinable + public func index(after index: Int) -> Int { + // Note: Range checks are deferred until element access. + index + 1 + } + + @inlinable + public func index(before index: Int) -> Int { + // Note: Range checks are deferred until element access. + index - 1 + } + + @inlinable + public func formIndex(after index: inout Int) { + // Note: Range checks are deferred until element access. + index += 1 + } + + @inlinable + public func formIndex(before index: inout Int) { + // Note: Range checks are deferred until element access. + index -= 1 + } + + @inlinable + public func distance(from start: Int, to end: Int) -> Int { + // Note: Range checks are deferred until element access. + end - start + } + + @inlinable + public func index(_ index: Int, offsetBy n: Int) -> Int { + // Note: Range checks are deferred until element access. + index + n + } + + @inlinable + public func formIndex( + _ index: inout Int, offsetBy distance: inout Int, limitedBy limit: Int + ) { + // Note: Range checks are deferred until element access. + if distance >= 0 { + guard limit >= index else { + index += distance + distance = 0 + return + } + let d = Swift.min(distance, limit - index) + index += d + distance -= d + } else { + guard limit <= index else { + index += distance + distance = 0 + return + } + let d = Swift.max(distance, limit - index) + index += d + distance -= d + } + } +} + +#if false // TODO +public protocol Muterator: ~Copyable, ~Escapable { + associatedtype Element: ~Copyable + + mutating func nextChunk(maximumCount: Int) -> dependsOn(scoped state) MutableSpan +} + +public protocol MutableContainer: Container, ~Copyable, ~Escapable { + associatedtype MutatingIterationState: ~Copyable, ~Escapable + + mutating func startMutatingIteration() -> MutatingIterationState + + // FIXME: Replace `@_borrowed` with proper `read`/`modify` accessor requirements + @_borrowed subscript(index: Index) -> Element { get set } + +} +#endif diff --git a/Sources/Future/Containers/DynamicArray.swift b/Sources/Future/Containers/DynamicArray.swift new file mode 100644 index 00000000..50a8f6a2 --- /dev/null +++ b/Sources/Future/Containers/DynamicArray.swift @@ -0,0 +1,181 @@ +/// A dynamically self-resizing, heap allocated, noncopyable array +/// of potentially noncopyable elements. +@frozen +public struct DynamicArray: ~Copyable { + @usableFromInline + internal var _storage: RigidArray + + @inlinable + public init() { + _storage = .init(capacity: 0) + } + + @inlinable + public init(minimumCapacity: Int) { + _storage = .init(capacity: minimumCapacity) + } + + @inlinable + public init(count: Int, initializedBy generator: (Int) -> Element) { + _storage = .init(count: count, initializedBy: generator) + } +} + +extension DynamicArray: Sendable where Element: Sendable & ~Copyable {} + +extension DynamicArray where Element: ~Copyable { + @inlinable + public var capacity: Int { _storage.capacity } +} + +extension DynamicArray: RandomAccessContainer where Element: ~Copyable { + public typealias BorrowingIterator = RigidArray.BorrowingIterator + public typealias Index = Int + + public func startBorrowingIteration() -> BorrowingIterator { + BorrowingIterator(for: _storage, startOffset: 0) + } + + public func startBorrowingIteration(from start: Int) -> BorrowingIterator { + BorrowingIterator(for: _storage, startOffset: start) + } + + @inlinable + public var isEmpty: Bool { _storage.isEmpty } + + @inlinable + public var count: Int { _storage.count } + + @inlinable + public var startIndex: Int { 0 } + + @inlinable + public var endIndex: Int { _storage.count } + + @inlinable + public subscript(position: Int) -> Element { + @inline(__always) + _read { + yield _storage[position] + } + @inline(__always) + _modify { + yield &_storage[position] + } + } + + @inlinable + public func index(after i: Int) -> Int { i + 1 } + + @inlinable + public func index(before i: Int) -> Int { i - 1 } + + @inlinable + public func formIndex(after index: inout Int) { + // Note: Range checks are deferred until element access. + index += 1 + } + + @inlinable + public func formIndex(before index: inout Int) { + // Note: Range checks are deferred until element access. + index -= 1 + } + + @inlinable + public func index(at position: borrowing BorrowingIterator) -> Int { + // Note: Range checks are deferred until element access. + position._offset + } + + @inlinable + public func distance(from start: Int, to end: Int) -> Int { + // Note: Range checks are deferred until element access. + end - start + } + + @inlinable + public func index(_ index: Int, offsetBy n: Int) -> Int { + // Note: Range checks are deferred until element access. + index + n + } + + @inlinable + public func formIndex( + _ index: inout Int, offsetBy distance: inout Int, limitedBy limit: Int + ) { + _storage.formIndex(&index, offsetBy: &distance, limitedBy: limit) + } +} + +extension DynamicArray where Element: ~Copyable { + @inlinable + public func borrowElement ( + at index: Int, + by body: (borrowing Element) throws(E) -> R + ) throws(E) -> R { + try _storage.borrowElement(at: index, by: body) + } + + @inlinable + public mutating func updateElement ( + at index: Int, + by body: (inout Element) throws(E) -> R + ) throws(E) -> R { + try _storage.updateElement(at: index, by: body) + } +} + +extension DynamicArray where Element: ~Copyable { + @inlinable + @discardableResult + public mutating func remove(at index: Int) -> Element { + _storage.remove(at: index) + } +} + +extension DynamicArray where Element: ~Copyable { + @inlinable + public mutating func reserveCapacity(_ n: Int) { + _storage.reserveCapacity(n) + } +} + +extension DynamicArray where Element: ~Copyable { + @inlinable + internal static func _grow(_ capacity: Int) -> Int { + 2 * capacity + } + + @inlinable + public mutating func _ensureFreeCapacity(_ minimumCapacity: Int) { + guard _storage.freeCapacity < minimumCapacity else { return } + reserveCapacity(max(count + minimumCapacity, Self._grow(capacity))) + } +} + +extension DynamicArray where Element: ~Copyable { + @inlinable + public mutating func append(_ item: consuming Element) { + _ensureFreeCapacity(1) + _storage.append(item) + } +} + +extension DynamicArray where Element: ~Copyable { + @inlinable + public mutating func insert(_ item: consuming Element, at index: Int) { + precondition(index >= 0 && index <= count) + _ensureFreeCapacity(1) + _storage.insert(item, at: index) + } +} + +extension DynamicArray { + @inlinable + public mutating func append(contentsOf items: some Sequence) { + for item in items { + append(item) + } + } +} diff --git a/Sources/Future/Containers/RigidArray.swift b/Sources/Future/Containers/RigidArray.swift new file mode 100644 index 00000000..eb85fc75 --- /dev/null +++ b/Sources/Future/Containers/RigidArray.swift @@ -0,0 +1,216 @@ +/// A manually resizable, heap allocated, noncopyable array of +/// potentially noncopyable elements. +@frozen +public struct RigidArray: ~Copyable { + @usableFromInline + internal var _storage: UnsafeMutableBufferPointer + + @usableFromInline + internal var _count: Int + + @inlinable + public init(capacity: Int) { + precondition(capacity >= 0) + if capacity > 0 { + _storage = .allocate(capacity: capacity) + } else { + _storage = .init(start: nil, count: 0) + } + _count = 0 + } + + @inlinable + public init(count: Int, initializedBy generator: (Int) -> Element) { + _storage = .allocate(capacity: count) + for i in 0 ..< count { + _storage.initializeElement(at: i, to: generator(i)) + } + _count = count + } + + deinit { + _storage.extracting(0 ..< count).deinitialize() + _storage.deallocate() + } +} + +extension RigidArray: @unchecked Sendable where Element: Sendable & ~Copyable {} + +extension RigidArray where Element: ~Copyable { + @inlinable + public var capacity: Int { _storage.count } + + @inlinable + public var freeCapacity: Int { capacity - count } + + @inlinable + public var isFull: Bool { freeCapacity == 0 } +} + +extension RigidArray: RandomAccessContainer where Element: ~Copyable { + public struct BorrowingIterator: BorrowingIteratorProtocol, ~Escapable { + @usableFromInline + internal let _items: UnsafeBufferPointer + + @usableFromInline + internal var _offset: Int + + @inlinable + internal init(for array: borrowing RigidArray, startOffset: Int) { + self._items = UnsafeBufferPointer(array._items) + self._offset = startOffset + } + + public mutating func nextChunk( + maximumCount: Int + ) -> dependsOn(scoped self) Span { + let end = _offset + Swift.min(maximumCount, _items.count - _offset) + defer { _offset = end } + let chunk = _items.extracting(Range(uncheckedBounds: (_offset, end))) + return Span(unsafeElements: chunk, owner: self) + } + } + + public func startBorrowingIteration() -> BorrowingIterator { + BorrowingIterator(for: self, startOffset: 0) + } + + public func startBorrowingIteration(from start: Int) -> BorrowingIterator { + BorrowingIterator(for: self, startOffset: start) + } + + public typealias Index = Int + + @inlinable + public var isEmpty: Bool { count == 0 } + + @inlinable + public var count: Int { _count } + + @inlinable + public var startIndex: Int { 0 } + + @inlinable + public var endIndex: Int { count } + + @inlinable + public subscript(position: Int) -> Element { + @inline(__always) + _read { + precondition(position >= 0 && position < _count) + yield _storage[position] + } + @inline(__always) + _modify { + precondition(position >= 0 && position < _count) + yield &_storage[position] + } + } + + @inlinable + public func index(at position: borrowing BorrowingIterator) -> Int { + precondition(position._items === UnsafeBufferPointer(self._items)) + return position._offset + } +} + +extension RigidArray where Element: ~Copyable { + @inlinable + internal var _items: UnsafeMutableBufferPointer { + _storage.extracting(Range(uncheckedBounds: (0, _count))) + } + + @inlinable + internal var _freeSpace: UnsafeMutableBufferPointer { + _storage.extracting(Range(uncheckedBounds: (_count, capacity))) + } +} + +extension RigidArray where Element: ~Copyable { + @inlinable + public mutating func resize(to newCapacity: Int) { + precondition(newCapacity >= count) + guard newCapacity != capacity else { return } + let newStorage: UnsafeMutableBufferPointer = .allocate(capacity: newCapacity) + let i = newStorage.moveInitialize(fromContentsOf: self._items) + assert(i == count) + _storage.deallocate() + _storage = newStorage + } + + @inlinable + public mutating func reserveCapacity(_ n: Int) { + guard capacity < n else { return } + resize(to: n) + } +} + + +extension RigidArray where Element: ~Copyable { + @inlinable + public func borrowElement ( + at index: Int, + by body: (borrowing Element) throws(E) -> R + ) throws(E) -> R { + precondition(index >= 0 && index < _count) + return try body(_storage[index]) + } + + @inlinable + public mutating func updateElement ( + at index: Int, + by body: (inout Element) throws(E) -> R + ) throws(E) -> R { + precondition(index >= 0 && index < _count) + return try body(&_storage[index]) + } +} + +extension RigidArray where Element: ~Copyable { + @inlinable + @discardableResult + public mutating func remove(at index: Int) -> Element { + precondition(index >= 0 && index < count) + let old = _storage.moveElement(from: index) + let source = _storage.extracting(index + 1 ..< count) + let target = _storage.extracting(index ..< count - 1) + let i = target.moveInitialize(fromContentsOf: source) + assert(i == target.endIndex) + _count -= 1 + return old + } +} + +extension RigidArray where Element: ~Copyable { + @inlinable + public mutating func append(_ item: consuming Element) { + precondition(!isFull) + _storage.initializeElement(at: _count, to: item) + _count += 1 + } +} + +extension RigidArray where Element: ~Copyable { + @inlinable + public mutating func insert(_ item: consuming Element, at index: Int) { + precondition(index >= 0 && index <= count) + precondition(!isFull) + if index < count { + let source = _storage.extracting(index ..< count) + let target = _storage.extracting(index + 1 ..< count + 1) + let last = target.moveInitialize(fromContentsOf: source) + assert(last == target.endIndex) + } + _storage.initializeElement(at: index, to: item) + _count += 1 + } +} + +extension RigidArray { + @inlinable + public mutating func append(contentsOf items: some Sequence) { + for item in items { + append(item) + } + } +} diff --git a/Sources/Future/UnsafeBufferPointer+Additions.swift b/Sources/Future/UnsafeBufferPointer+Additions.swift new file mode 100644 index 00000000..7b7a5e96 --- /dev/null +++ b/Sources/Future/UnsafeBufferPointer+Additions.swift @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +//===----------------------------------------------------------------------===// + +extension UnsafeBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two `UnsafeBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + public static func ===(_ a: Self, _ b: Self) -> Bool { + (a.baseAddress == b.baseAddress) && (a.count == b.count) + } +} + +extension UnsafeMutableBufferPointer where Element: ~Copyable { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + public static func ===(_ a: Self, _ b: Self) -> Bool { + (a.baseAddress == b.baseAddress) && (a.count == b.count) + } +} + +extension UnsafeRawBufferPointer { + /// Returns a Boolean value indicating whether two `UnsafeRawBufferPointer` + /// instances refer to the same region in memory. + @inlinable @inline(__always) + public static func ===(_ a: Self, _ b: Self) -> Bool { + (a.baseAddress == b.baseAddress) && (a.count == b.count) + } +} + +extension UnsafeMutableRawBufferPointer { + /// Returns a Boolean value indicating whether two + /// `UnsafeMutableRawBufferPointer` instances refer to the same region in + /// memory. + @inlinable @inline(__always) + public static func ===(_ a: Self, _ b: Self) -> Bool { + (a.baseAddress == b.baseAddress) && (a.count == b.count) + } +} diff --git a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb index 603e3047..014c9d30 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeBufferPointer+Extras.swift.gyb @@ -16,13 +16,44 @@ ${autogenerated_warning()} % for modifier in visibility_levels: ${visibility_boilerplate(modifier)} -extension UnsafeBufferPointer { +extension UnsafeBufferPointer where Element: ~Copyable { + @inlinable + @inline(__always) + ${modifier} static var _empty: Self { + .init(start: nil, count: 0) + } + @inlinable @inline(__always) ${modifier} func _ptr(at index: Int) -> UnsafePointer { assert(index >= 0 && index < count) return baseAddress.unsafelyUnwrapped + index } + + @_alwaysEmitIntoClient + ${modifier} func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + + @inlinable + ${modifier} func _extracting(first n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (0, n))) + } + + @inlinable + ${modifier} func _extracting(last n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (count - n, count))) + } } + % end ${visibility_boilerplate("end")} diff --git a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb index 4d7cdde7..a2f840f7 100644 --- a/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb +++ b/Sources/InternalCollectionsUtilities/UnsafeMutableBufferPointer+Extras.swift.gyb @@ -16,6 +16,45 @@ ${autogenerated_warning()} % for modifier in visibility_levels: ${visibility_boilerplate(modifier)} +extension UnsafeMutableBufferPointer where Element: ~Copyable { + @inlinable + @inline(__always) + ${modifier} static var _empty: Self { + .init(start: nil, count: 0) + } + + @inlinable + @inline(__always) + ${modifier} func _ptr(at index: Int) -> UnsafeMutablePointer { + assert(index >= 0 && index < count) + return baseAddress.unsafelyUnwrapped + index + } + + @_alwaysEmitIntoClient + ${modifier} func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + + @inlinable + ${modifier} func _extracting(first n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (0, n))) + } + + @inlinable + ${modifier} func _extracting(last n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (count - n, count))) + } +} + extension UnsafeMutableBufferPointer { @inlinable ${modifier} func initialize(fromContentsOf source: Self) -> Index { @@ -76,24 +115,40 @@ extension UnsafeMutableBufferPointer { assert(i == self.endIndex) } + @inlinable @inline(__always) + ${modifier} func initializeAll(fromContentsOf source: UnsafeBufferPointer) { + assert(self.count == source.count) + guard source.count > 0 else { return } + self.baseAddress.unsafelyUnwrapped.initialize( + from: source.baseAddress.unsafelyUnwrapped, + count: source.count) + } + + @inlinable @inline(__always) + ${modifier} func initializeAll(fromContentsOf source: Slice>) { + self.initializeAll(fromContentsOf: .init(rebasing: source)) + } + @inlinable @inline(__always) ${modifier} func initializeAll(fromContentsOf source: Self) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) + self.initializeAll(fromContentsOf: UnsafeBufferPointer(source)) } @inlinable @inline(__always) ${modifier} func initializeAll(fromContentsOf source: Slice) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) + self.initializeAll(fromContentsOf: UnsafeMutableBufferPointer(rebasing: source)) } +} +extension UnsafeMutableBufferPointer where Element: ~Copyable { @inlinable @inline(__always) ${modifier} func moveInitializeAll(fromContentsOf source: Self) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } +} +extension UnsafeMutableBufferPointer { @inlinable @inline(__always) ${modifier} func moveInitializeAll(fromContentsOf source: Slice) { let i = self.moveInitialize(fromContentsOf: source) diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift index 749f17bc..ec6a6f82 100644 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeBufferPointer+Extras.swift @@ -22,21 +22,83 @@ // but in regular builds we want them to be public. Unfortunately // the current best way to do this is to duplicate all definitions. #if COLLECTIONS_SINGLE_MODULE -extension UnsafeBufferPointer { +extension UnsafeBufferPointer where Element: ~Copyable { + @inlinable + @inline(__always) + internal static var _empty: Self { + .init(start: nil, count: 0) + } + @inlinable @inline(__always) internal func _ptr(at index: Int) -> UnsafePointer { assert(index >= 0 && index < count) return baseAddress.unsafelyUnwrapped + index } + + @_alwaysEmitIntoClient + internal func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + + @inlinable + internal func _extracting(first n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (0, n))) + } + + @inlinable + internal func _extracting(last n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (count - n, count))) + } } + #else // !COLLECTIONS_SINGLE_MODULE -extension UnsafeBufferPointer { +extension UnsafeBufferPointer where Element: ~Copyable { + @inlinable + @inline(__always) + public static var _empty: Self { + .init(start: nil, count: 0) + } + @inlinable @inline(__always) public func _ptr(at index: Int) -> UnsafePointer { assert(index >= 0 && index < count) return baseAddress.unsafelyUnwrapped + index } + + @_alwaysEmitIntoClient + public func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + + @inlinable + public func _extracting(first n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (0, n))) + } + + @inlinable + public func _extracting(last n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (count - n, count))) + } } + #endif // COLLECTIONS_SINGLE_MODULE diff --git a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift index be578b23..5c8dd948 100644 --- a/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift +++ b/Sources/InternalCollectionsUtilities/autogenerated/UnsafeMutableBufferPointer+Extras.swift @@ -22,6 +22,45 @@ // but in regular builds we want them to be public. Unfortunately // the current best way to do this is to duplicate all definitions. #if COLLECTIONS_SINGLE_MODULE +extension UnsafeMutableBufferPointer where Element: ~Copyable { + @inlinable + @inline(__always) + internal static var _empty: Self { + .init(start: nil, count: 0) + } + + @inlinable + @inline(__always) + internal func _ptr(at index: Int) -> UnsafeMutablePointer { + assert(index >= 0 && index < count) + return baseAddress.unsafelyUnwrapped + index + } + + @_alwaysEmitIntoClient + internal func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + + @inlinable + internal func _extracting(first n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (0, n))) + } + + @inlinable + internal func _extracting(last n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (count - n, count))) + } +} + extension UnsafeMutableBufferPointer { @inlinable internal func initialize(fromContentsOf source: Self) -> Index { @@ -82,24 +121,40 @@ extension UnsafeMutableBufferPointer { assert(i == self.endIndex) } + @inlinable @inline(__always) + internal func initializeAll(fromContentsOf source: UnsafeBufferPointer) { + assert(self.count == source.count) + guard source.count > 0 else { return } + self.baseAddress.unsafelyUnwrapped.initialize( + from: source.baseAddress.unsafelyUnwrapped, + count: source.count) + } + + @inlinable @inline(__always) + internal func initializeAll(fromContentsOf source: Slice>) { + self.initializeAll(fromContentsOf: .init(rebasing: source)) + } + @inlinable @inline(__always) internal func initializeAll(fromContentsOf source: Self) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) + self.initializeAll(fromContentsOf: UnsafeBufferPointer(source)) } @inlinable @inline(__always) internal func initializeAll(fromContentsOf source: Slice) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) + self.initializeAll(fromContentsOf: UnsafeMutableBufferPointer(rebasing: source)) } +} +extension UnsafeMutableBufferPointer where Element: ~Copyable { @inlinable @inline(__always) internal func moveInitializeAll(fromContentsOf source: Self) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } +} +extension UnsafeMutableBufferPointer { @inlinable @inline(__always) internal func moveInitializeAll(fromContentsOf source: Slice) { let i = self.moveInitialize(fromContentsOf: source) @@ -149,6 +204,45 @@ extension Slice { } } #else // !COLLECTIONS_SINGLE_MODULE +extension UnsafeMutableBufferPointer where Element: ~Copyable { + @inlinable + @inline(__always) + public static var _empty: Self { + .init(start: nil, count: 0) + } + + @inlinable + @inline(__always) + public func _ptr(at index: Int) -> UnsafeMutablePointer { + assert(index >= 0 && index < count) + return baseAddress.unsafelyUnwrapped + index + } + + @_alwaysEmitIntoClient + public func _extracting(unchecked bounds: Range) -> Self { + assert(bounds.lowerBound >= 0 && bounds.upperBound <= count, + "Index out of range") + guard let start = self.baseAddress else { + return Self(start: nil, count: 0) + } + return Self(start: start + bounds.lowerBound, count: bounds.count) + } + + @inlinable + public func _extracting(first n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (0, n))) + } + + @inlinable + public func _extracting(last n: Int) -> Self { + assert(n >= 0) + if n >= count { return self } + return extracting(Range(uncheckedBounds: (count - n, count))) + } +} + extension UnsafeMutableBufferPointer { @inlinable public func initialize(fromContentsOf source: Self) -> Index { @@ -209,24 +303,40 @@ extension UnsafeMutableBufferPointer { assert(i == self.endIndex) } + @inlinable @inline(__always) + public func initializeAll(fromContentsOf source: UnsafeBufferPointer) { + assert(self.count == source.count) + guard source.count > 0 else { return } + self.baseAddress.unsafelyUnwrapped.initialize( + from: source.baseAddress.unsafelyUnwrapped, + count: source.count) + } + + @inlinable @inline(__always) + public func initializeAll(fromContentsOf source: Slice>) { + self.initializeAll(fromContentsOf: .init(rebasing: source)) + } + @inlinable @inline(__always) public func initializeAll(fromContentsOf source: Self) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) + self.initializeAll(fromContentsOf: UnsafeBufferPointer(source)) } @inlinable @inline(__always) public func initializeAll(fromContentsOf source: Slice) { - let i = self.initialize(fromContentsOf: source) - assert(i == self.endIndex) + self.initializeAll(fromContentsOf: UnsafeMutableBufferPointer(rebasing: source)) } +} +extension UnsafeMutableBufferPointer where Element: ~Copyable { @inlinable @inline(__always) public func moveInitializeAll(fromContentsOf source: Self) { let i = self.moveInitialize(fromContentsOf: source) assert(i == self.endIndex) } +} +extension UnsafeMutableBufferPointer { @inlinable @inline(__always) public func moveInitializeAll(fromContentsOf source: Slice) { let i = self.moveInitialize(fromContentsOf: source) diff --git a/Tests/DequeTests/DequeTests.swift b/Tests/DequeTests/DequeTests.swift index 34c947fe..d36cd641 100644 --- a/Tests/DequeTests/DequeTests.swift +++ b/Tests/DequeTests/DequeTests.swift @@ -176,16 +176,18 @@ final class DequeTests: CollectionTestCase { let d1 = Deque>( unsafeUninitializedCapacity: cap, initializingWith: { target, c in - expectNotNil(target.baseAddress) expectEqual(target.count, cap) expectEqual(c, 0) - contents.withUnsafeBufferPointer { source in - precondition(source.count <= target.count) - target.baseAddress!.initialize( - from: source.baseAddress!, - count: source.count) + if target.count > 0 { + expectNotNil(target.baseAddress) + contents.withUnsafeBufferPointer { source in + precondition(source.count <= target.count) + target.baseAddress!.initialize( + from: source.baseAddress!, + count: source.count) + } + c = count } - c = count }) expectEqualElements(d1, contents) } @@ -206,16 +208,18 @@ final class DequeTests: CollectionTestCase { try Deque>( unsafeUninitializedCapacity: cap, initializingWith: { target, c in - expectNotNil(target.baseAddress) expectEqual(target.count, cap) expectEqual(c, 0) - contents.withUnsafeBufferPointer { source in - precondition(source.count <= target.count) - target.baseAddress!.initialize( - from: source.baseAddress!, - count: source.count) + if target.count > 0 { + expectNotNil(target.baseAddress) + contents.withUnsafeBufferPointer { source in + precondition(source.count <= target.count) + target.baseAddress!.initialize( + from: source.baseAddress!, + count: source.count) + } + c = count } - c = count throw TestError(count) }) ) { error in diff --git a/Tests/FutureTests/DynoArrayTests.swift b/Tests/FutureTests/DynoArrayTests.swift new file mode 100644 index 00000000..67d285ec --- /dev/null +++ b/Tests/FutureTests/DynoArrayTests.swift @@ -0,0 +1,180 @@ +import XCTest +import _CollectionsTestSupport +import Future + +struct Counted: ~Copyable { + var value: Int + nonisolated(unsafe) static var instances: Int = 0 + + init(_ value: Int) { + self.value = value + Counted.instances += 1 + } + + deinit { + Counted.instances -= 1 + expectGreaterThanOrEqual(Counted.instances, 0) + } +} + +class DynoArrayTests: CollectionTestCase { + + func test_basics() { + var array = DynoArray() + expectTrue(array.isEmpty) + expectEqual(array.count, 0) + expectEqual(array.capacity, 0) + expectEqual(Counted.instances, 0) + + array.append(Counted(42)) + expectFalse(array.isEmpty) + expectEqual(array.count, 1) + expectEqual(array[0].value, 42) + expectEqual(Counted.instances, 1) + + array.append(Counted(23)) + expectFalse(array.isEmpty) + expectEqual(array.count, 2) + expectEqual(array[0].value, 42) + expectEqual(array[1].value, 23) + expectEqual(Counted.instances, 2) + + let old = array.remove(at: 0) + expectEqual(old.value, 42) + expectFalse(array.isEmpty) + expectEqual(array.count, 1) + expectEqual(array[0].value, 23) + expectEqual(Counted.instances, 2) + _ = consume old + expectEqual(Counted.instances, 1) + + let old2 = array.remove(at: 0) + expectEqual(old2.value, 23) + expectEqual(array.count, 0) + expectTrue(array.isEmpty) + expectEqual(Counted.instances, 1) + _ = consume old2 + expectEqual(Counted.instances, 0) + } + + func test_read_access() { + let c = 100 + let array = DynoArray(count: c) { Counted($0) } + + for i in 0 ..< c { + expectEqual(array.borrowElement(at: i) { $0.value }, i) + expectEqual(array[i].value, i) + } + } + + func test_update_access() { + let c = 100 + var array = DynoArray(count: c) { Counted($0) } + + for i in 0 ..< c { + array.updateElement(at: i) { $0.value += 100 } + array[i].value += 100 + } + + for i in 0 ..< c { + expectEqual(array[i].value, 200 + i) + } + + expectEqual(Counted.instances, c) + _ = consume array + expectEqual(Counted.instances, 0) + } + + func test_append() { + var array = DynoArray() + let c = 100 + for i in 0 ..< c { + array.append(Counted(100 + i)) + } + expectEqual(Counted.instances, c) + expectEqual(array.count, c) + + for i in 0 ..< c { + // FIXME: unexpected exclusivity violation (rdar://128441125) + //expectEqual(array.borrowElement(at: i) { $0.value }, 100 + i) + expectEqual(array[i].value, 100 + i) + } + + _ = consume array + expectEqual(Counted.instances, 0) + } + + func test_insert() { + var array = DynoArray() + let c = 100 + for i in 0 ..< c { + array.insert(Counted(100 + i), at: 0) + } + expectEqual(Counted.instances, c) + expectEqual(array.count, c) + + for i in 0 ..< c { + // FIXME: unexpected exclusivity violation (rdar://128441125) + //expectEqual(array.borrowElement(at: i) { $0.value }, c + 99 - i) + expectEqual(array[i].value, c + 99 - i) + } + + _ = consume array + expectEqual(Counted.instances, 0) + } + + func test_remove() { + let c = 100 + var array = DynoArray(count: c) { Counted(100 + $0) } + expectEqual(Counted.instances, c) + expectEqual(array.count, c) + + for i in 0 ..< c { + array.remove(at: 0) + expectEqual(array.count, c - 1 - i) + expectEqual(Counted.instances, c - 1 - i) + } + + expectTrue(array.isEmpty) + expectEqual(Counted.instances, 0) + } + + func test_iterate_full() { + let c = 100 + let array = DynoArray(count: c) { Counted(100 + $0) } + + var state = array.startBorrowingIteration() + do { + let span = state.nextChunk(maximumCount: Int.max) + expectEqual(span.count, c) + for i in 0 ..< span.count { + expectEqual(span[i].value, 100 + i) + } + } + do { + let span2 = state.nextChunk(maximumCount: Int.max) + expectEqual(span2.count, 0) + } + } + + func test_iterate_stepped() { + let c = 100 + let array = DynoArray(count: c) { Counted($0) } + + withEvery("stride", in: 1 ... c) { stride in + var state = array.startBorrowingIteration() + var i = 0 + while true { + let span = state.nextChunk(maximumCount: stride) + if span.count == 0 { break } + expectEqual(span.count, i + stride <= c ? stride : c % stride) + for j in 0 ..< span.count { + expectEqual(span[j].value, i) + i += 1 + } + } + expectEqual(i, c) + expectEqual(state.nextChunk(maximumCount: Int.max).count, 0) + } + } +} diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 2eaac634..49f9630c 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -12,8 +12,6 @@ 7D9B859929E4F74400B291CD /* BitArray+LosslessStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859329E4F74400B291CD /* BitArray+LosslessStringConvertible.swift */; }; 7D9B859A29E4F74400B291CD /* BitArray+RandomBits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859429E4F74400B291CD /* BitArray+RandomBits.swift */; }; 7D9B859B29E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9B859529E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift */; }; - 7DB0AE762B6E06B300602A20 /* Specialize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB0AE752B6E06B300602A20 /* Specialize.swift */; }; - 7DB0AE772B6E06B300602A20 /* Specialize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB0AE752B6E06B300602A20 /* Specialize.swift */; }; 7DE91B2F29CA6721004483EB /* Collections.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7DE91B2629CA6721004483EB /* Collections.framework */; }; 7DE9200D29CA70F3004483EB /* OrderedDictionary+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91E7529CA70F3004483EB /* OrderedDictionary+Equatable.swift */; }; 7DE9200E29CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91E7629CA70F3004483EB /* OrderedDictionary+ExpressibleByDictionaryLiteral.swift */; }; @@ -76,18 +74,14 @@ 7DE9204729CA70F3004483EB /* _HashTable+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB229CA70F3004483EB /* _HashTable+Testing.swift */; }; 7DE9204829CA70F3004483EB /* _HashTable+CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB329CA70F3004483EB /* _HashTable+CustomStringConvertible.swift */; }; 7DE9204929CA70F3004483EB /* _HashTable+BucketIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB429CA70F3004483EB /* _HashTable+BucketIterator.swift */; }; - 7DE9204B29CA70F3004483EB /* _DequeBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB729CA70F3004483EB /* _DequeBuffer.swift */; }; 7DE9204C29CA70F3004483EB /* Deque+Collection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EB829CA70F3004483EB /* Deque+Collection.swift */; }; 7DE9204E29CA70F3004483EB /* Deque+CustomReflectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBA29CA70F3004483EB /* Deque+CustomReflectable.swift */; }; 7DE9204F29CA70F3004483EB /* Deque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBB29CA70F3004483EB /* Deque.swift */; }; 7DE9205029CA70F3004483EB /* _DequeSlot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBC29CA70F3004483EB /* _DequeSlot.swift */; }; 7DE9205129CA70F3004483EB /* Deque+Hashable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBD29CA70F3004483EB /* Deque+Hashable.swift */; }; 7DE9205229CA70F3004483EB /* _UnsafeWrappedBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBE29CA70F3004483EB /* _UnsafeWrappedBuffer.swift */; }; - 7DE9205329CA70F3004483EB /* _DequeBufferHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EBF29CA70F3004483EB /* _DequeBufferHeader.swift */; }; - 7DE9205429CA70F3004483EB /* Deque+Sendable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC029CA70F3004483EB /* Deque+Sendable.swift */; }; 7DE9205529CA70F3004483EB /* Deque+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC129CA70F3004483EB /* Deque+Codable.swift */; }; 7DE9205629CA70F3004483EB /* Deque+Testing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC229CA70F3004483EB /* Deque+Testing.swift */; }; - 7DE9205829CA70F3004483EB /* Deque._UnsafeHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC429CA70F3004483EB /* Deque._UnsafeHandle.swift */; }; 7DE9205929CA70F3004483EB /* Deque+Descriptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC529CA70F3004483EB /* Deque+Descriptions.swift */; }; 7DE9205A29CA70F3004483EB /* Deque+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC629CA70F3004483EB /* Deque+Extras.swift */; }; 7DE9205B29CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91EC729CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift */; }; @@ -354,9 +348,6 @@ 7DE9221C29CA8576004483EB /* RangeReplaceableCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE921F729CA8576004483EB /* RangeReplaceableCollectionTests.swift */; }; 7DE9221D29CA8576004483EB /* DequeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE921F829CA8576004483EB /* DequeTests.swift */; }; 7DE9221E29CA8576004483EB /* MutableCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE921F929CA8576004483EB /* MutableCollectionTests.swift */; }; - 7DEBDAF229CBEE5300ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDACD29CBEE5200ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift */; }; - 7DEBDAF429CBEE5300ADC226 /* UnsafeMutablePointer+SE-0370.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDACF29CBEE5200ADC226 /* UnsafeMutablePointer+SE-0370.swift */; }; - 7DEBDAF529CBEE5300ADC226 /* UnsafeRawPointer extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD029CBEE5200ADC226 /* UnsafeRawPointer extensions.swift */; }; 7DEBDAF829CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */; }; 7DEBDAF929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */; }; 7DEBDAFA29CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */; }; @@ -373,9 +364,6 @@ 7DEBDB0F29CBF68900ADC226 /* UInt+reversed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE829CBEE5300ADC226 /* UInt+reversed.swift */; }; 7DEBDB1029CBF68900ADC226 /* UInt+first and last set bit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAEA29CBEE5300ADC226 /* UInt+first and last set bit.swift */; }; 7DEBDB1129CBF68900ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAEB29CBEE5300ADC226 /* FixedWidthInteger+roundUpToPowerOfTwo.swift */; }; - 7DEBDB1229CBF68D00ADC226 /* UnsafeMutablePointer+SE-0370.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDACF29CBEE5200ADC226 /* UnsafeMutablePointer+SE-0370.swift */; }; - 7DEBDB1429CBF68D00ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDACD29CBEE5200ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift */; }; - 7DEBDB1529CBF68D00ADC226 /* UnsafeRawPointer extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAD029CBEE5200ADC226 /* UnsafeRawPointer extensions.swift */; }; 7DEBDB1629CBF69F00ADC226 /* _UnsafeBitSet+Index.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDADF29CBEE5300ADC226 /* _UnsafeBitSet+Index.swift */; }; 7DEBDB1729CBF69F00ADC226 /* _UnsafeBitSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE029CBEE5300ADC226 /* _UnsafeBitSet.swift */; }; 7DEBDB1829CBF69F00ADC226 /* _UnsafeBitSet+_Word.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDAE129CBEE5300ADC226 /* _UnsafeBitSet+_Word.swift */; }; @@ -422,6 +410,20 @@ 7DEBDB9129CCE44A00ADC226 /* CollectionTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2429CCE43600ADC226 /* CollectionTestCase.swift */; }; 7DEBDB9229CCE44A00ADC226 /* StringConvertibleValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBDB2B29CCE43600ADC226 /* StringConvertibleValue.swift */; }; 7DEBDB9D29CCE73D00ADC226 /* Collections.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DE91F7B29CA70F3004483EB /* Collections.swift */; }; + 7DEBEC152C5AB45600A1BF15 /* DynamicDeque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC132C5AB45600A1BF15 /* DynamicDeque.swift */; }; + 7DEBEC162C5AB45600A1BF15 /* RigidDeque.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC142C5AB45600A1BF15 /* RigidDeque.swift */; }; + 7DEBEC172C5AB45600A1BF15 /* _UnsafeDequeHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC122C5AB45600A1BF15 /* _UnsafeDequeHandle.swift */; }; + 7DEBEC252C5AE43C00A1BF15 /* CMakeLists.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7DEBEC1E2C5AE43C00A1BF15 /* CMakeLists.txt */; }; + 7DEBEC262C5AE43C00A1BF15 /* RigidArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC1A2C5AE43C00A1BF15 /* RigidArray.swift */; }; + 7DEBEC272C5AE43C00A1BF15 /* DynamicArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC192C5AE43C00A1BF15 /* DynamicArray.swift */; }; + 7DEBEC282C5AE43C00A1BF15 /* Inout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC202C5AE43C00A1BF15 /* Inout.swift */; }; + 7DEBEC292C5AE43C00A1BF15 /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC182C5AE43C00A1BF15 /* Container.swift */; }; + 7DEBEC2A2C5AE43C00A1BF15 /* Box.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC1C2C5AE43C00A1BF15 /* Box.swift */; }; + 7DEBEC2B2C5AE43C00A1BF15 /* UnsafeBufferPointer+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC232C5AE43C00A1BF15 /* UnsafeBufferPointer+Additions.swift */; }; + 7DEBEC2C2C5AE43C00A1BF15 /* RawSpan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC212C5AE43C00A1BF15 /* RawSpan.swift */; }; + 7DEBEC2D2C5AE43C00A1BF15 /* Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC1D2C5AE43C00A1BF15 /* Cell.swift */; }; + 7DEBEC2E2C5AE43C00A1BF15 /* Span.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC222C5AE43C00A1BF15 /* Span.swift */; }; + 7DEBEC2F2C5AE43C00A1BF15 /* ContiguousStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DEBEC1F2C5AE43C00A1BF15 /* ContiguousStorage.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -448,8 +450,6 @@ 7D9B859429E4F74400B291CD /* BitArray+RandomBits.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+RandomBits.swift"; sourceTree = ""; }; 7D9B859529E4F74400B291CD /* BitArray+ExpressibleByStringLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BitArray+ExpressibleByStringLiteral.swift"; sourceTree = ""; }; 7D9B859C29E4F77D00B291CD /* Collections.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Collections.xctestplan; sourceTree = ""; }; - 7DB0AE712B6E067A00602A20 /* Specialize.swift.gyb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Specialize.swift.gyb; sourceTree = ""; }; - 7DB0AE752B6E06B300602A20 /* Specialize.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Specialize.swift; sourceTree = ""; }; 7DE91B2629CA6721004483EB /* Collections.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Collections.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7DE91B2E29CA6721004483EB /* CollectionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CollectionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 7DE91E7229CA70F3004483EB /* OrderedCollections.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = OrderedCollections.docc; sourceTree = ""; }; @@ -516,7 +516,6 @@ 7DE91EB329CA70F3004483EB /* _HashTable+CustomStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "_HashTable+CustomStringConvertible.swift"; sourceTree = ""; }; 7DE91EB429CA70F3004483EB /* _HashTable+BucketIterator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "_HashTable+BucketIterator.swift"; sourceTree = ""; }; 7DE91EB529CA70F3004483EB /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; - 7DE91EB729CA70F3004483EB /* _DequeBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _DequeBuffer.swift; sourceTree = ""; }; 7DE91EB829CA70F3004483EB /* Deque+Collection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Collection.swift"; sourceTree = ""; }; 7DE91EB929CA70F3004483EB /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; 7DE91EBA29CA70F3004483EB /* Deque+CustomReflectable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+CustomReflectable.swift"; sourceTree = ""; }; @@ -524,12 +523,9 @@ 7DE91EBC29CA70F3004483EB /* _DequeSlot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _DequeSlot.swift; sourceTree = ""; }; 7DE91EBD29CA70F3004483EB /* Deque+Hashable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Hashable.swift"; sourceTree = ""; }; 7DE91EBE29CA70F3004483EB /* _UnsafeWrappedBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _UnsafeWrappedBuffer.swift; sourceTree = ""; }; - 7DE91EBF29CA70F3004483EB /* _DequeBufferHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _DequeBufferHeader.swift; sourceTree = ""; }; - 7DE91EC029CA70F3004483EB /* Deque+Sendable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Sendable.swift"; sourceTree = ""; }; 7DE91EC129CA70F3004483EB /* Deque+Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Codable.swift"; sourceTree = ""; }; 7DE91EC229CA70F3004483EB /* Deque+Testing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Testing.swift"; sourceTree = ""; }; 7DE91EC329CA70F3004483EB /* DequeModule.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = DequeModule.docc; sourceTree = ""; }; - 7DE91EC429CA70F3004483EB /* Deque._UnsafeHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deque._UnsafeHandle.swift; sourceTree = ""; }; 7DE91EC529CA70F3004483EB /* Deque+Descriptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Descriptions.swift"; sourceTree = ""; }; 7DE91EC629CA70F3004483EB /* Deque+Extras.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+Extras.swift"; sourceTree = ""; }; 7DE91EC729CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Deque+ExpressibleByArrayLiteral.swift"; sourceTree = ""; }; @@ -815,12 +811,6 @@ 7DE921F729CA8576004483EB /* RangeReplaceableCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RangeReplaceableCollectionTests.swift; sourceTree = ""; }; 7DE921F829CA8576004483EB /* DequeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DequeTests.swift; sourceTree = ""; }; 7DE921F929CA8576004483EB /* MutableCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutableCollectionTests.swift; sourceTree = ""; }; - 7DEBDAC829CBEE5200ADC226 /* UnsafeMutablePointer+SE-0370.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UnsafeMutablePointer+SE-0370.swift.gyb"; sourceTree = ""; }; - 7DEBDAC929CBEE5200ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UnsafeMutableBufferPointer+SE-0370.swift.gyb"; sourceTree = ""; }; - 7DEBDACB29CBEE5200ADC226 /* UnsafeRawPointer extensions.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "UnsafeRawPointer extensions.swift.gyb"; sourceTree = ""; }; - 7DEBDACD29CBEE5200ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableBufferPointer+SE-0370.swift"; sourceTree = ""; }; - 7DEBDACF29CBEE5200ADC226 /* UnsafeMutablePointer+SE-0370.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeMutablePointer+SE-0370.swift"; sourceTree = ""; }; - 7DEBDAD029CBEE5200ADC226 /* UnsafeRawPointer extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeRawPointer extensions.swift"; sourceTree = ""; }; 7DEBDAD129CBEE5200ADC226 /* Descriptions.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Descriptions.swift.gyb; sourceTree = ""; }; 7DEBDAD229CBEE5200ADC226 /* RandomAccessCollection+Offsets.swift.gyb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "RandomAccessCollection+Offsets.swift.gyb"; sourceTree = ""; }; 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UnsafeMutableBufferPointer+Extras.swift"; sourceTree = ""; }; @@ -885,6 +875,20 @@ 7DEBDB9729CCE4A600ADC226 /* CollectionsTests.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CollectionsTests.xcconfig; sourceTree = ""; }; 7DEBDB9829CCE4A600ADC226 /* Shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Shared.xcconfig; sourceTree = ""; }; 7DEBDB9929CCE4A600ADC226 /* Collections.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Collections.xcconfig; sourceTree = ""; }; + 7DEBEC122C5AB45600A1BF15 /* _UnsafeDequeHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = _UnsafeDequeHandle.swift; sourceTree = ""; }; + 7DEBEC132C5AB45600A1BF15 /* DynamicDeque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicDeque.swift; sourceTree = ""; }; + 7DEBEC142C5AB45600A1BF15 /* RigidDeque.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidDeque.swift; sourceTree = ""; }; + 7DEBEC182C5AE43C00A1BF15 /* Container.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Container.swift; sourceTree = ""; }; + 7DEBEC192C5AE43C00A1BF15 /* DynamicArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicArray.swift; sourceTree = ""; }; + 7DEBEC1A2C5AE43C00A1BF15 /* RigidArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidArray.swift; sourceTree = ""; }; + 7DEBEC1C2C5AE43C00A1BF15 /* Box.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Box.swift; sourceTree = ""; }; + 7DEBEC1D2C5AE43C00A1BF15 /* Cell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cell.swift; sourceTree = ""; }; + 7DEBEC1E2C5AE43C00A1BF15 /* CMakeLists.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = ""; }; + 7DEBEC1F2C5AE43C00A1BF15 /* ContiguousStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContiguousStorage.swift; sourceTree = ""; }; + 7DEBEC202C5AE43C00A1BF15 /* Inout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Inout.swift; sourceTree = ""; }; + 7DEBEC212C5AE43C00A1BF15 /* RawSpan.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RawSpan.swift; sourceTree = ""; }; + 7DEBEC222C5AE43C00A1BF15 /* Span.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Span.swift; sourceTree = ""; }; + 7DEBEC232C5AE43C00A1BF15 /* UnsafeBufferPointer+Additions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeBufferPointer+Additions.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -938,13 +942,14 @@ children = ( 7DE91F2229CA70F3004483EB /* InternalCollectionsUtilities */, 7DE91F3929CA70F3004483EB /* BitCollections */, + 7DE91EB529CA70F3004483EB /* CMakeLists.txt */, 7DE91F7929CA70F3004483EB /* Collections */, 7DE91EB629CA70F3004483EB /* DequeModule */, + 7DEBEC242C5AE43C00A1BF15 /* Future */, 7DE91FA729CA70F3004483EB /* HashTreeCollections */, 7DE9200229CA70F3004483EB /* HeapModule */, 7DE91E7129CA70F3004483EB /* OrderedCollections */, 7DE91ECA29CA70F3004483EB /* RopeModule */, - 7DE91EB529CA70F3004483EB /* CMakeLists.txt */, ); name = Sources; path = ../Sources; @@ -1055,13 +1060,12 @@ 7DE91EB629CA70F3004483EB /* DequeModule */ = { isa = PBXGroup; children = ( - 7DE91EB729CA70F3004483EB /* _DequeBuffer.swift */, - 7DE91EBF29CA70F3004483EB /* _DequeBufferHeader.swift */, 7DE91EBC29CA70F3004483EB /* _DequeSlot.swift */, + 7DEBEC122C5AB45600A1BF15 /* _UnsafeDequeHandle.swift */, 7DE91EBE29CA70F3004483EB /* _UnsafeWrappedBuffer.swift */, - 7DE91EC929CA70F3004483EB /* Deque._Storage.swift */, - 7DE91EC429CA70F3004483EB /* Deque._UnsafeHandle.swift */, + 7DE91EB929CA70F3004483EB /* CMakeLists.txt */, 7DE91EBB29CA70F3004483EB /* Deque.swift */, + 7DE91EC929CA70F3004483EB /* Deque._Storage.swift */, 7DE91EC129CA70F3004483EB /* Deque+Codable.swift */, 7DE91EB829CA70F3004483EB /* Deque+Collection.swift */, 7DE91EBA29CA70F3004483EB /* Deque+CustomReflectable.swift */, @@ -1070,10 +1074,10 @@ 7DE91EC729CA70F3004483EB /* Deque+ExpressibleByArrayLiteral.swift */, 7DE91EC629CA70F3004483EB /* Deque+Extras.swift */, 7DE91EBD29CA70F3004483EB /* Deque+Hashable.swift */, - 7DE91EC029CA70F3004483EB /* Deque+Sendable.swift */, 7DE91EC229CA70F3004483EB /* Deque+Testing.swift */, 7DE91EC329CA70F3004483EB /* DequeModule.docc */, - 7DE91EB929CA70F3004483EB /* CMakeLists.txt */, + 7DEBEC132C5AB45600A1BF15 /* DynamicDeque.swift */, + 7DEBEC142C5AB45600A1BF15 /* RigidDeque.swift */, ); path = DequeModule; sourceTree = ""; @@ -1253,7 +1257,6 @@ isa = PBXGroup; children = ( 7DEBDAD329CBEE5300ADC226 /* autogenerated */, - 7DEBDAC729CBEE5200ADC226 /* Compatibility */, 7DEBDAE229CBEE5300ADC226 /* IntegerTricks */, 7DEBDADA29CBEE5300ADC226 /* UnsafeBitSet */, 7DE91F3029CA70F3004483EB /* _SortedCollection.swift */, @@ -1261,7 +1264,6 @@ 7DEBDAED29CBEE5300ADC226 /* Debugging.swift.gyb */, 7DEBDAD129CBEE5200ADC226 /* Descriptions.swift.gyb */, 7DEBDAD229CBEE5200ADC226 /* RandomAccessCollection+Offsets.swift.gyb */, - 7DB0AE712B6E067A00602A20 /* Specialize.swift.gyb */, 7DEBDAD929CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift.gyb */, 7DEBDAEC29CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift.gyb */, 7DE91F2E29CA70F3004483EB /* CMakeLists.txt */, @@ -1647,34 +1649,12 @@ path = DequeTests; sourceTree = ""; }; - 7DEBDAC729CBEE5200ADC226 /* Compatibility */ = { - isa = PBXGroup; - children = ( - 7DEBDACC29CBEE5200ADC226 /* autogenerated */, - 7DEBDAC929CBEE5200ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift.gyb */, - 7DEBDAC829CBEE5200ADC226 /* UnsafeMutablePointer+SE-0370.swift.gyb */, - 7DEBDACB29CBEE5200ADC226 /* UnsafeRawPointer extensions.swift.gyb */, - ); - path = Compatibility; - sourceTree = ""; - }; - 7DEBDACC29CBEE5200ADC226 /* autogenerated */ = { - isa = PBXGroup; - children = ( - 7DEBDACD29CBEE5200ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift */, - 7DEBDACF29CBEE5200ADC226 /* UnsafeMutablePointer+SE-0370.swift */, - 7DEBDAD029CBEE5200ADC226 /* UnsafeRawPointer extensions.swift */, - ); - path = autogenerated; - sourceTree = ""; - }; 7DEBDAD329CBEE5300ADC226 /* autogenerated */ = { isa = PBXGroup; children = ( 7DEBDAD829CBEE5300ADC226 /* Debugging.swift */, 7DEBDAD729CBEE5300ADC226 /* Descriptions.swift */, 7DEBDAD629CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift */, - 7DB0AE752B6E06B300602A20 /* Specialize.swift */, 7DEBDAD529CBEE5300ADC226 /* UnsafeBufferPointer+Extras.swift */, 7DEBDAD429CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift */, ); @@ -1813,6 +1793,32 @@ name = Xcode; sourceTree = ""; }; + 7DEBEC1B2C5AE43C00A1BF15 /* Containers */ = { + isa = PBXGroup; + children = ( + 7DEBEC182C5AE43C00A1BF15 /* Container.swift */, + 7DEBEC192C5AE43C00A1BF15 /* DynamicArray.swift */, + 7DEBEC1A2C5AE43C00A1BF15 /* RigidArray.swift */, + ); + path = Containers; + sourceTree = ""; + }; + 7DEBEC242C5AE43C00A1BF15 /* Future */ = { + isa = PBXGroup; + children = ( + 7DEBEC1B2C5AE43C00A1BF15 /* Containers */, + 7DEBEC1C2C5AE43C00A1BF15 /* Box.swift */, + 7DEBEC1D2C5AE43C00A1BF15 /* Cell.swift */, + 7DEBEC1E2C5AE43C00A1BF15 /* CMakeLists.txt */, + 7DEBEC1F2C5AE43C00A1BF15 /* ContiguousStorage.swift */, + 7DEBEC202C5AE43C00A1BF15 /* Inout.swift */, + 7DEBEC212C5AE43C00A1BF15 /* RawSpan.swift */, + 7DEBEC222C5AE43C00A1BF15 /* Span.swift */, + 7DEBEC232C5AE43C00A1BF15 /* UnsafeBufferPointer+Additions.swift */, + ); + path = Future; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -1870,7 +1876,7 @@ attributes = { BuildIndependentTargetsInParallel = 1; LastSwiftUpdateCheck = 1430; - LastUpgradeCheck = 1520; + LastUpgradeCheck = 1600; TargetAttributes = { 7DE91B2529CA6721004483EB = { CreatedOnToolsVersion = 14.3; @@ -1904,6 +1910,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7DEBEC252C5AE43C00A1BF15 /* CMakeLists.txt in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1925,7 +1932,6 @@ 7DE9214529CA70F4004483EB /* _HashNode+Structural symmetricDifference.swift in Sources */, 7DE9201029CA70F3004483EB /* OrderedDictionary+Deprecations.swift in Sources */, 7DE9205929CA70F3004483EB /* Deque+Descriptions.swift in Sources */, - 7DEBDAF529CBEE5300ADC226 /* UnsafeRawPointer extensions.swift in Sources */, 7DE9212729CA70F4004483EB /* TreeSet+Equatable.swift in Sources */, 7DE9213429CA70F4004483EB /* TreeSet+ExpressibleByArrayLiteral.swift in Sources */, 7DE9209729CA70F4004483EB /* _RopePath.swift in Sources */, @@ -2005,7 +2011,6 @@ 7DE9217629CA70F4004483EB /* TreeDictionary+Initializers.swift in Sources */, 7DE9207E29CA70F4004483EB /* BigString+UTF16View.swift in Sources */, 7DEBDAFA29CBEE5300ADC226 /* RandomAccessCollection+Offsets.swift in Sources */, - 7DB0AE762B6E06B300602A20 /* Specialize.swift in Sources */, 7DE9216F29CA70F4004483EB /* TreeDictionary+CustomReflectable.swift in Sources */, 7DE920D729CA70F4004483EB /* BitSet+SetAlgebra isSuperset.swift in Sources */, 7DE920F429CA70F4004483EB /* BitArray+Hashable.swift in Sources */, @@ -2028,6 +2033,9 @@ 7DE920E929CA70F4004483EB /* BitArray+Invariants.swift in Sources */, 7DE9215429CA70F4004483EB /* _HashNode+UnsafeHandle.swift in Sources */, 7DE9209829CA70F4004483EB /* Rope+_Node.swift in Sources */, + 7DEBEC152C5AB45600A1BF15 /* DynamicDeque.swift in Sources */, + 7DEBEC162C5AB45600A1BF15 /* RigidDeque.swift in Sources */, + 7DEBEC172C5AB45600A1BF15 /* _UnsafeDequeHandle.swift in Sources */, 7DE9204529CA70F3004483EB /* _HashTable+Constants.swift in Sources */, 7DE9214229CA70F4004483EB /* _HashStack.swift in Sources */, 7DE9206F29CA70F4004483EB /* BigString+Chunk+Breaks.swift in Sources */, @@ -2036,12 +2044,10 @@ 7DE920B529CA70F4004483EB /* _SortedCollection.swift in Sources */, 7DE9206929CA70F4004483EB /* BigString+Chunk+Indexing by UTF16.swift in Sources */, 7DE9202A29CA70F3004483EB /* OrderedSet+Partial SetAlgebra isSuperset.swift in Sources */, - 7DEBDAF229CBEE5300ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift in Sources */, 7DE9207D29CA70F4004483EB /* BigSubstring+UTF16View.swift in Sources */, 7DEBDAF829CBEE5300ADC226 /* UnsafeMutableBufferPointer+Extras.swift in Sources */, 7DE9217229CA70F4004483EB /* TreeDictionary+Sendable.swift in Sources */, 7DE9207729CA70F4004483EB /* Range+BigString.swift in Sources */, - 7DE9204B29CA70F3004483EB /* _DequeBuffer.swift in Sources */, 7DE920DF29CA70F4004483EB /* Slice+Utilities.swift in Sources */, 7DE9215729CA70F4004483EB /* _RawHashNode.swift in Sources */, 7DE9209529CA70F4004483EB /* RopeSummary.swift in Sources */, @@ -2101,12 +2107,21 @@ 7DE9203229CA70F3004483EB /* OrderedSet+Sendable.swift in Sources */, 7DE9206E29CA70F4004483EB /* BigString+Chunk+Splitting.swift in Sources */, 7DE920D829CA70F4004483EB /* BitSet+SetAlgebra subtracting.swift in Sources */, + 7DEBEC262C5AE43C00A1BF15 /* RigidArray.swift in Sources */, + 7DEBEC272C5AE43C00A1BF15 /* DynamicArray.swift in Sources */, + 7DEBEC282C5AE43C00A1BF15 /* Inout.swift in Sources */, + 7DEBEC292C5AE43C00A1BF15 /* Container.swift in Sources */, + 7DEBEC2A2C5AE43C00A1BF15 /* Box.swift in Sources */, + 7DEBEC2B2C5AE43C00A1BF15 /* UnsafeBufferPointer+Additions.swift in Sources */, + 7DEBEC2C2C5AE43C00A1BF15 /* RawSpan.swift in Sources */, + 7DEBEC2D2C5AE43C00A1BF15 /* Cell.swift in Sources */, + 7DEBEC2E2C5AE43C00A1BF15 /* Span.swift in Sources */, + 7DEBEC2F2C5AE43C00A1BF15 /* ContiguousStorage.swift in Sources */, 7DE9209E29CA70F4004483EB /* Rope+ForEachWhile.swift in Sources */, 7DE9217B29CA70F4004483EB /* Heap+Invariants.swift in Sources */, 7DE9212F29CA70F4004483EB /* TreeSet+SetAlgebra formIntersection.swift in Sources */, 7DE920A329CA70F4004483EB /* Rope+Index.swift in Sources */, 7DE9207329CA70F4004483EB /* BigString+RemoveSubrange.swift in Sources */, - 7DE9205829CA70F3004483EB /* Deque._UnsafeHandle.swift in Sources */, 7DE9213529CA70F4004483EB /* TreeSet+SetAlgebra symmetricDifference.swift in Sources */, 7DE920D429CA70F4004483EB /* BitSet+SetAlgebra union.swift in Sources */, 7DE920C329CA70F4004483EB /* BitSet+SetAlgebra formUnion.swift in Sources */, @@ -2161,14 +2176,12 @@ 7DE9216329CA70F4004483EB /* _HashLevel.swift in Sources */, 7D9B859729E4F74400B291CD /* BitArray+Shifts.swift in Sources */, 7DE9216C29CA70F4004483EB /* TreeDictionary+Descriptions.swift in Sources */, - 7DE9205429CA70F3004483EB /* Deque+Sendable.swift in Sources */, 7DE920A229CA70F4004483EB /* Rope+RemoveSubrange.swift in Sources */, 7DE920C729CA70F4004483EB /* BitSet+ExpressibleByArrayLiteral.swift in Sources */, 7DE9214929CA70F4004483EB /* _HashNode+Structural isEqualSet.swift in Sources */, 7DE9206729CA70F4004483EB /* BigString+Builder.swift in Sources */, 7DE9208B29CA70F4004483EB /* RopeMetric.swift in Sources */, 7DE9205A29CA70F3004483EB /* Deque+Extras.swift in Sources */, - 7DEBDAF429CBEE5300ADC226 /* UnsafeMutablePointer+SE-0370.swift in Sources */, 7DE9205129CA70F3004483EB /* Deque+Hashable.swift in Sources */, 7DE9209929CA70F4004483EB /* Rope+Extract.swift in Sources */, 7DE9202629CA70F3004483EB /* OrderedSet+Partial SetAlgebra isStrictSubset.swift in Sources */, @@ -2178,7 +2191,6 @@ 7DEBDB0229CBEE5300ADC226 /* _UnsafeBitSet.swift in Sources */, 7DE9214329CA70F4004483EB /* _HashNode+Subtree Removals.swift in Sources */, 7DE9207929CA70F4004483EB /* BigString+UnicodeScalarView.swift in Sources */, - 7DE9205329CA70F3004483EB /* _DequeBufferHeader.swift in Sources */, 7DE9202429CA70F3004483EB /* OrderedSet+Invariants.swift in Sources */, 7DE920A729CA70F4004483EB /* _CharacterRecognizer.swift in Sources */, 7DE920A429CA70F4004483EB /* Rope+Sequence.swift in Sources */, @@ -2259,7 +2271,6 @@ 7DE9221429CA8576004483EB /* OrderedSet Diffing Tests.swift in Sources */, 7DEBDB1D29CBF6B200ADC226 /* RandomAccessCollection+Offsets.swift in Sources */, 7DEBDB8529CCE44A00ADC226 /* AllOnesRandomNumberGenerator.swift in Sources */, - 7DEBDB1429CBF68D00ADC226 /* UnsafeMutableBufferPointer+SE-0370.swift in Sources */, 7DE921FD29CA8576004483EB /* CombinatoricsChecks.swift in Sources */, 7DEBDB8B29CCE44A00ADC226 /* _CollectionState.swift in Sources */, 7DE9220229CA8576004483EB /* TreeDictionary Tests.swift in Sources */, @@ -2288,12 +2299,10 @@ 7DEBDB7D29CCE44A00ADC226 /* MinimalRangeReplaceableRandomAccessCollection.swift in Sources */, 7DEBDB8E29CCE44A00ADC226 /* Integer Square Root.swift in Sources */, 7DE9221E29CA8576004483EB /* MutableCollectionTests.swift in Sources */, - 7DEBDB1229CBF68D00ADC226 /* UnsafeMutablePointer+SE-0370.swift in Sources */, 7DE9221529CA8576004483EB /* RandomAccessCollection+Extras.swift in Sources */, 7DEBDB7929CCE44A00ADC226 /* LifetimeTracked.swift in Sources */, 7DE921FC29CA8576004483EB /* IndexRangeCollectionTests.swift in Sources */, 7DE9221229CA8576004483EB /* OrderedDictionary+Elements Tests.swift in Sources */, - 7DB0AE772B6E06B300602A20 /* Specialize.swift in Sources */, 7DEBDB7629CCE44A00ADC226 /* MinimalIndex.swift in Sources */, 7DE9221329CA8576004483EB /* OrderedSetInternals.swift in Sources */, 7DE9220329CA8576004483EB /* Colliders.swift in Sources */, @@ -2325,7 +2334,6 @@ 7DEBDB1829CBF69F00ADC226 /* _UnsafeBitSet+_Word.swift in Sources */, 7DE921B929CA81DC004483EB /* _SortedCollection.swift in Sources */, 7DEBDB1629CBF69F00ADC226 /* _UnsafeBitSet+Index.swift in Sources */, - 7DEBDB1529CBF68D00ADC226 /* UnsafeRawPointer extensions.swift in Sources */, 7DEBDB7B29CCE44A00ADC226 /* IndexRangeCollection.swift in Sources */, 7DE9221929CA8576004483EB /* HeapTests.swift in Sources */, 7DEBDB1729CBF69F00ADC226 /* _UnsafeBitSet.swift in Sources */, @@ -2388,7 +2396,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = 7DEBDB9729CCE4A600ADC226 /* CollectionsTests.xcconfig */; buildSettings = { - DEAD_CODE_STRIPPING = YES; }; name = Debug; }; @@ -2396,7 +2403,6 @@ isa = XCBuildConfiguration; baseConfigurationReference = 7DEBDB9729CCE4A600ADC226 /* CollectionsTests.xcconfig */; buildSettings = { - DEAD_CODE_STRIPPING = YES; }; name = Release; }; diff --git a/Xcode/Collections.xcodeproj/xcshareddata/xcschemes/Collections.xcscheme b/Xcode/Collections.xcodeproj/xcshareddata/xcschemes/Collections.xcscheme index 3266c5aa..88230e52 100644 --- a/Xcode/Collections.xcodeproj/xcshareddata/xcschemes/Collections.xcscheme +++ b/Xcode/Collections.xcodeproj/xcshareddata/xcschemes/Collections.xcscheme @@ -1,6 +1,6 @@