From 1522a8a85d3a5627bf7683435cbafc4c51b23def Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 21 Oct 2026 19:39:30 -0700 Subject: [PATCH] RigidArray, UniqueArray: Deprecate ancient span methods --- .../RigidArray+ContainerOperations.swift | 46 ++++++++- .../RigidArray/RigidArray+Deprecated.swift | 50 ++++++++++ .../RigidArray/RigidArray.swift | 95 ------------------- .../UniqueArray+ContainerOperations.swift | 25 +++++ .../UniqueArray/UniqueArray+Deprecated.swift | 33 +++++++ .../UniqueArray/UniqueArray.swift | 78 --------------- 6 files changed, 153 insertions(+), 174 deletions(-) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+ContainerOperations.swift b/Sources/BasicContainers/RigidArray/RigidArray+ContainerOperations.swift index f6c346eb..9f90ed3e 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+ContainerOperations.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+ContainerOperations.swift @@ -305,6 +305,17 @@ extension RigidArray where Element: ~Copyable { index._advance(by: &n, limitedBy: limit) } + /// Return a borrowing span over the maximal storage chunk following the + /// specified position in the array. + /// + /// The returned span provides direct read-only access to all array elements + /// in the range `index ..< count`. + /// + /// - Parameter index: A valid index in the array, including the end index. + /// When `span(after:)` returns, `index` is equal to the array's + /// `endIndex`. + /// + /// - Complexity: O(1) @inlinable @_lifetime(borrow self) public func nextSpan( @@ -429,6 +440,28 @@ extension RigidArray where Element: ~Copyable { before: index, maxDistance: maxDistance, limitedBy: limit) } + /// Return a borrowing span over the maximal storage chunk preceding the + /// specified position in the array. + /// + /// The returned span provides direct read-only access to all array elements + /// in the range `0 ..< index`. + /// + /// - Parameter index: A valid index in the array, including the end index. + /// When `span(before:)` returns, `index` is equal to the array's + /// `startIndex`. + /// + /// - Complexity: O(1) + @_alwaysEmitIntoClient + @_lifetime(borrow self) + public func previousSpan( + before index: inout Int + ) -> Span { + // FIXME: Remove this in favor of the BidirectionalContainer algorithm. + _checkValidIndex(index) + defer { index = 0 } + return _span(in: unsafe Range(uncheckedBounds: (0, index))) + } + @_alwaysEmitIntoClient @_lifetime(borrow self) public func previousSpan( @@ -439,6 +472,17 @@ extension RigidArray where Element: ~Copyable { precondition(maxCount > 0, "maxCount must be positive") let start = index index = start &- Swift.min(maxCount, start) - return _span(in: unsafe Range(uncheckedBounds: (start, index))) + return _span(in: unsafe Range(uncheckedBounds: (index, start))) + } + + @_alwaysEmitIntoClient + @_lifetime(&self) + public mutating func previousMutableSpan( + before index: inout Int + ) -> MutableSpan { + // FIXME: Remove this in favor of the BidirectionalContainer algorithm. + _checkValidIndex(index) + defer { index = 0 } + return _mutableSpan(in: unsafe Range(uncheckedBounds: (0, index))) } } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift index 57b2abc1..c946d4a5 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift @@ -13,6 +13,56 @@ @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + @available(*, deprecated, renamed: "nextSpan(after:)") + @inlinable + @_lifetime(borrow self) + public func span(after index: inout Int) -> Span { + self.nextSpan(after: &index) + } + + @available(*, deprecated, renamed: "previousSpan(before:)") + @inlinable + @_lifetime(borrow self) + public func span(before index: inout Int) -> Span { + previousSpan(before: &index) + } + +#if COLLECTIONS_SINGLE_MODULE // FIXME: Remove when references have been flushed + @available(*, unavailable) + @usableFromInline + internal func _contiguousSubrange(following index: inout Int) -> Range { + precondition(index >= 0 && index <= count, "Index out of bounds") + defer { index = count } + return unsafe Range(uncheckedBounds: (index, count)) + } + + @available(*, unavailable) + @usableFromInline + internal func _contiguousSubrange(preceding index: inout Int) -> Range { + precondition(index >= 0 && index <= count, "Index out of bounds") + defer { index = 0 } + return unsafe Range(uncheckedBounds: (0, index)) + } +#endif + + @available(*, deprecated, renamed: "nextMutableSpan(after:)") + @_lifetime(&self) + @inlinable + public mutating func mutableSpan( + after index: inout Int + ) -> MutableSpan { + nextMutableSpan(after: &index) + } + + @available(*, deprecated, renamed: "previousMutableSpan(before:)") + @_lifetime(&self) + @inlinable + public mutating func mutableSpan( + before index: inout Int + ) -> MutableSpan { + previousMutableSpan(before: &index) + } + @available(*, deprecated, renamed: "nextSpan(after:maxCount:)") @inlinable @_lifetime(borrow self) diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index a8c4b233..a9c7860e 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -263,101 +263,6 @@ extension RigidArray where Element: ~Copyable { } } -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - @inlinable - internal func _contiguousSubrange(following index: inout Int) -> Range { - precondition(index >= 0 && index <= count, "Index out of bounds") - defer { index = count } - return unsafe Range(uncheckedBounds: (index, count)) - } - - @inlinable - internal func _contiguousSubrange(preceding index: inout Int) -> Range { - precondition(index >= 0 && index <= count, "Index out of bounds") - defer { index = 0 } - return unsafe Range(uncheckedBounds: (0, index)) - } -} - -//MARK: - Container primitives - -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - /// Return a borrowing span over the maximal storage chunk following the - /// specified position in the array. - /// - /// The returned span provides direct read-only access to all array elements - /// in the range `index ..< count`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `span(after:)` returns, `index` is equal to the array's - /// `endIndex`. - /// - /// - Complexity: O(1) - @inlinable - @_lifetime(borrow self) - public func span(after index: inout Int) -> Span { - _span(in: _contiguousSubrange(following: &index)) - } - - /// Return a borrowing span over the maximal storage chunk preceding the - /// specified position in the array. - /// - /// The returned span provides direct read-only access to all array elements - /// in the range `0 ..< index`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `span(before:)` returns, `index` is equal to the array's - /// `startIndex`. - /// - /// - Complexity: O(1) - @inlinable - @_lifetime(borrow self) - public func span(before index: inout Int) -> Span { - _span(in: _contiguousSubrange(preceding: &index)) - } -} - -@available(SwiftStdlib 5.0, *) -extension RigidArray where Element: ~Copyable { - /// Return a mutable span over the maximal storage chunk following the - /// specified position in the array. - /// - /// The returned span provides direct mutating access to all array elements - /// in the range `index ..< count`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `mutableSpan(after:)` returns, `index` is equal to the array's - /// `endIndex`. - /// - /// - Complexity: O(1) - @_lifetime(&self) - public mutating func mutableSpan( - after index: inout Int - ) -> MutableSpan { - _mutableSpan(in: _contiguousSubrange(following: &index)) - } - - /// Return a mutable span over the maximal storage chunk preceding the specified - /// position in the array. - /// - /// The returned span provides direct mutating access to all array elements - /// in the range `0 ..< index`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `mutableSpan(before:)` returns, `index` is equal to the array's - /// `startIndex`. - /// - /// - Complexity: O(1) - @_lifetime(&self) - public mutating func mutableSpan( - before index: inout Int - ) -> MutableSpan { - _mutableSpan(in: _contiguousSubrange(preceding: &index)) - } -} - //MARK: - Resizing @available(SwiftStdlib 5.0, *) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+ContainerOperations.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+ContainerOperations.swift index a68fe5d9..e13ec5a9 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+ContainerOperations.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+ContainerOperations.swift @@ -346,6 +346,14 @@ extension UniqueArray where Element: ~Copyable { _storage.nextSpan(after: &index, maxCount: maxCount, limitedBy: limit) } + @_alwaysEmitIntoClient + @_lifetime(&self) + public mutating func nextMutableSpan( + after index: inout Int + ) -> MutableSpan { + _storage.nextMutableSpan(after: &index) + } + @inlinable @_lifetime(&self) public mutating func nextMutableSpan( @@ -369,6 +377,15 @@ extension UniqueArray where Element: ~Copyable { before: index, maxDistance: maxDistance, limitedBy: limit) } + @_alwaysEmitIntoClient + @_lifetime(borrow self) + public func previousSpan( + before index: inout Int + ) -> Span { + // FIXME: Remove this in favor of the BidirectionalContainer algorithm. + _storage.previousSpan(before: &index) + } + @_alwaysEmitIntoClient @_lifetime(borrow self) public func previousSpan( @@ -377,4 +394,12 @@ extension UniqueArray where Element: ~Copyable { // FIXME: Remove this in favor of the BidirectionalContainer algorithm. _storage.previousSpan(before: &index, maxCount: maxCount) } + + @_alwaysEmitIntoClient + @_lifetime(&self) + public mutating func previousMutableSpan( + before index: inout Int + ) -> MutableSpan { + _storage.previousMutableSpan(before: &index) + } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift index 1dbedc4d..f58f8fe8 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift @@ -17,6 +17,21 @@ import SpanPreview @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { + @available(*, deprecated, renamed: "nextSpan(after:)") + @inlinable + @inline(__always) + @_lifetime(borrow self) + public func span(after index: inout Int) -> Span { + nextSpan(after: &index) + } + + @available(*, deprecated, renamed: "nextSpan(after:)") + @inlinable + @_lifetime(borrow self) + public func span(before index: inout Int) -> Span { + previousSpan(before: &index) + } + @available(*, deprecated, renamed: "nextSpan(after:maxCount:)") @inlinable @_lifetime(borrow self) @@ -29,6 +44,24 @@ extension UniqueArray where Element: ~Copyable { limitedBy: self.endIndex) } + @available(*, deprecated, renamed: "nextMutableSpan(after:)") + @_lifetime(&self) + @inlinable + public mutating func mutableSpan( + after index: inout Int + ) -> MutableSpan { + self.nextMutableSpan(after: &index) + } + + @available(*, deprecated, renamed: "previousMutableSpan(before:)") + @_lifetime(&self) + @inlinable + public mutating func mutableSpan( + before index: inout Int + ) -> MutableSpan { + self.previousMutableSpan(before: &index) + } + @available(*, deprecated, renamed: "nextMutableSpan(after:maxCount:)") @inlinable @_lifetime(&self) diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index e6e29076..8fc73873 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -155,84 +155,6 @@ extension UniqueArray where Element: ~Copyable { } } -//MARK: - Container primitives - -@available(SwiftStdlib 5.0, *) -extension UniqueArray where Element: ~Copyable { - /// Return a borrowing span over the maximal storage chunk following the - /// specified position in the array. - /// - /// The returned span provides direct read-only access to all array elements - /// in the range `index ..< count`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `span(after:)` returns, `index` is equal to the array's - /// `endIndex`. - /// - /// - Complexity: O(1) - @inlinable - @_lifetime(borrow self) - public func span(after index: inout Int) -> Span { - _storage.span(after: &index) - } - - /// Return a borrowing span over the maximal storage chunk preceding the - /// specified position in the array. - /// - /// The returned span provides direct read-only access to all array elements - /// in the range `0 ..< index`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `span(before:)` returns, `index` is equal to the array's - /// `startIndex`. - /// - /// - Complexity: O(1) - @inlinable - @_lifetime(borrow self) - public func span(before index: inout Int) -> Span { - _storage.span(before: &index) - } -} - -@available(SwiftStdlib 5.0, *) -extension UniqueArray where Element: ~Copyable { - /// Return a mutable span over the maximal storage chunk following the - /// specified position in the array. - /// - /// The returned span provides direct mutating access to all array elements - /// in the range `index ..< count`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `mutableSpan(after:)` returns, `index` is equal to the array's - /// `endIndex`. - /// - /// - Complexity: O(1) - @_lifetime(&self) - public mutating func mutableSpan( - after index: inout Int - ) -> MutableSpan { - _storage.mutableSpan(after: &index) - } - - /// Return a mutable span over the maximal storage chunk preceding the specified - /// position in the array. - /// - /// The returned span provides direct mutating access to all array elements - /// in the range `0 ..< index`. - /// - /// - Parameter index: A valid index in the array, including the end index. - /// When `mutableSpan(before:)` returns, `index` is equal to the array's - /// `startIndex`. - /// - /// - Complexity: O(1) - @_lifetime(&self) - public mutating func mutableSpan( - before index: inout Int - ) -> MutableSpan { - _storage.mutableSpan(before: &index) - } -} - //MARK: - Resizing @_alwaysEmitIntoClient