From bb0dc189efd298e115c4555a6dce0821541a6e31 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Wed, 1 Jul 2026 17:39:08 -0700 Subject: [PATCH] =?UTF-8?q?maximumCount=20=E2=86=92=20maxCount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While we’re here, adjust `RigidSet.insert(maximumCount:initializingWith:)` and similar APIs to be consistent with RangeReplaceableContainer’s methods. --- Sources/BasicContainers/CMakeLists.txt | 1 + .../HashTable/_HTable+Deprecated.swift | 63 +++++++++++++++++++ .../HashTable/_HTable+Iteration.swift | 22 +++---- .../RigidArray/RigidArray+Consumption.swift | 4 +- .../RigidArray/RigidArray+Container.swift | 38 +++++------ .../RigidArray/RigidArray+Deprecated.swift | 27 ++++++++ .../RigidArray/RigidArray+Replacements.swift | 4 +- .../RigidDictionary+Indices.swift | 4 +- .../RigidSet/RigidSet+BorrowingSequence.swift | 8 +-- .../RigidSet/RigidSet+Deprecated.swift | 63 +++++++++++++++++++ .../RigidSet/RigidSet+Initializers.swift | 6 +- .../RigidSet/RigidSet+Insertions.swift | 40 ++++++++---- .../UniqueArray/UniqueArray+Container.swift | 30 ++++----- .../UniqueArray/UniqueArray+Deprecated.swift | 27 ++++++++ .../UniqueArray+Replacements.swift | 6 +- .../UniqueSet/UniqueSet+Deprecations.swift | 30 +++++++++ .../UniqueSet/UniqueSet+Initializers.swift | 2 +- .../UniqueSet/UniqueSet+Insertions.swift | 11 ++-- .../BitArray+ChunkedBitsIterators.swift | 6 +- .../BitArray/BitArray+Copy.swift | 2 +- .../BitArray+RangeReplaceableCollection.swift | 2 +- Sources/ContainersPreview/CMakeLists.txt | 2 +- .../Conformances/InputSpan+Container.swift | 18 +++--- .../Conformances/MutableSpan+Container.swift | 18 +++--- .../Conformances/OutputSpan+Container.swift | 18 +++--- .../Conformances/Span+Container.swift | 12 ++-- ...rowingIteratorProtocol+ElementsEqual.swift | 4 +- .../BorrowingIteratorProtocol+Filter.swift | 4 +- .../BorrowingIteratorProtocol+Map.swift | 4 +- .../BorrowingIteratorProtocol+MapError.swift | 4 +- ...orrowingIteratorProtocol+SpanwiseZip.swift | 4 +- .../Protocols/BorrowingIteratorProtocol.swift | 14 ++--- .../Container/BidirectionalContainer.swift | 12 ++-- .../Container/Container+Filter.swift | 6 +- .../Protocols/Container/Container.swift | 28 ++++----- .../Container/ContainerIterator.swift | 4 +- .../Container/MutableContainer.swift | 22 +++---- .../Container/RangeReplaceableContainer.swift | 28 +++------ .../Protocols/Drain+Map.swift | 2 +- .../ContainersPreview/Protocols/Drain.swift | 18 +++--- .../Protocols/Iterable+Algorithms.swift | 4 +- .../Iterable+Standard Conformances.swift | 4 +- .../Protocols/Iterable+Utilities.swift | 2 +- .../Protocols/Producer.swift | 12 ++-- ...+Extras.swift => OutputSpan+Helpers.swift} | 0 .../Types/SpanIterator.swift | 4 +- .../Deque/Deque._UnsafeHandle.swift | 4 +- .../RigidDeque/RigidDeque+Consumption.swift | 4 +- .../RigidDeque/RigidDeque+Container.swift | 22 +++---- .../RigidDeque/RigidDeque+Prepend.swift | 4 +- .../RigidDeque/RigidDeque+Replacements.swift | 2 +- .../UniqueDeque/UniqueDeque+Container.swift | 12 ++-- .../UniqueDeque/UniqueDeque+Prepend.swift | 2 +- .../BigString/Views/BigString+UTF8View.swift | 2 +- .../RigidArrayTests.swift | 2 +- .../BasicContainersTests/RigidSetTests.swift | 18 +++--- .../BorrowingSequenceTests.swift | 2 +- Tests/DequeTests/RigidDequeCrashTests.swift | 10 +-- Tests/DequeTests/RigidDequeTests.swift | 6 +- .../Assertions+Containers.swift | 4 +- .../ConformanceCheckers/CheckContainer.swift | 4 +- .../MinimalTypes/CustomDrain.swift | 4 +- .../MinimalTypes/StaccatoContainer.swift | 14 ++--- Xcode/Collections.xcodeproj/project.pbxproj | 20 ++++-- 64 files changed, 505 insertions(+), 275 deletions(-) create mode 100644 Sources/BasicContainers/HashTable/_HTable+Deprecated.swift create mode 100644 Sources/BasicContainers/RigidSet/RigidSet+Deprecated.swift create mode 100644 Sources/BasicContainers/UniqueSet/UniqueSet+Deprecations.swift rename Sources/ContainersPreview/Types/{OutputSpan+Extras.swift => OutputSpan+Helpers.swift} (100%) diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index 29bc573c..ceeb6e37 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -57,6 +57,7 @@ target_sources(${module_name} PRIVATE "HashTable/_HTable+Bucket.swift" "HashTable/_HTable+Consumption.swift" "HashTable/_HTable+Debug.swift" + "HashTable/_HTable+Deprecated.swift" "HashTable/_HTable+Find.swift" "HashTable/_HTable+Insert.swift" "HashTable/_HTable+Iteration.swift" diff --git a/Sources/BasicContainers/HashTable/_HTable+Deprecated.swift b/Sources/BasicContainers/HashTable/_HTable+Deprecated.swift new file mode 100644 index 00000000..449d93db --- /dev/null +++ b/Sources/BasicContainers/HashTable/_HTable+Deprecated.swift @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception +// +//===----------------------------------------------------------------------===// + +#if COLLECTIONS_SINGLE_MODULE + +#if compiler(>=6.2) +extension _HTable.BucketIterator { + // FIXME: Remove after 27.0 releases + @available(*, deprecated, renamed: "advanceToOccupied(maxCount:)") + @usableFromInline + @discardableResult + @_lifetime(self: copy self) + internal mutating func advanceToOccupied( + maximumCount: Int + ) -> Bool { + self.advanceToOccupied(maxCount: maximumCount) + } + + // FIXME: Remove after 27.0 releases + @available(*, deprecated, renamed: "advanceToUnoccupied(maxCount:)") + @usableFromInline + @discardableResult + @_lifetime(self: copy self) + internal mutating func advanceToUnoccupied( + maximumCount: Int + ) -> Bool { + self.advanceToUnoccupied(maxCount: maximumCount) + } + + // FIXME: Remove after 27.0 releases + @available(*, deprecated, renamed: "nextOccupiedRegion(maxCount:)") + @usableFromInline + @_lifetime(self: copy self) + internal mutating func nextOccupiedRegion( + maximumCount: Int + ) -> Range? { + self.nextOccupiedRegion(maxCount: maximumCount) + } + + // FIXME: Remove after 27.0 releases + @available(*, deprecated, renamed: "nextUnoccupiedRegion(maxCount:)") + @usableFromInline + @_lifetime(self: copy self) + internal mutating func nextUnoccupiedRegion( + maximumCount: Int + ) -> Range? { + self.nextUnoccupiedRegion(maxCount: maximumCount) + } +} +#endif + +#endif + diff --git a/Sources/BasicContainers/HashTable/_HTable+Iteration.swift b/Sources/BasicContainers/HashTable/_HTable+Iteration.swift index 2905a889..728ee918 100644 --- a/Sources/BasicContainers/HashTable/_HTable+Iteration.swift +++ b/Sources/BasicContainers/HashTable/_HTable+Iteration.swift @@ -232,9 +232,9 @@ extension _HTable.BucketIterator { @discardableResult @_lifetime(self: copy self) package mutating func advanceToOccupied( - maximumCount: Int + maxCount: Int ) -> Bool { - var remainder = UInt(bitPattern: maximumCount) + var remainder = UInt(bitPattern: maxCount) if isAtEnd { return false } if _words == nil { let delta = Swift.min(_endBucket._offset &- _bucket._offset, remainder) @@ -309,11 +309,11 @@ extension _HTable.BucketIterator { @discardableResult @_lifetime(self: copy self) package mutating func advanceToUnoccupied( - maximumCount: Int + maxCount: Int ) -> Bool { - assert(maximumCount > 0) + assert(maxCount > 0) assert(!isAtEnd) - var remainder = UInt(bitPattern: maximumCount) + var remainder = UInt(bitPattern: maxCount) if _words == nil { let delta = Swift.min(_endBucket._offset &- _bucket._offset, remainder) _bucket._offset &+= delta @@ -363,13 +363,13 @@ extension _HTable.BucketIterator { @usableFromInline @_lifetime(self: copy self) package mutating func nextOccupiedRegion( - maximumCount: Int = .max + maxCount: Int = .max ) -> Range? { - assert(maximumCount > 0) + assert(maxCount > 0) guard self.advanceToOccupied() else { return nil } assert(self.isOccupied) let start = self.currentBucket - self.advanceToUnoccupied(maximumCount: maximumCount) + self.advanceToUnoccupied(maxCount: maxCount) let end = self.currentBucket return Range(uncheckedBounds: (start, end)) } @@ -377,13 +377,13 @@ extension _HTable.BucketIterator { @usableFromInline @_lifetime(self: copy self) package mutating func nextUnoccupiedRegion( - maximumCount: Int = .max + maxCount: Int = .max ) -> Range? { - assert(maximumCount > 0) + assert(maxCount > 0) guard self.advanceToUnoccupied() else { return nil } assert(!self.isOccupied) let start = self.currentBucket - self.advanceToOccupied(maximumCount: maximumCount) + self.advanceToOccupied(maxCount: maxCount) let end = self.currentBucket return Range(uncheckedBounds: (start, end)) } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift b/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift index 096569e0..2447d23f 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Consumption.swift @@ -205,11 +205,11 @@ extension RigidArray.SubrangeConsumer where Element: ~Copyable { @inlinable @_lifetime(&self) @_lifetime(self: copy self) - public mutating func drainNext(maximumCount: Int) -> InputSpan { + public mutating func drainNext(maxCount: Int) -> InputSpan { if _remainder.isEmpty { return .init() } - let buffer = _remainder._trim(first: maximumCount) + let buffer = _remainder._trim(first: maxCount) return _overrideLifetime( InputSpan(buffer: buffer, initializedCount: buffer.count), mutating: &self) diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index d2aa4ae1..8b825fe2 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -324,7 +324,7 @@ extension RigidArray where Element: ~Copyable { /// Return a span over the array's storage that begins with the element at /// the given index, and extends to the end of the contiguous storage chunk - /// that contains it, but no more than `maximumCount` items. + /// that contains it, but no more than `maxCount` items. /// /// On return, the index is updated to address the next item following the /// end of the returned span. @@ -335,30 +335,30 @@ extension RigidArray where Element: ~Copyable { /// /// var index = items.startIndex /// while true { - /// let span = items.nextSpan(after: &index, maximumCount: 4) + /// let span = items.nextSpan(after: &index, maxCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// The `maximumCount` argument gives the caller control over the number of + /// The `maxCount` argument gives the caller control over the number of /// items it receives from the iterator. This lets the caller avoid getting /// more elements than it would be able to immediately process, which would /// significantly complicate container use. /// /// If the caller is able to process any number available items, it can signal - /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// that by passing `Int.max` as the `maxCount`, or simply by calling the /// `nexSpan(after:)` method, which does precisely that. This is frequently /// the case when the caller simply wants to iterate over the entire /// container in a single loop. /// - /// `maximumCount` sets an upper bound. To read a specific number of items, + /// `maxCount` sets an upper bound. To read a specific number of items, /// the caller usually needs to invoke `nextSpan` in a loop: /// /// var items: some Container /// var index = items.startIndex /// var remainder = numberOfItemsToRead /// while remainder > 0 { - /// let next = items.nextSpan(after: &index, maximumCount: remainder) + /// let next = items.nextSpan(after: &index, maxCount: remainder) /// guard !next.isEmpty else { /// // Container does not have enough items /// break @@ -381,10 +381,10 @@ extension RigidArray where Element: ~Copyable { /// - Parameter index: A valid index in the container, including the end /// index. On return, this index is advanced by the count of the resulting /// span, to simplify iteration. - /// - Parameter maximumCount: The maximum number of items the caller is able - /// to process immediately. `maximumCount` must be greater than zero. + /// - Parameter maxCount: The maximum number of items the caller is able + /// to process immediately. `maxCount` must be greater than zero. /// If you are able to process an arbitrary number of items, set - /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// `maxCount` to `Int.max`, or call the `nextSpan(after:)` method. /// - Returns: A span over contiguous storage that starts at the given index. /// If the input index is the end index, then this returns an empty span. /// Otherwise the result is non-empty, with its first element matching the @@ -393,34 +393,36 @@ extension RigidArray where Element: ~Copyable { @inlinable @_lifetime(borrow self) public func nextSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> Span { _checkValidIndex(index) - precondition(maximumCount > 0, "maximumCount must be positive") + precondition(maxCount > 0, "maxCount must be positive") let start = index - index = start &+ Swift.min(maximumCount, _count &- start) + index = start &+ Swift.min(maxCount, _count &- start) return _span(in: Range(uncheckedBounds: (start, index))) } @inlinable @_lifetime(&self) - public mutating func nextMutableSpan(after index: inout Int, maximumCount: Int) -> MutableSpan { + public mutating func nextMutableSpan( + after index: inout Int, maxCount: Int + ) -> MutableSpan { _checkValidIndex(index) - precondition(maximumCount > 0, "maximumCount must be positive") + precondition(maxCount > 0, "maxCount must be positive") let start = index - index = start &+ Swift.min(maximumCount, _count &- start) + index = start &+ Swift.min(maxCount, _count &- start) return _mutableSpan(in: Range(uncheckedBounds: (start, index))) } @inlinable @_lifetime(borrow self) public func previousSpan( - before index: inout Int, maximumCount: Int + before index: inout Int, maxCount: Int ) -> Span { _checkValidIndex(index) - precondition(maximumCount > 0, "maximumCount must be positive") + precondition(maxCount > 0, "maxCount must be positive") let start = index - index = start &- Swift.min(maximumCount, start) + index = start &- Swift.min(maxCount, start) return _span(in: Range(uncheckedBounds: (index, start))) } } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift index 43cc2db5..68d90aa8 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Deprecated.swift @@ -15,6 +15,33 @@ @available(SwiftStdlib 5.0, *) extension RigidArray where Element: ~Copyable { + @available(*, deprecated, renamed: "nextSpan(after:maxCount:)") + @inlinable + @_lifetime(borrow self) + public func nextSpan( + after index: inout Int, maximumCount: Int + ) -> Span { + self.nextSpan(after: &index, maxCount: maximumCount) + } + + @available(*, deprecated, renamed: "nextMutableSpan(after:maxCount:)") + @inlinable + @_lifetime(&self) + public mutating func nextMutableSpan( + after index: inout Int, maximumCount: Int + ) -> MutableSpan { + self.nextMutableSpan(after: &index, maxCount: maximumCount) + } + + @available(*, deprecated, renamed: "previousSpan(before:maxCount:)") + @inlinable + @_lifetime(borrow self) + public func previousSpan( + before index: inout Int, maximumCount: Int + ) -> Span { + self.previousSpan(before: &index, maxCount: maximumCount) + } + /// Append a given number of items to the end of this array by populating /// an output span. /// diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index c62bd142..99085eec 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -446,7 +446,7 @@ extension RigidArray where Element: ~Copyable { /// - newItemCount: The maximum number of items to insert into the array. /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `maximumCount`) + /// - Complexity: O(`self.count` + `newItemCount`) @_alwaysEmitIntoClient public mutating func replace< E: Error, @@ -594,7 +594,7 @@ extension RigidArray { var it = items.makeIterableIterator_() self.replace(removing: subrange, addingCount: newCount) { target in while !target.isFull { - let source = it.nextSpan_(maximumCount: target.freeCapacity) + let source = it.nextSpan_(maxCount: target.freeCapacity) precondition( !source.isEmpty, "Broken Container: count doesn't match contents") diff --git a/Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift b/Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift index 6563d56d..c8e933cf 100644 --- a/Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift +++ b/Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift @@ -15,7 +15,7 @@ import ContainersPreview #endif -#if compiler(>=6.4) && UnstableHashedContainers +#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview @available(SwiftStdlib 6.2, *) extension RigidDictionary where Key: ~Copyable, Value: ~Copyable { @@ -87,7 +87,7 @@ where Key: ~Copyable, Value: ~Copyable { public typealias Element_ = Element @_lifetime(&self) - public mutating func nextSpan_(maximumCount: Int) -> Span { + public mutating func nextSpan_(maxCount: Int) -> Span { guard _it.advanceToOccupied() else { return .init() } _current[0] = Element(_bucket: _it.currentBucket) _it.advanceToNextBit() diff --git a/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift b/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift index dcda6311..14884934 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift @@ -70,11 +70,11 @@ extension RigidSet: Iterable_ where Element: ~Copyable { } @_alwaysEmitIntoClient - @_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)` - public mutating func nextSpan_(maximumCount: Int) -> Span { - precondition(maximumCount > 0, "maximumCount must be positive") + @_lifetime(&self) + public mutating func nextSpan_(maxCount: Int) -> Span { + precondition(maxCount > 0, "maxCount must be positive") guard - let next = _bucketIterator.nextOccupiedRegion(maximumCount: maximumCount) + let next = _bucketIterator.nextOccupiedRegion(maxCount: maxCount) else { return .init() } diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Deprecated.swift b/Sources/BasicContainers/RigidSet/RigidSet+Deprecated.swift new file mode 100644 index 00000000..9e118d5c --- /dev/null +++ b/Sources/BasicContainers/RigidSet/RigidSet+Deprecated.swift @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception +// +//===----------------------------------------------------------------------===// + +#if COLLECTIONS_SINGLE_MODULE // Don't define these outside the Xcode project + +#if compiler(>=6.4) && UnstableHashedContainers +@available(SwiftStdlib 5.0, *) +extension RigidSet where Element: ~Copyable { + @available(*, deprecated, renamed: "insert(addingCount:initializingWith:)") + @_alwaysEmitIntoClient + public mutating func insert( + maximumCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + try self.insert(addingCount: maximumCount, initializingWith: initializer) + } + + @available(*, deprecated, renamed: "insert(addingCount:from:)") + @_alwaysEmitIntoClient + public mutating func insert< + E: Error, + P: Producer & ~Copyable & ~Escapable + >( + maximumCount: Int?, + from producer: inout P + ) throws(E) + where P.Element: ~Copyable + { + try self.insert(addingCount: maximumCount, from: &producer) + } + + @available(*, deprecated, renamed: "insert(addingCount:from:)") + @_alwaysEmitIntoClient + public mutating func insert< + D: Drain & ~Copyable & ~Escapable + >( + maximumCount: Int?, + from drain: inout D + ) { + var remainder = drain.count + while remainder > 0 { + var span = drain.drainNext(maxCount: remainder) + guard !span.isEmpty else { break } + remainder &-= span.count + while let next = span.popFirst() { + self.insert(next) + } + } + } +} +#endif + +#endif diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift b/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift index 7146c0b3..d7bc1cf8 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift @@ -46,7 +46,7 @@ extension RigidSet where Element: ~Copyable { initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) { self.init(capacity: capacity) - try self.insert(maximumCount: capacity, initializingWith: initializer) + try self.insert(addingCount: capacity, initializingWith: initializer) } #if UnstableContainersPreview @@ -61,7 +61,7 @@ extension RigidSet where Element: ~Copyable { where P.Element: ~Copyable { self.init(capacity: capacity) - try self.insert(maximumCount: capacity, from: &producer) + try self.insert(addingCount: capacity, from: &producer) } #endif @@ -74,7 +74,7 @@ extension RigidSet where Element: ~Copyable { from drain: inout D ) { self.init(capacity: capacity) - self.insert(maximumCount: capacity, from: &drain) + self.insert(addingCount: capacity, from: &drain) } #endif } diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift b/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift index 0fdd0c99..b103301c 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift @@ -102,7 +102,8 @@ extension RigidSet where Element: ~Copyable { /// Inserts the given element in the set if it is not already present. /// /// - Parameter item: An element to insert into the set. - /// - Returns: + /// - Returns: `item` if an equal member already exists in the set; + /// otherwise `nil`. @inlinable @discardableResult public mutating func insert( @@ -121,14 +122,14 @@ extension RigidSet where Element: ~Copyable { extension RigidSet where Element: ~Copyable { @_alwaysEmitIntoClient public mutating func insert( - maximumCount: Int, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - precondition(maximumCount >= 0, "Cannot insert a negative number of items") - guard maximumCount > 0 else { return } - precondition(freeCapacity >= maximumCount, "RigidSet capacity overflow") - var remainder = maximumCount - + precondition(newItemCount >= 0, "Cannot insert a negative number of items") + guard newItemCount > 0 else { return } + precondition(freeCapacity >= newItemCount, "RigidSet capacity overflow") + var remainder = newItemCount + // FIXME: Instead of getting temporary buffers, we could place the new // items in unoccupied buckets, then incrementally // rehash them into their correct location, like the stdlib does for @@ -171,13 +172,13 @@ extension RigidSet where Element: ~Copyable { E: Error, P: Producer & ~Copyable & ~Escapable >( - maximumCount: Int? = nil, + addingCount newItemCount: Int? = nil, from producer: inout P ) throws(E) where P.Element: ~Copyable { try self.insert( - maximumCount: maximumCount ?? freeCapacity + addingCount: newItemCount ?? freeCapacity ) { target throws(E) in while !target.isFull { guard try producer.generate(into: &target) else { break } @@ -186,23 +187,36 @@ extension RigidSet where Element: ~Copyable { } #endif +#if UnstableContainersPreview + @_alwaysEmitIntoClient + public mutating func insert< + E: Error, + P: CountedProducer & ~Copyable & ~Escapable + >( + from producer: consuming P + ) throws(E) { + try self.insert(addingCount: producer.count, from: &producer) + try producer._expectEnd("Invalid CountedProducer") + } +#endif + #if UnstableContainersPreview @_alwaysEmitIntoClient public mutating func insert< D: Drain & ~Copyable & ~Escapable >( - maximumCount: Int? = nil, - from drain: inout D + from drain: consuming D ) { - var remainder = maximumCount ?? freeCapacity + var remainder = drain.count while remainder > 0 { - var span = drain.drainNext(maximumCount: remainder) + var span = drain.drainNext(maxCount: remainder) guard !span.isEmpty else { break } remainder &-= span.count while let next = span.popFirst() { self.insert(next) } } + drain._expectEnd("Invalid Drain") } #endif } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift index d330f1d0..39ca060c 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -284,7 +284,7 @@ extension UniqueArray where Element: ~Copyable { /// Return a span over the array's storage that begins with the element at /// the given index, and extends to the end of the contiguous storage chunk - /// that contains it, but no more than `maximumCount` items. + /// that contains it, but no more than `maxCount` items. /// /// On return, the index is updated to address the next item following the /// end of the returned span. @@ -295,30 +295,30 @@ extension UniqueArray where Element: ~Copyable { /// /// var index = items.startIndex /// while true { - /// let span = items.nextSpan(after: &index, maximumCount: 4) + /// let span = items.nextSpan(after: &index, maxCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// The `maximumCount` argument gives the caller control over the number of + /// The `maxCount` argument gives the caller control over the number of /// items it receives from the iterator. This lets the caller avoid getting /// more elements than it would be able to immediately process, which would /// significantly complicate container use. /// /// If the caller is able to process any number available items, it can signal - /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// that by passing `Int.max` as the `maxCount`, or simply by calling the /// `nexSpan(after:)` method, which does precisely that. This is frequently /// the case when the caller simply wants to iterate over the entire /// container in a single loop. /// - /// `maximumCount` sets an upper bound. To read a specific number of items, + /// `maxCount` sets an upper bound. To read a specific number of items, /// the caller usually needs to invoke `nextSpan` in a loop: /// /// var items: some Container /// var index = items.startIndex /// var remainder = numberOfItemsToRead /// while remainder > 0 { - /// let next = items.nextSpan(after: &index, maximumCount: remainder) + /// let next = items.nextSpan(after: &index, maxCount: remainder) /// guard !next.isEmpty else { /// // Container does not have enough items /// break @@ -341,10 +341,10 @@ extension UniqueArray where Element: ~Copyable { /// - Parameter index: A valid index in the container, including the end /// index. On return, this index is advanced by the count of the resulting /// span, to simplify iteration. - /// - Parameter maximumCount: The maximum number of items the caller is able - /// to process immediately. `maximumCount` must be greater than zero. + /// - Parameter maxCount: The maximum number of items the caller is able + /// to process immediately. `maxCount` must be greater than zero. /// If you are able to process an arbitrary number of items, set - /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// `maxCount` to `Int.max`, or call the `nextSpan(after:)` method. /// - Returns: A span over contiguous storage that starts at the given index. /// If the input index is the end index, then this returns an empty span. /// Otherwise the result is non-empty, with its first element matching the @@ -353,25 +353,25 @@ extension UniqueArray where Element: ~Copyable { @inlinable @_lifetime(borrow self) public func nextSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> Span { - _storage.nextSpan(after: &index, maximumCount: maximumCount) + _storage.nextSpan(after: &index, maxCount: maxCount) } @inlinable @_lifetime(&self) public mutating func nextMutableSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> MutableSpan { - _storage.nextMutableSpan(after: &index, maximumCount: maximumCount) + _storage.nextMutableSpan(after: &index, maxCount: maxCount) } @inlinable @_lifetime(borrow self) public func previousSpan( - before index: inout Int, maximumCount: Int + before index: inout Int, maxCount: Int ) -> Span { - _storage.previousSpan(before: &index, maximumCount: maximumCount) + _storage.previousSpan(before: &index, maxCount: maxCount) } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift index 8a7b7028..b1839027 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Deprecated.swift @@ -15,6 +15,33 @@ @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { + @available(*, deprecated, renamed: "nextSpan(after:maxCount:)") + @inlinable + @_lifetime(borrow self) + public func nextSpan( + after index: inout Int, maximumCount: Int + ) -> Span { + self.nextSpan(after: &index, maxCount: maximumCount) + } + + @available(*, deprecated, renamed: "nextMutableSpan(after:maxCount:)") + @inlinable + @_lifetime(&self) + public mutating func nextMutableSpan( + after index: inout Int, maximumCount: Int + ) -> MutableSpan { + self.nextMutableSpan(after: &index, maxCount: maximumCount) + } + + @available(*, deprecated, renamed: "previousSpan(before:maxCount:)") + @inlinable + @_lifetime(borrow self) + public func previousSpan( + before index: inout Int, maximumCount: Int + ) -> Span { + self.previousSpan(before: &index, maxCount: maximumCount) + } + /// Initializes a new unique array with the specified capacity and no elements. @available(*, deprecated, renamed: "init(minimumCapacity:)") @inlinable diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift index 2b6c91b5..816e5818 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Replacements.swift @@ -346,7 +346,7 @@ extension UniqueArray where Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { #if compiler(>=6.4) && UnstableContainersPreview - /// Replaces the specified range of elements by at most `maximumCount` items + /// Replaces the specified range of elements by at most `maxCount` items /// generated by a producer. /// /// This method has the effect of removing the specified range of elements @@ -367,8 +367,8 @@ extension UniqueArray where Element: ~Copyable { /// directly expressed by calling `removeSubrange`. /// /// This operation inserts as many items as the producer can generate before - /// either reaching `maximumCount`, or the producer hitting its end, or - /// throwing an error. If the producer has more than `maximumCount` items left in + /// either reaching `maxCount`, or the producer hitting its end, or + /// throwing an error. If the producer has more than `maxCount` items left in /// its underlying sequence, then extra items remain available after this /// method returns. /// diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Deprecations.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Deprecations.swift new file mode 100644 index 00000000..08823fe8 --- /dev/null +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Deprecations.swift @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 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 +// +// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception +// +//===----------------------------------------------------------------------===// + +#if COLLECTIONS_SINGLE_MODULE // Don't define these outside the Xcode project + +#if compiler(>=6.4) && UnstableHashedContainers +@available(SwiftStdlib 5.0, *) +extension UniqueSet where Element: ~Copyable { + @available(*, deprecated, renamed: "insert(addingCount:initializingWith:)") + @_alwaysEmitIntoClient + public mutating func insert( + maximumCount: Int, + initializingWith initializer: (inout OutputSpan) throws(E) -> Void + ) throws(E) -> Void { + try self.insert(addingCount: maximumCount, initializingWith: initializer) + } +} +#endif + +#endif diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift index 03ffcf4f..c6855e27 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift @@ -46,7 +46,7 @@ extension UniqueSet where Element: ~Copyable { ) throws(E) { self.init(minimumCapacity: minimumCapacity) try self.insert( - maximumCount: minimumCapacity, + addingCount: minimumCapacity, initializingWith: initializer) } diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift index 1a9d235b..162de94b 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift @@ -56,7 +56,8 @@ extension UniqueSet where Element: ~Copyable { /// Inserts the given element in the set if it is not already present. /// /// - Parameter item: An element to insert into the set. - /// - Returns: + /// - Returns: `item` if an equal member already exists in the set; + /// otherwise `nil`. @inlinable @discardableResult public mutating func insert( @@ -71,12 +72,12 @@ extension UniqueSet where Element: ~Copyable { extension UniqueSet where Element: ~Copyable { @_alwaysEmitIntoClient public mutating func insert( - maximumCount: Int, + addingCount newItemCount: Int, initializingWith initializer: (inout OutputSpan) throws(E) -> Void ) throws(E) -> Void { - _ensureFreeCapacity(maximumCount) + _ensureFreeCapacity(newItemCount) try _storage.insert( - maximumCount: maximumCount, initializingWith: initializer) + addingCount: newItemCount, initializingWith: initializer) } #if UnstableContainersPreview @@ -92,7 +93,7 @@ extension UniqueSet where Element: ~Copyable { var done = false while !done { _ensureFreeCapacity(Swift.max(producer.underestimatedCount, 1)) - try self.insert(maximumCount: self.freeCapacity) { target throws(E) in + try self.insert(addingCount: self.freeCapacity) { target throws(E) in while !target.isFull, !done { done = try !producer.generate(into: &target) } diff --git a/Sources/BitCollections/BitArray/BitArray+ChunkedBitsIterators.swift b/Sources/BitCollections/BitArray/BitArray+ChunkedBitsIterators.swift index 5b6c7610..715bb5ab 100644 --- a/Sources/BitCollections/BitArray/BitArray+ChunkedBitsIterators.swift +++ b/Sources/BitCollections/BitArray/BitArray+ChunkedBitsIterators.swift @@ -87,15 +87,15 @@ internal struct _ChunkedBitsBackwardIterator { extension IteratorProtocol where Element == Bool { mutating func _nextChunk( - maximumCount: UInt = _Word._capacity + maxCount: UInt = _Word._capacity ) -> (bits: _Word, count: UInt) { - assert(maximumCount <= _Word.capacity) + assert(maxCount <= _Word.capacity) var bits = _Word.empty var c: UInt = 0 while let v = next() { if v { bits.insert(c) } c += 1 - if c == maximumCount { break } + if c == maxCount { break } } return (bits, c) } diff --git a/Sources/BitCollections/BitArray/BitArray+Copy.swift b/Sources/BitCollections/BitArray/BitArray+Copy.swift index 2cc80b73..f40faecb 100644 --- a/Sources/BitCollections/BitArray/BitArray+Copy.swift +++ b/Sources/BitCollections/BitArray/BitArray+Copy.swift @@ -162,7 +162,7 @@ extension BitArray._UnsafeHandle { var it = source.makeIterator() if pos.bit > 0 { let (bits, count) = it._nextChunk( - maximumCount: _Word._capacity - pos.bit) + maxCount: _Word._capacity - pos.bit) _copy(bits: bits, count: count, to: pos) pos.value += count } diff --git a/Sources/BitCollections/BitArray/BitArray+RangeReplaceableCollection.swift b/Sources/BitCollections/BitArray/BitArray+RangeReplaceableCollection.swift index ca1e319e..7cf20ac8 100644 --- a/Sources/BitCollections/BitArray/BitArray+RangeReplaceableCollection.swift +++ b/Sources/BitCollections/BitArray/BitArray+RangeReplaceableCollection.swift @@ -285,7 +285,7 @@ extension BitArray { var pos = _BitPosition(_count) if pos.bit > 0 { let (bits, count) = it._nextChunk( - maximumCount: _Word._capacity - pos.bit) + maxCount: _Word._capacity - pos.bit) guard count > 0 else { return } _count += count _update { $0._copy(bits: bits, count: count, to: pos) } diff --git a/Sources/ContainersPreview/CMakeLists.txt b/Sources/ContainersPreview/CMakeLists.txt index 2e2a478c..ece38517 100644 --- a/Sources/ContainersPreview/CMakeLists.txt +++ b/Sources/ContainersPreview/CMakeLists.txt @@ -64,7 +64,7 @@ target_sources(${module_name} PRIVATE "Protocols/Producer+Reduce.swift" "Types/InputSpan.swift" "Types/MutableRef.swift" - "Types/OutputSpan+Extras.swift" + "Types/OutputSpan+Helpers.swift" "Types/Shared.swift" "Types/SpanIterator.swift" "Types/UniqueBox.swift" diff --git a/Sources/ContainersPreview/Conformances/InputSpan+Container.swift b/Sources/ContainersPreview/Conformances/InputSpan+Container.swift index ebc6655f..805907ce 100644 --- a/Sources/ContainersPreview/Conformances/InputSpan+Container.swift +++ b/Sources/ContainersPreview/Conformances/InputSpan+Container.swift @@ -31,10 +31,10 @@ where Element: ~Copyable @inlinable @_lifetime(borrow self) - public func nextSpan(after index: inout Index, maximumCount: Int) -> Span { + public func nextSpan(after index: inout Index, maxCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let c = Swift.min(count &- index, maximumCount) + precondition(maxCount > 0, "maxCount must be positive") + let c = Swift.min(count &- index, maxCount) let start = capacity &- count &+ index return _uncheckedSpan(in: Range(uncheckedBounds: (start, start &+ c))) } @@ -42,21 +42,21 @@ where Element: ~Copyable @inlinable @_lifetime(&self) public mutating func nextMutableSpan( - after index: inout Index, maximumCount: Int + after index: inout Index, maxCount: Int ) -> MutableSpan { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let c = Swift.min(count &- index, maximumCount) + precondition(maxCount > 0, "maxCount must be positive") + let c = Swift.min(count &- index, maxCount) let start = capacity &- count &+ index return _uncheckedMutableSpan(in: Range(uncheckedBounds: (start, start &+ c))) } @inlinable @_lifetime(borrow self) - public func previousSpan(before index: inout Int, maximumCount: Int) -> Span { + public func previousSpan(before index: inout Int, maxCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let c = Swift.min(index, maximumCount) + precondition(maxCount > 0, "maxCount must be positive") + let c = Swift.min(index, maxCount) let end = capacity &- count &+ index return _uncheckedSpan(in: Range(uncheckedBounds: (end &- c, end))) } diff --git a/Sources/ContainersPreview/Conformances/MutableSpan+Container.swift b/Sources/ContainersPreview/Conformances/MutableSpan+Container.swift index 508332b7..4b524e46 100644 --- a/Sources/ContainersPreview/Conformances/MutableSpan+Container.swift +++ b/Sources/ContainersPreview/Conformances/MutableSpan+Container.swift @@ -31,22 +31,22 @@ extension MutableSpan: RandomAccessContainer where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) public func nextSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = index &+ Swift.min(maximumCount, count &- index) + precondition(maxCount > 0, "maxCount must be positive") + let limit = index &+ Swift.min(maxCount, count &- index) return self.span.extracting(unchecked: Range(uncheckedBounds: (index, limit))) } @_alwaysEmitIntoClient @_lifetime(borrow self) public func previousSpan( - before index: inout Int, maximumCount: Int + before index: inout Int, maxCount: Int ) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = index &- Swift.min(maximumCount, index) + precondition(maxCount > 0, "maxCount must be positive") + let limit = index &- Swift.min(maxCount, index) return self.span.extracting(unchecked: Range(uncheckedBounds: (limit, index))) } } @@ -55,11 +55,11 @@ extension MutableSpan: MutableContainer where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(&self) public mutating func nextMutableSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> MutableSpan { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = index &+ Swift.min(maximumCount, count &- index) + precondition(maxCount > 0, "maxCount must be positive") + let limit = index &+ Swift.min(maxCount, count &- index) return self._mutatingExtracting(unchecked: Range(uncheckedBounds: (index, limit))) } } diff --git a/Sources/ContainersPreview/Conformances/OutputSpan+Container.swift b/Sources/ContainersPreview/Conformances/OutputSpan+Container.swift index 84db9109..d3f5ceb8 100644 --- a/Sources/ContainersPreview/Conformances/OutputSpan+Container.swift +++ b/Sources/ContainersPreview/Conformances/OutputSpan+Container.swift @@ -30,30 +30,30 @@ where Element: ~Copyable @inlinable @_lifetime(borrow self) - public func nextSpan(after index: inout Index, maximumCount: Int) -> Span { + public func nextSpan(after index: inout Index, maxCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = Swift.min(count &- index, maximumCount) + precondition(maxCount > 0, "maxCount must be positive") + let limit = Swift.min(count &- index, maxCount) return self.span.extracting(unchecked: Range(uncheckedBounds: (index, limit))) } @inlinable @_lifetime(&self) public mutating func nextMutableSpan( - after index: inout Index, maximumCount: Int + after index: inout Index, maxCount: Int ) -> MutableSpan { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = Swift.min(count &- index, maximumCount) + precondition(maxCount > 0, "maxCount must be positive") + let limit = Swift.min(count &- index, maxCount) return self.mutableSpan._consumingExtracting(Range(uncheckedBounds: (index, limit))) } @inlinable @_lifetime(borrow self) - public func previousSpan(before index: inout Int, maximumCount: Int) -> Span { + public func previousSpan(before index: inout Int, maxCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = Swift.max(0, index - maximumCount) + precondition(maxCount > 0, "maxCount must be positive") + let limit = Swift.max(0, index - maxCount) return self.span.extracting(unchecked: Range(uncheckedBounds: (limit, index))) } } diff --git a/Sources/ContainersPreview/Conformances/Span+Container.swift b/Sources/ContainersPreview/Conformances/Span+Container.swift index 06397241..4d5c81d5 100644 --- a/Sources/ContainersPreview/Conformances/Span+Container.swift +++ b/Sources/ContainersPreview/Conformances/Span+Container.swift @@ -26,19 +26,19 @@ extension Span: RandomAccessContainer where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) - public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { + public func nextSpan(after index: inout Int, maxCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = index &+ Swift.min(maximumCount, count &- index) + precondition(maxCount > 0, "maxCount must be positive") + let limit = index &+ Swift.min(maxCount, count &- index) return self.extracting(unchecked: Range(uncheckedBounds: (index, limit))) } @_alwaysEmitIntoClient @_lifetime(borrow self) - public func previousSpan(before index: inout Int, maximumCount: Int) -> Span { + public func previousSpan(before index: inout Int, maxCount: Int) -> Span { precondition(index >= 0 && index <= count, "Index out of bounds") - precondition(maximumCount > 0, "maximumCount must be positive") - let limit = index &- Swift.min(maximumCount, index) + precondition(maxCount > 0, "maxCount must be positive") + let limit = index &- Swift.min(maxCount, index) return self.extracting(unchecked: Range(uncheckedBounds: (limit, index))) } } diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift index b9786690..fd321645 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift @@ -123,7 +123,7 @@ where // Note: This is the less efficient implementation of elementsEqual. The // variant in the #else branch would be preferable, but it doesn't work yet. // (It lets the two iterators run at their native speeds, with no artificial - // maximumCounts.) + // maxCounts.) while true { let a = try self.nextSpan_() var i = 0 @@ -131,7 +131,7 @@ where return try other.nextSpan_().isEmpty } while i < a.count { - let b = try other.nextSpan_(maximumCount: a.count - i) + let b = try other.nextSpan_(maxCount: a.count - i) if b.isEmpty { return false } diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift index 62ea6c1e..c5cc3d96 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift @@ -59,10 +59,10 @@ where Base.Element_: ~Copyable { extension BorrowingFilter: BorrowingIteratorProtocol_ where Base: ~Copyable & ~Escapable, Base.Element_: ~Copyable { @_lifetime(&self) - public mutating func nextSpan_(maximumCount: Int) throws(Failure) -> Span { + public mutating func nextSpan_(maxCount: Int) throws(Failure) -> Span { // FIXME: This is quite inefficient compared to Container's filter while true { - let span = try _base.nextSpan_(maximumCount: 1) + let span = try _base.nextSpan_(maxCount: 1) if span.isEmpty { return span } precondition(span.count == 1, "Invalid BorrowingIterator") if try _isIncluded(span[unchecked: 0]) { return span } diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift index 9192d9c0..73affc6c 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift @@ -90,7 +90,7 @@ where @inlinable @_lifetime(self: copy self) public mutating func next() throws(Failure) -> Element? { - let span = try _it.nextSpan_(maximumCount: 1) + let span = try _it.nextSpan_(maxCount: 1) guard !span.isEmpty else { return nil } return try _transform(span[unchecked: 0]) } @@ -104,7 +104,7 @@ where ) throws(Failure) -> Bool { var success = false while !target.isFull { - let span = try _it.nextSpan_(maximumCount: target.freeCapacity) + let span = try _it.nextSpan_(maxCount: target.freeCapacity) guard !span.isEmpty else { break } success = true var i = 0 diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+MapError.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+MapError.swift index 87f358e3..292db26e 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+MapError.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+MapError.swift @@ -73,9 +73,9 @@ where @inlinable @_lifetime(&self) @_lifetime(self: copy self) - public mutating func nextSpan_(maximumCount: Int) throws(Failure_) -> Span { + public mutating func nextSpan_(maxCount: Int) throws(Failure_) -> Span { do { - return try _base.nextSpan_(maximumCount: maximumCount) + return try _base.nextSpan_(maxCount: maxCount) } catch { throw _transform(error) } diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift index 60dcaf3a..393f2023 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift @@ -38,7 +38,7 @@ where // Note: This is the less efficient implementation of spanwiseZip. The // variant in the #else branch would be preferable, but it doesn't work yet. // (It lets the two iterators run at their native speeds, with no artificial - // maximumCounts.) + // maxCounts.) loop: while true { var a = try self.nextSpan_() @@ -51,7 +51,7 @@ where return } repeat { - let b = try other.nextSpan_(maximumCount: a.count) + let b = try other.nextSpan_(maxCount: a.count) if b.isEmpty { guard try process(&state, a, b) else { return } } else { diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift index b26aa039..ea33fd18 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift @@ -34,10 +34,10 @@ public protocol BorrowingIteratorProtocol_: ~Copyable, ~Esca /// invocation of it. /// /// If the iterator has not yet reached the end of the underlying sequence, - /// then this method returns a non-empty span of at most `maximumCount` + /// then this method returns a non-empty span of at most `maxCount` /// elements, and updates the iterator's current position to the element /// following the last item in the returned span (or the end, if there is - /// none). The `maximumCount` argument allows callers to avoid getting more + /// none). The `maxCount` argument allows callers to avoid getting more /// items that they are able to process in one go, simplifying usage, and /// avoiding materializing more elements than needed. /// @@ -70,7 +70,7 @@ public protocol BorrowingIteratorProtocol_: ~Copyable, ~Esca /// method may vary between different borrows of the same container.) @_lifetime(&self) @_lifetime(self: copy self) - mutating func nextSpan_(maximumCount: Int) throws(Failure_) -> Span + mutating func nextSpan_(maxCount: Int) throws(Failure_) -> Span /// Advance the position of this iterator by the specified offset, or until /// the end of the underlying sequence. @@ -92,7 +92,7 @@ where Self: ~Copyable & ~Escapable, Element_: ~Copyable { @_lifetime(self: copy self) @_transparent public mutating func nextSpan_() throws(Failure_) -> Span { - try nextSpan_(maximumCount: Int.max) + try nextSpan_(maxCount: Int.max) } } @@ -104,7 +104,7 @@ where Self: ~Copyable & ~Escapable, Element_: ~Copyable { public mutating func skip_(by offset: Int) throws(Failure_) -> Int { var remainder = offset while remainder > 0 { - let span = try nextSpan_(maximumCount: remainder) + let span = try nextSpan_(maxCount: remainder) if span.isEmpty { break } remainder &-= span.count } @@ -118,7 +118,7 @@ extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable { @_lifetime(&self) @_lifetime(self: copy self) public mutating func next() -> Ref? { - let span = nextSpan(maximumCount: 1) + let span = nextSpan(maxCount: 1) guard !span.isEmpty else { return nil } return Ref(_borrowing: span[unchecked: 0]) } @@ -136,7 +136,7 @@ extension BorrowingIteratorProtocol_ try target.withUnsafeMutableBufferPointer { (dst, dstCount) throws(Failure_) -> Void in var tail = dst._extracting(droppingFirst: dstCount) while !tail.isEmpty { - let src = try nextSpan_(maximumCount: tail.count) + let src = try nextSpan_(maxCount: tail.count) if src.isEmpty { break } tail._initializeAndDropPrefix(copying: src) dstCount += src.count diff --git a/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift b/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift index 0a4b54bc..6c1e3535 100644 --- a/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/BidirectionalContainer.swift @@ -50,7 +50,7 @@ where Element: ~Copyable, Index: Comparable func formIndex(before i: inout Index) @_lifetime(borrow self) - func previousSpan(before index: inout Index, maximumCount: Int) -> Span + func previousSpan(before index: inout Index, maxCount: Int) -> Span override func index(after index: Index) -> Index @@ -77,7 +77,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { @inlinable @_lifetime(borrow self) public func previousSpan(before index: inout Index) -> Span { - previousSpan(before: &index, maximumCount: Int.max) + previousSpan(before: &index, maxCount: Int.max) } @inlinable @@ -107,7 +107,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { var n = n if n >= 0 { while n > 0 { - let span = self.nextSpan(after: &index, maximumCount: n) + let span = self.nextSpan(after: &index, maxCount: n) precondition( !span.isEmpty, "Cannot advance index beyond the end of the container") @@ -116,7 +116,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { } else { n = -n while n > 0 { - let span = self.previousSpan(before: &index, maximumCount: n) + let span = self.previousSpan(before: &index, maxCount: n) precondition( !span.isEmpty, "Cannot advance index beyond the end of the container") @@ -142,7 +142,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { // Skip forward until we find our target or overshoot the limit. while n > 0 { var j = index - let span = self.nextSpan(after: &j, maximumCount: n) + let span = self.nextSpan(after: &j, maxCount: n) precondition( !span.isEmpty, "Cannot advance index beyond the end of the container") @@ -172,7 +172,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { // Skip backward until we find our target or overshoot the limit. while n < 0 { var j = index - let span = self.previousSpan(before: &j, maximumCount: -n) + let span = self.previousSpan(before: &j, maxCount: -n) precondition( !span.isEmpty, "Cannot move index before the start of the container") diff --git a/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift b/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift index 47107f6d..5968aa33 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift @@ -92,8 +92,8 @@ extension ContainerFilter: BorrowingIteratorProtocol_ where Element: ~Copyable { public typealias Element_ = Base.Element @_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)` - public mutating func nextSpan_(maximumCount: Int) -> Span { - precondition(maximumCount > 0) + public mutating func nextSpan_(maxCount: Int) -> Span { + precondition(maxCount > 0) while true { // Drop filtered out items from prefix of _remainder var i = 0 @@ -102,7 +102,7 @@ extension ContainerFilter: BorrowingIteratorProtocol_ where Element: ~Copyable { } _remainder = _remainder.extracting(droppingFirst: i) if !_remainder.isEmpty { - let c = Swift.min(_remainder.count, maximumCount) + let c = Swift.min(_remainder.count, maxCount) i = 1 while i < c, _isIncluded(_remainder[unchecked: i]) { i &+= 1 diff --git a/Sources/ContainersPreview/Protocols/Container/Container.swift b/Sources/ContainersPreview/Protocols/Container/Container.swift index 89eb8e6f..dd45a270 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container.swift @@ -109,7 +109,7 @@ public protocol Container: /// Return a span over the container's storage that begins with the element at /// the given index, and extends to the end of the contiguous storage chunk - /// that contains it, but no more than `maximumCount` items. + /// that contains it, but no more than `maxCount` items. /// /// On return, the index is updated to address the next item following the /// end of the returned span. @@ -120,30 +120,30 @@ public protocol Container: /// /// var index = items.startIndex /// while true { - /// let span = items.nextSpan(after: &index, maximumCount: 4) + /// let span = items.nextSpan(after: &index, maxCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// The `maximumCount` argument gives the caller control over the number of + /// The `maxCount` argument gives the caller control over the number of /// items it receives from the iterator. This lets the caller avoid getting /// more elements than it would be able to immediately process, which would /// significantly complicate container use. /// /// If the caller is able to process any number available items, it can signal - /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// that by passing `Int.max` as the `maxCount`, or simply by calling the /// `nexSpan(after:)` method, which does precisely that. This is frequently /// the case when the caller simply wants to iterate over the entire /// container in a single loop. /// - /// `maximumCount` sets an upper bound. To read a specific number of items, + /// `maxCount` sets an upper bound. To read a specific number of items, /// the caller usually needs to invoke `nextSpan` in a loop: /// /// var items: some Container /// var index = items.startIndex /// var remainder = numberOfItemsToRead /// while remainder > 0 { - /// let next = items.nextSpan(after: &index, maximumCount: remainder) + /// let next = items.nextSpan(after: &index, maxCount: remainder) /// guard !next.isEmpty else { /// // Container does not have enough items /// break @@ -166,16 +166,16 @@ public protocol Container: /// - Parameter index: A valid index in the container, including the end /// index. On return, this index is advanced by the count of the resulting /// span, to simplify iteration. - /// - Parameter maximumCount: The maximum number of items the caller is able - /// to process immediately. `maximumCount` must be greater than zero. + /// - Parameter maxCount: The maximum number of items the caller is able + /// to process immediately. `maxCount` must be greater than zero. /// If you are able to process an arbitrary number of items, set - /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// `maxCount` to `Int.max`, or call the `nextSpan(after:)` method. /// - Returns: A span over contiguous storage that starts at the given index. /// If the input index is the end index, then this returns an empty span. /// Otherwise the result is non-empty, with its first element matching the /// element at the input index. @_lifetime(borrow self) - func nextSpan(after index: inout Index, maximumCount: Int) -> Span + func nextSpan(after index: inout Index, maxCount: Int) -> Span /// Return the nearest valid index in this container less than or equal to /// the given index value, which must be valid in at least one view of self. @@ -252,7 +252,7 @@ extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) public func nextSpan(after index: inout Index) -> Span { - nextSpan(after: &index, maximumCount: Int.max) + nextSpan(after: &index, maxCount: Int.max) } } @@ -282,16 +282,16 @@ extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable { var index = self.index(alignedDown: index) var n = n -#if true // with nextSpan(after:maximumCount:) +#if true // with nextSpan(after:maxCount:) while n > 0 { - let span = self.nextSpan(after: &index, maximumCount: n) + let span = self.nextSpan(after: &index, maxCount: n) precondition( !span.isEmpty, "Cannot advance index beyond the end of the container") n &-= span.count } return index -#else // without nextSpan(after:maximumCount:) +#else // without nextSpan(after:maxCount:) // FIXME: This implementation can be wasteful for piecewise contiguous // containers, as iterating over spans will tend to overshoot the target. diff --git a/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift b/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift index 80483914..bc0bc204 100644 --- a/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift +++ b/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift @@ -60,8 +60,8 @@ where @_alwaysEmitIntoClient @_unsafeNonescapableResult // FIXME: we cannot convert from a borrow to an inout dependence?! @_lifetime(&self) - public mutating func nextSpan_(maximumCount: Int) -> Span { - _base.value.nextSpan(after: &self._position, maximumCount: maximumCount) + public mutating func nextSpan_(maxCount: Int) -> Span { + _base.value.nextSpan(after: &self._position, maxCount: maxCount) } @_alwaysEmitIntoClient diff --git a/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift b/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift index 267352c1..c0000f95 100644 --- a/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/MutableContainer.swift @@ -29,7 +29,7 @@ where /// Return a mutable span over the container's storage that begins with the /// element at the given index, and extends to the end of the contiguous - /// storage chunk that contains it, but no more than `maximumCount` items. + /// storage chunk that contains it, but no more than `maxCount` items. /// /// On return, the index is updated to address the next item following the /// end of the returned span. @@ -40,30 +40,30 @@ where /// /// var index = items.startIndex /// while true { - /// var span = items.nextMutableSpan(after: &index, maximumCount: 4) + /// var span = items.nextMutableSpan(after: &index, maxCount: 4) /// if span.isEmpty { break } /// // Process items in `span` /// } /// - /// The `maximumCount` argument gives the caller control over the number of + /// The `maxCount` argument gives the caller control over the number of /// items it receives from the iterator. This lets the caller avoid getting /// more elements than it would be able to immediately process, which would /// significantly complicate container use. /// /// If the caller is able to process any number available items, it can signal - /// that by passing `Int.max` as the `maximumCount`, or simply by calling the + /// that by passing `Int.max` as the `maxCount`, or simply by calling the /// `nexSpan(after:)` method, which does precisely that. This is frequently /// the case when the caller simply wants to iterate over the entire /// container in a single loop. /// - /// `maximumCount` sets an upper bound. To read a specific number of items, + /// `maxCount` sets an upper bound. To read a specific number of items, /// the caller usually needs to invoke `nextSpan` in a loop: /// /// var items: some MutableContainer /// var index = items.startIndex /// var remainder = numberOfItemsToRead /// while remainder > 0 { - /// let next = items.nextMutableSpan(after: &index, maximumCount: remainder) + /// let next = items.nextMutableSpan(after: &index, maxCount: remainder) /// guard !next.isEmpty else { /// // Container does not have enough items /// break @@ -82,10 +82,10 @@ where /// - Parameter index: A valid index in the container, including the end /// index. On return, this index is advanced by the count of the resulting /// span, to simplify iteration. - /// - Parameter maximumCount: The maximum number of items the caller is able - /// to process immediately. `maximumCount` must be greater than zero. + /// - Parameter maxCount: The maximum number of items the caller is able + /// to process immediately. `maxCount` must be greater than zero. /// If you are able to process an arbitrary number of items, set - /// `maximumCount` to `Int.max`, or call the `nextSpan(after:)` method. + /// `maxCount` to `Int.max`, or call the `nextSpan(after:)` method. /// - Returns: A mutable span over contiguous storage that starts at the given /// index. If the input index is the end index, then this returns an empty /// span. Otherwise the result is non-empty, with its first element @@ -93,7 +93,7 @@ where @_lifetime(&self) mutating func nextMutableSpan( after index: inout Index, - maximumCount: Int + maxCount: Int ) -> MutableSpan } @@ -106,7 +106,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable mutating func nextMutableSpan( after index: inout Index, ) -> MutableSpan { - nextMutableSpan(after: &index, maximumCount: Int.max) + nextMutableSpan(after: &index, maxCount: Int.max) } } diff --git a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift index d9142942..c58d1aea 100644 --- a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift @@ -209,9 +209,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable removing: subrange, addingCount: producer.count, from: &producer) - if try !producer._isAtEnd() { - preconditionFailure("Invalid Container") - } + try producer._expectEnd("Invalid Container") } @_alwaysEmitIntoClient @@ -278,9 +276,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable var producer = source.consume(sourceSubrange) let targetSubrange = targetSubrange.relative(to: self) self.replace(removing: targetSubrange, addingCount: c, from: &producer) - if !producer._isAtEnd() { - preconditionFailure("Invalid Container") - } + producer._expectEnd("Invalid Container") } @_alwaysEmitIntoClient @@ -521,9 +517,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable while !target.isFull, try producer.generate(into: &target) { } } - if try !producer._isAtEnd() { - preconditionFailure("Invalid Container") - } + try producer._expectEnd("Invalid Container") } @_alwaysEmitIntoClient @@ -548,9 +542,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable let c = source.distance(from: sourceSubrange.lowerBound, to: sourceSubrange.upperBound) var producer = source.consume(sourceSubrange) self.insert(addingCount: c, from: &producer, at: index) - if !producer._isAtEnd() { - preconditionFailure("Invalid Container") - } + producer._expectEnd("Invalid Container") } @_alwaysEmitIntoClient @@ -617,9 +609,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { where P.Element: ~Copyable { try append(addingCount: producer.count, from: &producer) - if try !producer._isAtEnd() { - preconditionFailure("Invalid Container") - } + try producer._expectEnd("Invalid Container") } /// Moves the elements of a given container into the end of this one, leaving @@ -650,9 +640,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { let c = source.distance(from: sourceSubrange.lowerBound, to: sourceSubrange.upperBound) var producer = source.consume(sourceSubrange) self.append(addingCount: c, from: &producer) - if !producer._isAtEnd() { - preconditionFailure("Invalid Container") - } + producer._expectEnd("Invalid Container") } /// Appends the elements of a given container to the end of this one by @@ -689,7 +677,7 @@ where var c = items.count var i = items.startIndex self.replace(removing: subrange, addingCount: c) { target in - let source = items.nextSpan(after: &i, maximumCount: target.freeCapacity) + let source = items.nextSpan(after: &i, maxCount: target.freeCapacity) target._append(copying: source) c -= source.count } @@ -707,7 +695,7 @@ where var it = items.makeIterableIterator_() insert(addingCount: newCount, at: index) { target in while !target.isFull { - let source = it.nextSpan_(maximumCount: target.freeCapacity) + let source = it.nextSpan_(maxCount: target.freeCapacity) precondition(!source.isEmpty, "Broken container: mismatching count") target._append(copying: source) } diff --git a/Sources/ContainersPreview/Protocols/Drain+Map.swift b/Sources/ContainersPreview/Protocols/Drain+Map.swift index 319091b8..4feb9a10 100644 --- a/Sources/ContainersPreview/Protocols/Drain+Map.swift +++ b/Sources/ContainersPreview/Protocols/Drain+Map.swift @@ -73,7 +73,7 @@ where ) throws(Error) -> Bool { var success = false while !target.isFull { - var source = _base.drainNext(maximumCount: target.freeCapacity) + var source = _base.drainNext(maxCount: target.freeCapacity) if source.isEmpty { break } success = true while !source.isEmpty { diff --git a/Sources/ContainersPreview/Protocols/Drain.swift b/Sources/ContainersPreview/Protocols/Drain.swift index 039fa984..948e0b0a 100644 --- a/Sources/ContainersPreview/Protocols/Drain.swift +++ b/Sources/ContainersPreview/Protocols/Drain.swift @@ -26,7 +26,7 @@ public protocol Drain: CountedProducer, ~Copyable, ~Escapable where Element: ~Copyable, Failure == Never { /// Returns the next span of consumable items in the sequence underlying this - /// drain, of at most the specified maximum count. A `maximumCount` of nil + /// drain, of at most the specified maximum count. A `maxCount` of nil /// indicates no limit, meaning that the client is able to process an /// arbitrarily large number of elements. /// @@ -36,7 +36,7 @@ where Element: ~Copyable, Failure == Never /// /// While the returned input spans exist, they continue to mutate the drain, /// extending the exclusive access initiated by the call to - /// `drainNext(maximumCount:)`. To call this (or any other) method again, the + /// `drainNext(maxCount:)`. To call this (or any other) method again, the /// returned input span needs to be consumed or otherwise destroyed. /// /// Once this method returns, the contents of the resulting input span are @@ -47,7 +47,7 @@ where Element: ~Copyable, Failure == Never /// temporary location and later reinserting them into the underlying /// construct through some type-specific operations. /// - /// - Parameter maximumCount: The maximum number of items that the client + /// - Parameter maxCount: The maximum number of items that the client /// is prepared to consume, or nil if the client is able to process an /// arbitrary number of elements. If this is non-nil, then it must be a /// positive integer. @@ -57,7 +57,7 @@ where Element: ~Copyable, Failure == Never /// the end of the sequence. @_lifetime(&self) @_lifetime(self: copy self) - mutating func drainNext(maximumCount: Int) -> InputSpan + mutating func drainNext(maxCount: Int) -> InputSpan // TODO: The primary use case does not need this to throw; do we need to allow that? // Note: making this failable is not entirely straightforward, as there is no // easy way to signal partial success -- conforming implementations @@ -75,7 +75,7 @@ where Element: ~Copyable, Failure == Never // ) throws(E) -> R // // This would allow partial consumption, eliminating the need for - // `maximumCount`, but at the cost of having to deal with closures -- + // `maxCount`, but at the cost of having to deal with closures -- // it can be tricky to elegantly flow data/control in & out higher-order // functions. Allowing the function argument to throw also precludes // the drain itself from throwing, unless they are both required @@ -93,7 +93,7 @@ extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { /// /// While the returned input spans exist, they continue to mutate the drain, /// extending the exclusive access initiated by the call to - /// `drain(maximumCount:)`. To call this (or any other) method again, the + /// `drain(maxCount:)`. To call this (or any other) method again, the /// returned input span needs to be consumed or otherwise destroyed. /// /// Once this method returns, the contents of the resulting input span are @@ -111,7 +111,7 @@ extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { @_lifetime(self: copy self) @_transparent public mutating func drainNext() -> InputSpan { - drainNext(maximumCount: Int.max) + drainNext(maxCount: Int.max) } /// Generate the next batch of items into the supplied output span instance, @@ -165,7 +165,7 @@ extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { public mutating func generate( into target: inout OutputSpan ) throws(Never) -> Bool { - var source = self.drainNext(maximumCount: target.freeCapacity) + var source = self.drainNext(maxCount: target.freeCapacity) if source.isEmpty { return false } target._append(moving: &source) return true @@ -207,7 +207,7 @@ extension Drain where Self: ~Copyable & ~Escapable, Element: ~Copyable { ) -> Bool { // FIXME: Compiler crash when this declares throws(Failure) precondition(n >= 0, "Cannot skip a negative number of elements") guard n > 0 else { return true } - let span = drainNext(maximumCount: n) + let span = drainNext(maxCount: n) let success = span.count > 0 n &-= span.count return success diff --git a/Sources/ContainersPreview/Protocols/Iterable+Algorithms.swift b/Sources/ContainersPreview/Protocols/Iterable+Algorithms.swift index 96b7f807..85330318 100644 --- a/Sources/ContainersPreview/Protocols/Iterable+Algorithms.swift +++ b/Sources/ContainersPreview/Protocols/Iterable+Algorithms.swift @@ -76,12 +76,12 @@ extension Iterable_ if el1.isEmpty { // LHS is empty - sequences are equal iff RHS is also empty - let el2 = try iter2.nextSpan_(maximumCount: 1) + let el2 = try iter2.nextSpan_(maxCount: 1) return el2.isEmpty } while el1.count > 0 { - let el2 = try iter2.nextSpan_(maximumCount: el1.count) + let el2 = try iter2.nextSpan_(maxCount: el1.count) if el2.isEmpty { return false } for i in 0.. Span { + public mutating func nextSpan_(maxCount: Int) -> Span { if _progress { _current[0] = _current[0].advanced(by: 1) } @@ -187,7 +187,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger } @inlinable @_lifetime(&self) - public mutating func nextSpan_(maximumCount: Int) -> Span { + public mutating func nextSpan_(maxCount: Int) -> Span { if _progress { _current[0] = _current[0].advanced(by: 1) } diff --git a/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift b/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift index c6734a32..16fb1c8f 100644 --- a/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift +++ b/Sources/ContainersPreview/Protocols/Iterable+Utilities.swift @@ -26,7 +26,7 @@ extension Iterable_ where Self: ~Copyable & ~Escapable, Element_: Copyable { var target = buffer var it = self.makeIterableIterator_() while target.count != 0 { - let span = try it.nextSpan_(maximumCount: target.count) + let span = try it.nextSpan_(maxCount: target.count) if span.isEmpty { return buffer.count - target.count } diff --git a/Sources/ContainersPreview/Protocols/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift index 737f30cb..cbbfc7b6 100644 --- a/Sources/ContainersPreview/Protocols/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -266,15 +266,17 @@ extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { @available(SwiftStdlib 5.0, *) extension Producer where Self: ~Copyable & ~Escapable, Element: ~Copyable { - /// Returns true if the producer has no more elements, consuming it in + /// Triggers a runtime trap if the producer is not at its end, consuming it in /// the process. This is implemented by checking if it is possible to /// skip one item. - /// - /// This is useful in preconditions. @inlinable - public consuming func _isAtEnd() throws(Failure) -> Bool { + public consuming func _expectEnd( + _ message: String = "Invalid Producer" + ) throws(Failure) { var c = 1 - return try !skip(by: &c) + if try !skip(by: &c) { + preconditionFailure(message) + } } } diff --git a/Sources/ContainersPreview/Types/OutputSpan+Extras.swift b/Sources/ContainersPreview/Types/OutputSpan+Helpers.swift similarity index 100% rename from Sources/ContainersPreview/Types/OutputSpan+Extras.swift rename to Sources/ContainersPreview/Types/OutputSpan+Helpers.swift diff --git a/Sources/ContainersPreview/Types/SpanIterator.swift b/Sources/ContainersPreview/Types/SpanIterator.swift index a5513c27..6e59e785 100644 --- a/Sources/ContainersPreview/Types/SpanIterator.swift +++ b/Sources/ContainersPreview/Types/SpanIterator.swift @@ -37,8 +37,8 @@ public struct SpanIterator: BorrowingIteratorProtocol_, ~Copyable, ~Es @_lifetime(&self) @_lifetime(self: copy self) @_transparent - public mutating func nextSpan_(maximumCount: Int) -> Span { - let c = Swift.min(maximumCount, _count) + public mutating func nextSpan_(maxCount: Int) -> Span { + let c = Swift.min(maxCount, _count) defer { _start &+= c _count &-= c diff --git a/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift b/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift index 91916abb..db83bd45 100644 --- a/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift +++ b/Sources/DequeModule/Deque/Deque._UnsafeHandle.swift @@ -359,7 +359,7 @@ extension Deque._UnsafeHandle { @inlinable internal func withUnsafeSegment( startingAt start: Int, - maximumCount: Int?, + maxCount: Int?, _ body: (UnsafeBufferPointer) throws -> R ) rethrows -> (end: Int, result: R) { assert(start <= count) @@ -370,7 +370,7 @@ extension Deque._UnsafeHandle { let segmentStart = self.slot(forOffset: start) let segmentEnd = segmentStart < endSlot ? endSlot : limSlot - let count = Swift.min(maximumCount ?? Int.max, segmentEnd.position - segmentStart.position) + let count = Swift.min(maxCount ?? Int.max, segmentEnd.position - segmentStart.position) let result = try body(UnsafeBufferPointer(start: ptr(at: segmentStart), count: count)) return (start + count, result) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift index 5a014007..018f6152 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Consumption.swift @@ -235,14 +235,14 @@ extension RigidDeque.SubrangeConsumer where Element: ~Copyable { @inlinable @_lifetime(&self) @_lifetime(self: copy self) - public mutating func drainNext(maximumCount: Int) -> InputSpan { + public mutating func drainNext(maxCount: Int) -> InputSpan { if _buffer1.isEmpty { if _buffer2.isEmpty { return .init() } swap(&_buffer1, &_buffer2) } - let buffer = _buffer1._trim(first: maximumCount) + let buffer = _buffer1._trim(first: maxCount) return _overrideLifetime( InputSpan(buffer: buffer, initializedCount: buffer.count), mutating: &self) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index 3084493b..6f671115 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -48,8 +48,8 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)` @_lifetime(self: copy self) - public mutating func nextSpan_(maximumCount: Int) -> Span { - let result = _currentSegment._trim(first: maximumCount) + public mutating func nextSpan_(maxCount: Int) -> Span { + let result = _currentSegment._trim(first: maxCount) if _currentSegment.isEmpty { _currentSegment = _nextSegment _nextSegment = Span() @@ -118,25 +118,25 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) - public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { + public func nextSpan(after index: inout Int, maxCount: Int) -> Span { _checkValidIndex(index) - precondition(maximumCount > 0, "maximumCount must be positive") + precondition(maxCount > 0, "maxCount must be positive") let segment = self._handle .nextSegment(after: index) - ._extracting(first: maximumCount) + ._extracting(first: maxCount) index &+= segment.count return _overrideLifetime(Span(_unsafeElements: segment), borrowing: self) } @_lifetime(&self) public mutating func nextMutableSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> MutableSpan { _checkValidIndex(index) - precondition(maximumCount > 0, "maximumCount must be positive") + precondition(maxCount > 0, "maxCount must be positive") let segment = self._handle .nextSegment(after: index) - ._extracting(first: maximumCount) + ._extracting(first: maxCount) index &+= segment.count return _overrideLifetime( MutableSpan(_unsafeElements: .init(mutating: segment)), @@ -145,12 +145,12 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) - public func previousSpan(before index: inout Int, maximumCount: Int) -> Span { + public func previousSpan(before index: inout Int, maxCount: Int) -> Span { _checkValidIndex(index) - precondition(maximumCount > 0, "maximumCount must be positive") + precondition(maxCount > 0, "maxCount must be positive") let segment = self._handle .previousSegment(before: index) - ._extracting(last: maximumCount) + ._extracting(last: maxCount) index &-= segment.count return _overrideLifetime(Span(_unsafeElements: segment), borrowing: self) } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 931cba4d..47c5227a 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -202,7 +202,7 @@ extension RigidDeque where Element: ~Copyable { /// many items as promised. /// /// - Parameters: - /// - maximumCount: The maximum number of items to prepend to the deque, or + /// - maxCount: The maximum number of items to prepend to the deque, or /// nil to use all available capacity. /// - producer: A producer that generates the items to prepend. /// @@ -317,7 +317,7 @@ extension RigidDeque /*where Element: Copyable*/ { where S.Element_ == Element { var it = items.makeIterableIterator_() try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in - let span = try it.nextSpan_(maximumCount: target.freeCapacity) + let span = try it.nextSpan_(maxCount: target.freeCapacity) target._append(copying: span) } } diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 9fde6108..ae6bdfc6 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -316,7 +316,7 @@ extension RigidDeque where Element: ~Copyable { /// - newItemCount: The maximum number of items to insert into the deque. /// - producer: A producer that generates the items to append. /// - /// - Complexity: O(`self.count` + `maximumCount`) + /// - Complexity: O(`self.count` + `maxCount`) @_alwaysEmitIntoClient public mutating func replace< E: Error, diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift index 7922a568..a20f5dc6 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift @@ -87,21 +87,21 @@ extension UniqueDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) - public func nextSpan(after index: inout Int, maximumCount: Int) -> Span { - _storage.nextSpan(after: &index, maximumCount: maximumCount) + public func nextSpan(after index: inout Int, maxCount: Int) -> Span { + _storage.nextSpan(after: &index, maxCount: maxCount) } @_lifetime(&self) public mutating func nextMutableSpan( - after index: inout Int, maximumCount: Int + after index: inout Int, maxCount: Int ) -> MutableSpan { - _storage.nextMutableSpan(after: &index, maximumCount: maximumCount) + _storage.nextMutableSpan(after: &index, maxCount: maxCount) } @_alwaysEmitIntoClient @_lifetime(borrow self) - public func previousSpan(before index: inout Int, maximumCount: Int) -> Span { - _storage.previousSpan(before: &index, maximumCount: maximumCount) + public func previousSpan(before index: inout Int, maxCount: Int) -> Span { + _storage.previousSpan(before: &index, maxCount: maxCount) } } diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index 274454f7..29f6b209 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -346,7 +346,7 @@ extension UniqueDeque /*where Element: Copyable*/ { where S.Element_ == Element { var it = items.makeIterableIterator_() try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in - let span = try it.nextSpan_(maximumCount: target.freeCapacity) + let span = try it.nextSpan_(maxCount: target.freeCapacity) target._append(copying: span) } } diff --git a/Sources/RopeModule/BigString/Views/BigString+UTF8View.swift b/Sources/RopeModule/BigString/Views/BigString+UTF8View.swift index 6d727b5d..00670bac 100644 --- a/Sources/RopeModule/BigString/Views/BigString+UTF8View.swift +++ b/Sources/RopeModule/BigString/Views/BigString+UTF8View.swift @@ -96,7 +96,7 @@ extension BigString.UTF8View.Iterator: IteratorProtocol { } public mutating func next( - maximumCount: Int, + maximumCount: Int, // FIXME: Should be `maxCount` with body: (UnsafeBufferPointer) -> (consumed: Int, result: R) ) -> R { guard _index < _base.endIndex else { diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index dbfe64a9..b7219bd0 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -1508,7 +1508,7 @@ class RigidArrayTests: CollectionTestCase { } var consumer = a.consume(0 ..< 2) - let span = consumer.drainNext(maximumCount: .max) + let span = consumer.drainNext(maxCount: .max) expectEqual(span.count, 2) expectEqual(span[0].payload, 0) diff --git a/Tests/BasicContainersTests/RigidSetTests.swift b/Tests/BasicContainersTests/RigidSetTests.swift index b8536df6..5025ccfd 100644 --- a/Tests/BasicContainersTests/RigidSetTests.swift +++ b/Tests/BasicContainersTests/RigidSetTests.swift @@ -242,7 +242,7 @@ class RigidSetTests: CollectionTestCase { func test_bucketIterator_consistency() { withEvery("capacity", in: [0, 1, 2, 3, 4, 10, 100, 200]) { capacity in - withEvery("maximumCount", in: [1, 2, 3, Int.max]) { maximumCount in + withEvery("maxCount", in: [1, 2, 3, Int.max]) { maxCount in withLifetimeTracking { tracker in var s = RigidSet>(capacity: capacity) withEvery("i", in: 0 ..< capacity) { i in @@ -250,13 +250,13 @@ class RigidSetTests: CollectionTestCase { var it = s._table.makeBucketIterator() var j = s._table.startBucket - while let next = it.nextOccupiedRegion(maximumCount: maximumCount) { + while let next = it.nextOccupiedRegion(maxCount: maxCount) { expectFalse(next.isEmpty, "Empty chunk; j: \(j), next: \(next)") expectLessThanOrEqual( next.upperBound.offset - next.lowerBound.offset, - maximumCount, + maxCount, "Overlong chunk") - if maximumCount == Int.max, j > s._table.startBucket { + if maxCount == Int.max, j > s._table.startBucket { expectGreaterThan( next.lowerBound, j, "Unnecessarily split run of occupied buckets") @@ -294,7 +294,7 @@ class RigidSetTests: CollectionTestCase { #if UnstableContainersPreview func test_borrowing_iterator() { withEvery("capacity", in: [0, 1, 2, 3, 4, 10, 100, 1000]) { capacity in - withEvery("maximumCount", in: [1, 2, 3, Int.max]) { maximumCount in + withEvery("maxCount", in: [1, 2, 3, Int.max]) { maxCount in withLifetimeTracking { tracker in var s = RigidSet>(capacity: capacity) withEvery("i", in: 0 ..< capacity) { i in @@ -303,9 +303,9 @@ class RigidSetTests: CollectionTestCase { var expected = Set(0 ... i) var it = s.makeIterableIterator_() while true { - let next = it.nextSpan_(maximumCount: maximumCount) + let next = it.nextSpan_(maxCount: maxCount) guard !next.isEmpty else { break } - expectLessThanOrEqual(next.count, maximumCount) + expectLessThanOrEqual(next.count, maxCount) for j in next.indices { let v = next[j].payload expectEqual(expected.remove(v), v, "Unexpected item \(v)") @@ -426,7 +426,7 @@ class RigidSetTests: CollectionTestCase { } } - func test_insert_drain_maximumCount() { + func test_insert_drain_maxCount() { withEvery("capacity", in: [5, 10, 100]) { capacity in withEvery("drainLength", in: [0, 1, 2, 4, 10, capacity]) { drainLength in withEvery("maxCount", in: [0, 1, 2, 3, 5]) { maxCount in @@ -440,7 +440,7 @@ class RigidSetTests: CollectionTestCase { ) { i in tracker.instance(for: i) } - s.insert(maximumCount: maxCount, from: &drain) + s.insert(addingCount: maxCount, from: &drain) expectConsistentSet(s) let expectedCount = Swift.min(maxCount, drainLength) diff --git a/Tests/ContainersTests/BorrowingSequenceTests.swift b/Tests/ContainersTests/BorrowingSequenceTests.swift index 220ed1cd..7b49da9c 100644 --- a/Tests/ContainersTests/BorrowingSequenceTests.swift +++ b/Tests/ContainersTests/BorrowingSequenceTests.swift @@ -69,7 +69,7 @@ extension Iterable_ where Self: ~Copyable & ~Escapable, Element_: Copyable { var borrowIterator = makeIterableIterator_() var result: [Element_] = [] while true { - let span = try borrowIterator.nextSpan_(maximumCount: .max) + let span = try borrowIterator.nextSpan_(maxCount: .max) if span.isEmpty { break } for i in span.indices { result.append(span[i]) diff --git a/Tests/DequeTests/RigidDequeCrashTests.swift b/Tests/DequeTests/RigidDequeCrashTests.swift index 238869b1..95615425 100644 --- a/Tests/DequeTests/RigidDequeCrashTests.swift +++ b/Tests/DequeTests/RigidDequeCrashTests.swift @@ -85,26 +85,26 @@ struct RigidDequeCrashTests { await #expect(processExitsWith: .failure) { var deque = RigidDeque(copying: [1, 2, 3]) var index = -1 - _ = deque.nextMutableSpan(after: &index, maximumCount: 1) + _ = deque.nextMutableSpan(after: &index, maxCount: 1) } await #expect(processExitsWith: .failure) { var deque = RigidDeque(copying: [1, 2, 3]) var index = 4 // valid range is 0...3 (count == 3) - _ = deque.nextMutableSpan(after: &index, maximumCount: 1) + _ = deque.nextMutableSpan(after: &index, maxCount: 1) } } - @Test("nextMutableSpan with non-positive maximumCount traps") + @Test("nextMutableSpan with non-positive maxCount traps") func nextMutableSpanNonPositiveMaximumCount() async { await #expect(processExitsWith: .failure) { var deque = RigidDeque(copying: [1, 2, 3]) var index = 0 - _ = deque.nextMutableSpan(after: &index, maximumCount: 0) + _ = deque.nextMutableSpan(after: &index, maxCount: 0) } await #expect(processExitsWith: .failure) { var deque = RigidDeque(copying: [1, 2, 3]) var index = 0 - _ = deque.nextMutableSpan(after: &index, maximumCount: -1) + _ = deque.nextMutableSpan(after: &index, maxCount: -1) } } } diff --git a/Tests/DequeTests/RigidDequeTests.swift b/Tests/DequeTests/RigidDequeTests.swift index 3e533725..b558f4c7 100644 --- a/Tests/DequeTests/RigidDequeTests.swift +++ b/Tests/DequeTests/RigidDequeTests.swift @@ -1573,15 +1573,15 @@ final class RigidDequeTests: CollectionTestCase { func test_nextMutableSpan() { withEveryDeque("layout", ofCapacities: [0, 1, 2, 3, 5, 10]) { layout in - withEvery("maximumCount", in: [1, 2, 3, 5, 100]) { maximumCount in + withEvery("maxCount", in: [1, 2, 3, 5, 100]) { maxCount in var deque = RigidDeque(layout: layout, contents: layout.valueRange) var index = deque.startIndex var totalSeen = 0 while index < deque.endIndex { let oldIndex = index - var span = deque.nextMutableSpan(after: &index, maximumCount: maximumCount) + var span = deque.nextMutableSpan(after: &index, maxCount: maxCount) expectGreaterThan(span.count, 0) - expectLessThanOrEqual(span.count, maximumCount) + expectLessThanOrEqual(span.count, maxCount) expectEqual(index, oldIndex + span.count) // Overwrite each element with its logical position in the deque. for i in 0 ..< span.count { diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index e21df0db..ca9c9a18 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -142,7 +142,7 @@ public func expectIterablePayloads< var it2 = right.makeIterator() var i = 0 while true { - let next1 = try it1.nextSpan_(maximumCount: 1) + let next1 = try it1.nextSpan_(maxCount: 1) let next2 = it2.next() switch (next1.isEmpty, next2) { case (true, nil): @@ -190,7 +190,7 @@ public func expectIterablePayloads< var it2 = right.makeIterator() var i = 0 while true { - let next1 = try it1.nextSpan_(maximumCount: 1) + let next1 = try it1.nextSpan_(maxCount: 1) let next2 = it2.next() switch (next1.isEmpty, next2) { case (true, nil): diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index 83b44c76..04b040ea 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -102,7 +102,7 @@ public func checkIterable< var pos = 0 var it = iterable.makeIterableIterator_() while true { - let span = try it.nextSpan_(maximumCount: 1) + let span = try it.nextSpan_(maxCount: 1) if span.isEmpty { break } expectEqual(span.count, 1) for i in 0 ..< span.count { @@ -119,7 +119,7 @@ public func checkIterable< var it = iterable.makeIterableIterator_() var spanIndex = 0 while true { - let span = try it.nextSpan_(maximumCount: Int.max) + let span = try it.nextSpan_(maxCount: Int.max) if span.isEmpty { break } expectEqual( span.count, spanShapes[spanIndex].count, diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/CustomDrain.swift b/Tests/_CollectionsTestSupport/MinimalTypes/CustomDrain.swift index 7eb616ed..113db813 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/CustomDrain.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/CustomDrain.swift @@ -47,12 +47,12 @@ package struct CustomDrain: ~Copyable { @available(SwiftStdlib 5.0, *) extension CustomDrain: Drain where Element: ~Copyable { @_lifetime(&self) - package mutating func drainNext(maximumCount: Int) -> InputSpan { + package mutating func drainNext(maxCount: Int) -> InputSpan { assert(_buffer.isEmpty) if _remainder == 0 { _remainder = _chunkSize } - let c = Swift.min(maximumCount, _remainder) + let c = Swift.min(maxCount, _remainder) _remainder -= c for _ in 0 ..< c { guard _position < count else { break } diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift index 9591b8a0..ac83ee40 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift @@ -58,9 +58,9 @@ package struct _StaccatoParameters { internal func endOffset( fromOffset startOffset: Int, - maximumCount: Int + maxCount: Int ) -> Int { - precondition(maximumCount > 0) + precondition(maxCount > 0) precondition(startOffset >= 0 && startOffset <= _count) var cycleOffset = startOffset % _modulus var i = 0 @@ -71,7 +71,7 @@ package struct _StaccatoParameters { i += 1 } let c = _spanCounts[i] - return Swift.min(_count, startOffset + Swift.min(c - cycleOffset, maximumCount)) + return Swift.min(_count, startOffset + Swift.min(c - cycleOffset, maxCount)) } } @@ -91,8 +91,8 @@ public struct _StaccatoBorrowingIterator: BorrowingIteratorP } @_lifetime(&self) // FIXME: Should be `@_lifetime(copy self)` - public mutating func nextSpan_(maximumCount: Int) -> Span { - let endOffset = _params.endOffset(fromOffset: _offset, maximumCount: maximumCount) + public mutating func nextSpan_(maxCount: Int) -> Span { + let endOffset = _params.endOffset(fromOffset: _offset, maxCount: maxCount) let startOffset = _offset _offset = endOffset return _contents.extracting(startOffset ..< endOffset) @@ -183,11 +183,11 @@ extension StaccatoContainer: Container where Element: ~Copyable { @_lifetime(borrow self) public func nextSpan( - after index: inout Index, maximumCount: Int + after index: inout Index, maxCount: Int ) -> Span { precondition(_isValid(index)) let startOffset = index._offset - let endOffset = _params.endOffset(fromOffset: index._offset, maximumCount: maximumCount) + let endOffset = _params.endOffset(fromOffset: index._offset, maxCount: maxCount) index._offset = endOffset return _contents.span.extracting(startOffset ..< endOffset) } diff --git a/Xcode/Collections.xcodeproj/project.pbxproj b/Xcode/Collections.xcodeproj/project.pbxproj index 89720ff8..ffc840f3 100644 --- a/Xcode/Collections.xcodeproj/project.pbxproj +++ b/Xcode/Collections.xcodeproj/project.pbxproj @@ -7,7 +7,9 @@ objects = { /* Begin PBXBuildFile section */ - 7D12E33D2FF5CC2A003050AB /* OutputSpan+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D12E33C2FF5CC2A003050AB /* OutputSpan+Extras.swift */; }; + 7D12E33D2FF5CC2A003050AB /* OutputSpan+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D12E33C2FF5CC2A003050AB /* OutputSpan+Helpers.swift */; }; + 7D12E33F2FF5DAE4003050AB /* _HTable+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D12E33E2FF5DADE003050AB /* _HTable+Deprecated.swift */; }; + 7D12E3412FF5DD0B003050AB /* RigidSet+Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D12E3402FF5DD07003050AB /* RigidSet+Deprecated.swift */; }; 7D24E3ED2FAD4C37005A55EB /* RigidArray+Formatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D24E3EC2FAD4C37005A55EB /* RigidArray+Formatter.swift */; }; 7D2A77262F27F1D1005780C7 /* Span+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77252F27F1D1005780C7 /* Span+Extras.swift */; }; 7D2A77392F27F1E4005780C7 /* UniqueBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D2A77332F27F1E4005780C7 /* UniqueBox.swift */; }; @@ -154,6 +156,7 @@ 7D77E6122FCF810E003FA63B /* CountedProducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D77E6112FCF810E003FA63B /* CountedProducer.swift */; }; 7D77E6252FD0F880003FA63B /* UnsafePointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D77E6242FD0F87B003FA63B /* UnsafePointer+Extras.swift */; }; 7D77E6272FD0F94B003FA63B /* UnsafeMutablePointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D77E6262FD0F940003FA63B /* UnsafeMutablePointer+Extras.swift */; }; + 7D945E6B2FF5E0D1001041A6 /* UniqueSet+Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D945E6A2FF5E0CB001041A6 /* UniqueSet+Deprecations.swift */; }; 7D9748D42E9748930098631A /* BigString+Chunk+UTF16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D32E9748930098631A /* BigString+Chunk+UTF16.swift */; }; 7D9748D52E9748930098631A /* BigString+Chunk+UnicodeScalar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D12E9748930098631A /* BigString+Chunk+UnicodeScalar.swift */; }; 7D9748D62E9748930098631A /* BigString+Chunk+Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */; }; @@ -616,7 +619,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 7D12E33C2FF5CC2A003050AB /* OutputSpan+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OutputSpan+Extras.swift"; sourceTree = ""; }; + 7D12E33C2FF5CC2A003050AB /* OutputSpan+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OutputSpan+Helpers.swift"; sourceTree = ""; }; + 7D12E33E2FF5DADE003050AB /* _HTable+Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "_HTable+Deprecated.swift"; sourceTree = ""; }; + 7D12E3402FF5DD07003050AB /* RigidSet+Deprecated.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidSet+Deprecated.swift"; sourceTree = ""; }; 7D24E3EC2FAD4C37005A55EB /* RigidArray+Formatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidArray+Formatter.swift"; sourceTree = ""; }; 7D24E9862FAD53E1005A55EB /* RigidArray_Fixture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RigidArray_Fixture.swift; sourceTree = ""; }; 7D24E9882FAD53E1005A55EB /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; @@ -777,6 +782,7 @@ 7D77E6112FCF810E003FA63B /* CountedProducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountedProducer.swift; sourceTree = ""; }; 7D77E6242FD0F87B003FA63B /* UnsafePointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafePointer+Extras.swift"; sourceTree = ""; }; 7D77E6262FD0F940003FA63B /* UnsafeMutablePointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutablePointer+Extras.swift"; sourceTree = ""; }; + 7D945E6A2FF5E0CB001041A6 /* UniqueSet+Deprecations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueSet+Deprecations.swift"; sourceTree = ""; }; 7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BigString+Chunk+Character.swift"; sourceTree = ""; }; 7D9748D02E9748930098631A /* BigString+Chunk+Index.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BigString+Chunk+Index.swift"; sourceTree = ""; }; 7D9748D12E9748930098631A /* BigString+Chunk+UnicodeScalar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BigString+Chunk+UnicodeScalar.swift"; sourceTree = ""; }; @@ -1354,7 +1360,7 @@ children = ( 7D2A77332F27F1E4005780C7 /* UniqueBox.swift */, 7DC037C82FE3792300CF0CB8 /* MutableRef.swift */, - 7D12E33C2FF5CC2A003050AB /* OutputSpan+Extras.swift */, + 7D12E33C2FF5CC2A003050AB /* OutputSpan+Helpers.swift */, 7D2A77352F27F1E4005780C7 /* InputSpan.swift */, 7D2A77362F27F1E4005780C7 /* Shared.swift */, 7DACFA112F75FBF100291F2E /* SpanIterator.swift */, @@ -1432,6 +1438,7 @@ 7D479CCC2F46D23400A8CB59 /* UniqueSet+BorrowingSequence.swift */, 7D479CC42F46D20400A8CB59 /* UniqueSet+Consumption.swift */, 7D479CBA2F46A71500A8CB59 /* UniqueSet+Debugging.swift */, + 7D945E6A2FF5E0CB001041A6 /* UniqueSet+Deprecations.swift */, 7DEB31532F4E75AF00F9AF28 /* UniqueSet+Equatable.swift */, 7DEB31552F4E75B800F9AF28 /* UniqueSet+Hashable.swift */, 7DEB31652F52268100F9AF28 /* UniqueSet+Index.swift */, @@ -1525,6 +1532,7 @@ 7D72467C2F3D9DDB00112FD0 /* _HTable+Bucket.swift */, 7D479CE62F47D88000A8CB59 /* _HTable+Consumption.swift */, 7D9B75762F3E65DB0048157E /* _HTable+Debug.swift */, + 7D12E33E2FF5DADE003050AB /* _HTable+Deprecated.swift */, 7D72467E2F3D9DDB00112FD0 /* _HTable+Find.swift */, 7D72467F2F3D9DDB00112FD0 /* _HTable+Insert.swift */, 7D7246802F3D9DDB00112FD0 /* _HTable+Iteration.swift */, @@ -1562,6 +1570,7 @@ 7D479CAF2F450E3F00A8CB59 /* RigidSet+BorrowingSequence.swift */, 7D479CC02F46D14800A8CB59 /* RigidSet+Consumption.swift */, 7D479CB82F46A6D700A8CB59 /* RigidSet+Debugging.swift */, + 7D12E3402FF5DD07003050AB /* RigidSet+Deprecated.swift */, 7D479CFE2F4E487700A8CB59 /* RigidSet+Equatable.swift */, 7DEB31512F4E720500F9AF28 /* RigidSet+Hashable.swift */, 7DEB31632F5218A600F9AF28 /* RigidSet+Index.swift */, @@ -2714,9 +2723,10 @@ 7D2A77952F27F2BF005780C7 /* Deque+Codable.swift in Sources */, 7D2A77962F27F2BF005780C7 /* RigidDeque+Experimental.swift in Sources */, 7D2A77972F27F2BF005780C7 /* Deque+Testing.swift in Sources */, - 7D12E33D2FF5CC2A003050AB /* OutputSpan+Extras.swift in Sources */, + 7D12E33D2FF5CC2A003050AB /* OutputSpan+Helpers.swift in Sources */, 7D2A77982F27F2BF005780C7 /* RigidDeque+Replacements.swift in Sources */, 7D7246872F3D9DDB00112FD0 /* _HTable+Iteration.swift in Sources */, + 7D945E6B2FF5E0D1001041A6 /* UniqueSet+Deprecations.swift in Sources */, 7D7246882F3D9DDB00112FD0 /* RigidDictionary.swift in Sources */, 7D7246892F3D9DDB00112FD0 /* _HTable+Find.swift in Sources */, 7D72468A2F3D9DDB00112FD0 /* _HTable.swift in Sources */, @@ -2901,6 +2911,7 @@ 7DAD899E2E8B09C300DD5786 /* UInt+first and last set bit.swift in Sources */, 7DAD899F2E8B09C300DD5786 /* UInt+reversed.swift in Sources */, 7DAD89A02E8B09C300DD5786 /* FixedWidthInteger+roundUpToPowerOfTwo.swift in Sources */, + 7D12E3412FF5DD0B003050AB /* RigidSet+Deprecated.swift in Sources */, 7DAD89A12E8B09C300DD5786 /* Integer rank.swift in Sources */, 7DE9207429CA70F4004483EB /* BigString+ReplaceSubrange.swift in Sources */, 7DE920DC29CA70F4004483EB /* BitSet+Invariants.swift in Sources */, @@ -2996,6 +3007,7 @@ 7DE9215529CA70F4004483EB /* _RawHashNode+UnsafeHandle.swift in Sources */, 7D2A77392F27F1E4005780C7 /* UniqueBox.swift in Sources */, 7D2A773A2F27F1E4005780C7 /* Drain.swift in Sources */, + 7D12E33F2FF5DAE4003050AB /* _HTable+Deprecated.swift in Sources */, 7D479CC32F46D19600A8CB59 /* RigidSet+Resizing.swift in Sources */, 7D57A2D02F353946002543BD /* RigidArray+Deprecated.swift in Sources */, 7D2A77432F27F1E4005780C7 /* Shared.swift in Sources */,