diff --git a/Sources/BasicContainers/CMakeLists.txt b/Sources/BasicContainers/CMakeLists.txt index 505d131c..053c1548 100644 --- a/Sources/BasicContainers/CMakeLists.txt +++ b/Sources/BasicContainers/CMakeLists.txt @@ -63,7 +63,7 @@ target_sources(${module_name} PRIVATE "HashTable/_HTable+Resizing.swift" "HashTable/_HTable+Sizing.swift" "RigidSet/RigidSet.swift" - "RigidSet/RigidSet+BorrowingSequence.swift" + "RigidSet/RigidSet+BorrowingSequence_.swift" "RigidSet/RigidSet+Consumption.swift" "RigidSet/RigidSet+Debugging.swift" "RigidSet/RigidSet+Equatable.swift" @@ -75,7 +75,7 @@ target_sources(${module_name} PRIVATE "RigidSet/RigidSet+Removals.swift" "RigidSet/RigidSet+Resizing.swift" "UniqueSet/UniqueSet.swift" - "UniqueSet/UniqueSet+BorrowingSequence.swift" + "UniqueSet/UniqueSet+BorrowingSequence_.swift" "UniqueSet/UniqueSet+Consumption.swift" "UniqueSet/UniqueSet+Debugging.swift" "UniqueSet/UniqueSet+Equatable.swift" diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift index 0c3a2f86..33d548e7 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Append.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Append.swift @@ -350,7 +350,7 @@ extension RigidArray { @available(SwiftStdlib 6.4, *) @inlinable internal mutating func _append< - Source: BorrowingSequence & ~Copyable & ~Escapable + Source: BorrowingSequence_ & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { @@ -373,7 +373,7 @@ extension RigidArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: BorrowingSequence & ~Copyable & ~Escapable + Source: BorrowingSequence_ & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { @@ -416,7 +416,7 @@ extension RigidArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: BorrowingSequence & Sequence + Source: BorrowingSequence_ & Sequence >(copying newElements: Source) { _append(copying: newElements) } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift index 492151b0..c90391be 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Container.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Container.swift @@ -20,11 +20,11 @@ import ContainersPreview #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension RigidArray: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = SpanIterator +extension RigidArray: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = SpanIterator @_alwaysEmitIntoClient @inline(__always) - public func makeBorrowingIterator() -> BorrowingIterator { + public func makeBorrowingIterator_() -> BorrowingIterator_ { SpanIterator(self.span) } } diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift index ef2b7cc7..f1b3fbf2 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Initializers.swift @@ -125,7 +125,7 @@ extension RigidArray /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient @inline(__always) - public init & ~Copyable & ~Escapable>( + public init & ~Copyable & ~Escapable>( capacity: Int, copying contents: borrowing Source ) { @@ -147,7 +147,7 @@ extension RigidArray /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient @inline(__always) - public init & Sequence>( + public init & Sequence>( capacity: Int, copying contents: Source ) { diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift index 0659c56d..b7b9bab8 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Insertions.swift @@ -416,15 +416,15 @@ extension RigidArray { copying items: borrowing C, newCount: Int ) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() insert(addingCount: newCount, at: index) { target in while !target.isFull { - let source = it.nextSpan(maximumCount: target.freeCapacity) + let source = it.nextSpan_(maximumCount: target.freeCapacity) precondition(!source.isEmpty, "Broken container: mismatching count") target._append(copying: source) } } - precondition(it.nextSpan().isEmpty, "Broken container: mismatching count") + precondition(it.nextSpan_().isEmpty, "Broken container: mismatching count") } #endif diff --git a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift index 3d4ca72b..5df8a6cd 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray+Replacements.swift @@ -591,17 +591,17 @@ extension RigidArray { copyingContainer items: borrowing C, newCount: Int ) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() self.replace(removing: subrange, addingCount: newCount) { target in while !target.isFull { - let source = it.nextSpan(maximumCount: target.freeCapacity) + let source = it.nextSpan_(maximumCount: target.freeCapacity) precondition( !source.isEmpty, "Broken Container: count doesn't match contents") target._append(copying: source) } precondition( - it.nextSpan().isEmpty, + it.nextSpan_().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 b22f5aca..eb7e3cf1 100644 --- a/Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift +++ b/Sources/BasicContainers/RigidDictionary/RigidDictionary+Indices.swift @@ -41,7 +41,7 @@ extension RigidDictionary where Key: ~Copyable, Value: ~Copyable { } @available(SwiftStdlib 6.2, *) -extension RigidDictionary.Indices: BorrowingSequence +extension RigidDictionary.Indices: BorrowingSequence_ where Key: ~Copyable, Value: ~Copyable { public typealias Element = RigidDictionary.Index diff --git a/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift b/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift index 3210a7c3..8e2cfa81 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+BorrowingSequence.swift @@ -18,12 +18,12 @@ import ContainersPreview #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension RigidSet: BorrowingSequence where Element: ~Copyable { +extension RigidSet: BorrowingSequence_ where Element: ~Copyable { @inlinable public var underestimatedCount: Int { count } @inlinable - public func _customContainsEquatableElement( + public func _customContainsEquatableElement_( _ element: borrowing Element ) -> Bool? { self.contains(element) diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift b/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift index ab56c761..853bc89b 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+Initializers.swift @@ -86,7 +86,7 @@ extension RigidSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( capacity: Int, copying contents: borrowing S @@ -121,7 +121,7 @@ extension RigidSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( capacity: Int, copying contents: borrowing S @@ -134,7 +134,7 @@ extension RigidSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & Collection + S: BorrowingSequence_ & Collection >( capacity: Int? = nil, copying contents: S diff --git a/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift b/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift index c1917f64..1df89dea 100644 --- a/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift +++ b/Sources/BasicContainers/RigidSet/RigidSet+Insertions.swift @@ -224,7 +224,7 @@ extension RigidSet /* where Element: Copyable */ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient package mutating func _insert< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { @@ -242,7 +242,7 @@ extension RigidSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public mutating func insert< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { @@ -264,7 +264,7 @@ extension RigidSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public mutating func insert< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( copying items: borrowing S ) { diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift index fb0ad0eb..0d952350 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Append.swift @@ -311,14 +311,14 @@ extension UniqueArray { @available(SwiftStdlib 6.4, *) @inlinable internal mutating func _append< - Source: BorrowingSequence & ~Copyable & ~Escapable + Source: BorrowingSequence_ & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { - _ensureFreeCapacity(newElements.underestimatedCount) - var it = newElements.makeBorrowingIterator() + _ensureFreeCapacity(newElements.underestimatedCount_) + var it = newElements.makeBorrowingIterator_() while true { - let span = it.nextSpan() + let span = it.nextSpan_() if span.isEmpty { break } _ensureFreeCapacity(span.count) _storage.append(copying: span) @@ -345,7 +345,7 @@ extension UniqueArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: BorrowingSequence & ~Copyable & ~Escapable + Source: BorrowingSequence_ & ~Copyable & ~Escapable >( copying newElements: borrowing Source ) { @@ -400,7 +400,7 @@ extension UniqueArray { @_alwaysEmitIntoClient @inline(__always) public mutating func append< - Source: BorrowingSequence & Sequence + Source: BorrowingSequence_ & Sequence >(copying newElements: Source) { self._append(copying: newElements) } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift index a167706b..0119d07e 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Container.swift @@ -20,16 +20,16 @@ import ContainersPreview #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension UniqueArray: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = RigidArray.BorrowingIterator +extension UniqueArray: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = RigidArray.BorrowingIterator_ @inlinable - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } @_alwaysEmitIntoClient @inline(__always) - public func makeBorrowingIterator() -> BorrowingIterator { - self._storage.makeBorrowingIterator() + public func makeBorrowingIterator_() -> BorrowingIterator_ { + self._storage.makeBorrowingIterator_() } } #endif diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift index 03b723a5..3fdc07d5 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray+Initializers.swift @@ -105,7 +105,7 @@ extension UniqueArray /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient @inline(__always) - public init & ~Copyable & ~Escapable>( + public init & ~Copyable & ~Escapable>( capacity: Int? = nil, copying contents: borrowing Source ) { @@ -142,7 +142,7 @@ extension UniqueArray /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient @inline(__always) - public init & Sequence>( + public init & Sequence>( capacity: Int? = nil, copying contents: Source ) { diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+BorrowingSequence.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+BorrowingSequence.swift index cfe5b408..2f1e08c8 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+BorrowingSequence.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+BorrowingSequence.swift @@ -19,14 +19,14 @@ import ContainersPreview #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_HASHED_CONTAINERS && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 5.0, *) -extension UniqueSet: BorrowingSequence where Element: ~Copyable { +extension UniqueSet: BorrowingSequence_ where Element: ~Copyable { public typealias BorrowingIterator = RigidSet.BorrowingIterator @inlinable public var underestimatedCount: Int { count } @inlinable - public func _customContainsEquatableElement( + public func _customContainsEquatableElement_( _ element: borrowing Element ) -> Bool? { self.contains(element) diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift index 412cb406..66ce7c2a 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Initializers.swift @@ -78,7 +78,7 @@ extension UniqueSet where Element: Copyable { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public init< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { @@ -97,7 +97,7 @@ extension UniqueSet where Element: Copyable { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public init< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( copying items: borrowing S ) { diff --git a/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift b/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift index d6aea3bc..df77c9d8 100644 --- a/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift +++ b/Sources/BasicContainers/UniqueSet/UniqueSet+Insertions.swift @@ -133,7 +133,7 @@ extension UniqueSet /* where Element: Copyable */ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient package mutating func _insert< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { @@ -152,7 +152,7 @@ extension UniqueSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public mutating func insert< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { @@ -175,7 +175,7 @@ extension UniqueSet /* where Element: Copyable */ { @_alwaysEmitIntoClient @inline(__always) public mutating func insert< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( copying items: borrowing S ) { diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Copy.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Copy.swift index d7ef0153..4b64a9e6 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Copy.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Copy.swift @@ -14,10 +14,10 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: Copyable + Element_: Copyable { /// Turns a borrowing iterator into a producer by copying its elements. /// This allows producer algorithms (such as `collect(into:)`) to get @@ -25,7 +25,7 @@ where /// will get copied. @inlinable @_lifetime(copy self) - public consuming func copy() -> BorrowingMapProducer { + public consuming func copy() -> BorrowingMapProducer { // FIXME: We could also just define a direct implementation that avoids the closure. BorrowingMapProducer(_base: self, transform: { $0 }) } diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift index 8e359470..5247147a 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+ElementsEqual.swift @@ -18,30 +18,30 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingSequence +extension BorrowingSequence_ where - Self: ~Copyable & ~Escapable, Element: Equatable, - Element: ~Copyable + Self: ~Copyable & ~Escapable, Element_: Equatable, + Element_: ~Copyable { @inlinable package func _elementsEqual< - Other: BorrowingSequence & ~Copyable & ~Escapable + Other: BorrowingSequence_ & ~Copyable & ~Escapable >( _ other: borrowing Other, ) -> Bool - where Other.Element: ~Copyable + where Other.Element_: ~Copyable { - let it1 = self.makeBorrowingIterator() - let it2 = other.makeBorrowingIterator() + let it1 = self.makeBorrowingIterator_() + let it2 = other.makeBorrowingIterator_() return it1.elementsEqual(it2) } } @available(SwiftStdlib 6.4, *) -extension BorrowingSequence +extension BorrowingSequence_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { /// Returns a Boolean value indicating whether two borrowing sequences contain /// equivalent elements in the same order, using the given predicate as the @@ -67,32 +67,32 @@ where @inlinable package func _elementsEqual< E: Error, - Other: BorrowingSequence & ~Copyable & ~Escapable + Other: BorrowingSequence_ & ~Copyable & ~Escapable >( _ other: borrowing Other, - by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool + by areEquivalent: (borrowing Element_, borrowing Other.Element_) throws(E) -> Bool ) throws(E) -> Bool - where Other.Element: ~Copyable + where Other.Element_: ~Copyable { - let it1 = self.makeBorrowingIterator() - let it2 = other.makeBorrowingIterator() + let it1 = self.makeBorrowingIterator_() + let it2 = other.makeBorrowingIterator_() return try it1.elementsEqual(it2, by: areEquivalent) } } @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable & Equatable + Element_: ~Copyable & Equatable { @inlinable package consuming func elementsEqual< - Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable + Other: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable >( _ other: consuming Other, ) -> Bool - where Other.Element: ~Copyable + where Other.Element_: ~Copyable { var result = true _spanwiseZip(state: &result, with: other) { state, a, b in @@ -114,11 +114,11 @@ where @inlinable package consuming func _directElementsEqual< - Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable + Other: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable >( _ other: consuming Other, ) -> Bool - where Other.Element: ~Copyable + where Other.Element_: ~Copyable { #if true // FIXME: rdar://150228920 Exclusive access scopes aren't expanded enough // Note: This is the less efficient implementation of elementsEqual. The @@ -126,13 +126,13 @@ where // (It lets the two iterators run at their native speeds, with no artificial // maximumCounts.) while true { - let a = self.nextSpan() + let a = self.nextSpan_() var i = 0 if a.isEmpty { - return other.nextSpan().isEmpty + return other.nextSpan_().isEmpty } while i < a.count { - let b = other.nextSpan(maximumCount: a.count - i) + let b = other.nextSpan_(maximumCount: a.count - i) if b.isEmpty { return false } @@ -175,20 +175,20 @@ where } @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { @inlinable package consuming func elementsEqual< E: Error, - Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable + Other: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable >( _ other: consuming Other, - by areEquivalent: (borrowing Element, borrowing Other.Element) throws(E) -> Bool + by areEquivalent: (borrowing Element_, borrowing Other.Element_) throws(E) -> Bool ) throws(E) -> Bool - where Other.Element: ~Copyable + where Other.Element_: ~Copyable { var result = true try _spanwiseZip(state: &result, with: other) { state, a, b throws(E) in diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift index ebc32e83..aeb80125 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Filter.swift @@ -14,15 +14,15 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { @inlinable @_lifetime(copy self) public consuming func filter( - _ isIncluded: @escaping (borrowing Element) -> Bool + _ isIncluded: @escaping (borrowing Element_) -> Bool ) -> BorrowingFilter { BorrowingFilter(_base: self, isIncluded: isIncluded) } @@ -30,13 +30,13 @@ where @available(SwiftStdlib 6.4, *) public struct BorrowingFilter< - Base: BorrowingIteratorProtocol & ~Copyable & ~Escapable + Base: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable >: ~Copyable, ~Escapable -where Base.Element: ~Copyable { - public typealias Element = Base.Element +where Base.Element_: ~Copyable { + public typealias Element_ = Base.Element_ @_alwaysEmitIntoClient - public let _isIncluded: (borrowing Element) -> Bool + public let _isIncluded: (borrowing Element_) -> Bool @_alwaysEmitIntoClient public var _base: Base @@ -45,7 +45,7 @@ where Base.Element: ~Copyable { @_lifetime(copy _base) internal init( _base: consuming Base, - isIncluded: @escaping (borrowing Element) -> Bool + isIncluded: @escaping (borrowing Element_) -> Bool ) { self._isIncluded = isIncluded self._base = _base @@ -55,13 +55,13 @@ where Base.Element: ~Copyable { // FIXME: Sendable @available(SwiftStdlib 6.4, *) -extension BorrowingFilter: BorrowingIteratorProtocol -where Base: ~Copyable & ~Escapable, Base.Element: ~Copyable { +extension BorrowingFilter: BorrowingIteratorProtocol_ +where Base: ~Copyable & ~Escapable, Base.Element_: ~Copyable { @_lifetime(&self) - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { // FIXME: This is quite inefficient compared to Container's filter while true { - let span = _base.nextSpan(maximumCount: 1) + let span = _base.nextSpan_(maximumCount: 1) if span.isEmpty { return span } precondition(span.count == 1, "Invalid BorrowingIterator") if _isIncluded(span[unchecked: 0]) { return span } diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift index 62184c5e..95f1b95f 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Map.swift @@ -14,15 +14,15 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { @inlinable @_lifetime(copy self) public consuming func map( - _ transform: @escaping (borrowing Element) throws(E) -> T + _ transform: @escaping (borrowing Element_) throws(E) -> T ) throws(E) -> BorrowingMapProducer { BorrowingMapProducer(_base: self, transform: transform) } @@ -30,12 +30,12 @@ where @available(SwiftStdlib 6.4, *) public struct BorrowingMapProducer< - Base: BorrowingIteratorProtocol & ~Copyable & ~Escapable, + Base: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable, Element: ~Copyable, Error: Swift.Error >: ~Copyable, ~Escapable { @_alwaysEmitIntoClient - public let _transform: (borrowing Base.Element) throws(Error) -> Element + public let _transform: (borrowing Base.Element_) throws(Error) -> Element @_alwaysEmitIntoClient public var _it: Base @@ -44,7 +44,7 @@ public struct BorrowingMapProducer< @_lifetime(copy _base) internal init( _base: consuming Base, - transform: @escaping (borrowing Base.Element) throws(Error) -> Element + transform: @escaping (borrowing Base.Element_) throws(Error) -> Element ) { self._transform = transform self._it = _base @@ -68,7 +68,7 @@ where @inlinable public mutating func next() throws(ProducerError) -> Element? { - let span = _it.nextSpan(maximumCount: 1) + let span = _it.nextSpan_(maximumCount: 1) guard !span.isEmpty else { return nil } return try _transform(span[unchecked: 0]) } @@ -82,7 +82,7 @@ where ) throws(Error) -> Bool { var success = false while !target.isFull { - let span = _it.nextSpan(maximumCount: target.freeCapacity) + let span = _it.nextSpan_(maximumCount: target.freeCapacity) guard !span.isEmpty else { break } success = true var i = 0 diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift index 30dcb6ca..73ea15c3 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+Reduce.swift @@ -14,19 +14,19 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { @inlinable public consuming func reduce( _ initialResult: consuming Result, - _ nextPartialResult: (consuming Result, borrowing Element) throws(E) -> Result + _ nextPartialResult: (consuming Result, borrowing Element_) throws(E) -> Result ) throws(E) -> Result { var result = initialResult while true { - let span = self.nextSpan() + let span = self.nextSpan_() guard !span.isEmpty else { break } var i = 0 while i < span.count { @@ -40,11 +40,11 @@ where @inlinable public consuming func reduce( into initialResult: consuming Result, - _ updateAccumulatingResult: (inout Result, borrowing Element) throws(E) -> Void + _ updateAccumulatingResult: (inout Result, borrowing Element_) throws(E) -> Void ) throws(E) -> Result { var result = initialResult while true { - let span = self.nextSpan() + let span = self.nextSpan_() guard !span.isEmpty else { break } var i = 0 while i < span.count { diff --git a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift index f1af33a2..82378771 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift @@ -18,21 +18,21 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { @inlinable internal consuming func _spanwiseZip< - Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable, + Other: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable, State: ~Copyable, E: Error >( state: inout State, with other: consuming Other, - by process: (inout State, Span, Span) throws(E) -> Bool + by process: (inout State, Span, Span) throws(E) -> Bool ) throws(E) - where Other.Element: ~Copyable + where Other.Element_: ~Copyable { #if true // FIXME: rdar://150228920 Exclusive access scopes aren't expanded enough // Note: This is the less efficient implementation of spanwiseZip. The @@ -41,17 +41,17 @@ where // maximumCounts.) loop: while true { - var a = self.nextSpan() + var a = self.nextSpan_() if a.isEmpty { while true { - let b = other.nextSpan() + let b = other.nextSpan_() guard !b.isEmpty else { break } guard try process(&state, a, b) else { break } } return } repeat { - let b = other.nextSpan(maximumCount: a.count) + let b = other.nextSpan_(maximumCount: 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 5c2f3425..68d5429d 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingIteratorProtocol.swift @@ -17,11 +17,9 @@ import InternalCollectionsUtilities #endif -#if false // Use the stdlib's definition - @available(SwiftStdlib 5.0, *) -public protocol BorrowingIteratorProtocol: ~Copyable, ~Escapable { - associatedtype Element: ~Copyable +public protocol BorrowingIteratorProtocol_: ~Copyable, ~Escapable { + associatedtype Element_: ~Copyable // FIXME: This ought to be a core requirement, but `Ref` is not a thing yet. // @_lifetime(&self) @@ -76,7 +74,7 @@ public protocol BorrowingIteratorProtocol: ~Copyable, ~Escapable { /// method may vary between different borrows of the same container.) @_lifetime(&self) @_lifetime(self: copy self) - mutating func nextSpan(maximumCount: Int) -> Span + mutating func nextSpan_(maximumCount: Int) -> Span /// Advance the position of this iterator by the specified offset, or until /// the end of the underlying sequence. @@ -88,7 +86,7 @@ public protocol BorrowingIteratorProtocol: ~Copyable, ~Escapable { /// /// `maximumOffset` must be nonnegative. @_lifetime(self: copy self) - mutating func skip(by maximumOffset: Int) -> Int + mutating func skip_(by maximumOffset: Int) -> Int // FIXME: Add BidirectionalBorrowingIteratorProtocol and RandomAccessBorrowingIteratorProtocol. // BidirectionalBorrowingIteratorProtocol would need to have a `previousSpan` @@ -98,25 +96,25 @@ public protocol BorrowingIteratorProtocol: ~Copyable, ~Escapable { } @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol -where Self: ~Copyable & ~Escapable, Element: ~Copyable { +extension BorrowingIteratorProtocol_ +where Self: ~Copyable & ~Escapable, Element_: ~Copyable { @_lifetime(&self) @_lifetime(self: copy self) @_transparent - public mutating func nextSpan() -> Span { - nextSpan(maximumCount: Int.max) + public mutating func nextSpan_() -> Span { + nextSpan_(maximumCount: Int.max) } } @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol -where Self: ~Copyable & ~Escapable, Element: ~Copyable { +extension BorrowingIteratorProtocol_ +where Self: ~Copyable & ~Escapable, Element_: ~Copyable { @_lifetime(self: copy self) @inlinable - public mutating func skip(by offset: Int) -> Int { + public mutating func skip_(by offset: Int) -> Int { var remainder = offset while remainder > 0 { - let span = nextSpan(maximumCount: remainder) + let span = nextSpan_(maximumCount: remainder) if span.isEmpty { break } remainder &-= span.count } @@ -125,7 +123,7 @@ where Self: ~Copyable & ~Escapable, Element: ~Copyable { } @available(SwiftStdlib 5.0, *) -extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { +extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable { #if false // FIXME: This doesn't work, but it should? @_lifetime(&self) @_lifetime(self: copy self) @@ -144,20 +142,18 @@ extension BorrowingIteratorProtocol where Self: ~Copyable & ~Escapable { // } } -#endif - @available(SwiftStdlib 6.4, *) -extension BorrowingIteratorProtocol -where Self: ~Copyable & ~Escapable, Element: Copyable +extension BorrowingIteratorProtocol_ +where Self: ~Copyable & ~Escapable, Element_: Copyable { @_lifetime(self: copy self) @inlinable @_transparent - package mutating func _copyContents(into target: inout OutputSpan) { + package mutating func _copyContents_(into target: inout OutputSpan) { target.withUnsafeMutableBufferPointer { dst, dstCount in var tail = dst._extracting(droppingFirst: dstCount) while !tail.isEmpty { - let src = nextSpan(maximumCount: tail.count) + let src = nextSpan_(maximumCount: tail.count) if src.isEmpty { break } tail._initializeAndDropPrefix(copying: src) dstCount += src.count diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift index 19a98fcc..62b26bb2 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Algorithms.swift @@ -14,67 +14,74 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingSequence -where - Self: ~Copyable & ~Escapable, - Element: ~Copyable +extension BorrowingSequence_ + where Self: ~Copyable & ~Escapable, Element_: ~Copyable { @inlinable public func reduce( _ initialResult: consuming Result, _ nextPartialResult: - (_ partialResult: consuming Result, borrowing Element) throws -> Result + (_ partialResult: consuming Result, borrowing Element_) throws -> Result ) rethrows -> Result { - try makeBorrowingIterator().reduce(initialResult, nextPartialResult) + try makeBorrowingIterator_().reduce(initialResult, nextPartialResult) } @inlinable public func reduce( into initialResult: consuming Result, _ updateAccumulatingResult: - (_ partialResult: inout Result, borrowing Element) throws -> () + (_ partialResult: inout Result, borrowing Element_) throws -> () ) rethrows -> Result { - try makeBorrowingIterator().reduce(into: initialResult, updateAccumulatingResult) + try makeBorrowingIterator_().reduce(into: initialResult, updateAccumulatingResult) } - - // Not proposed: can be used to avoid ambiguity. +} + +// Ambiguity breakers +@available(SwiftStdlib 6.4, *) +extension Sequence where Self: BorrowingSequence_ { + public func reduce( + _ initialResult: consuming Result, + _ nextPartialResult: + (_ partialResult: consuming Result, borrowing Element_) throws -> Result + ) rethrows -> Result { + try makeBorrowingIterator_().reduce(initialResult, nextPartialResult) + } + @inlinable - public func _borrowingReduce( + public func reduce( into initialResult: consuming Result, _ updateAccumulatingResult: - (_ partialResult: inout Result, borrowing Element) throws -> () + (_ partialResult: inout Result, borrowing Element_) throws -> () ) rethrows -> Result { - try makeBorrowingIterator().reduce(into: initialResult, updateAccumulatingResult) + try makeBorrowingIterator_().reduce(into: initialResult, updateAccumulatingResult) } } @available(SwiftStdlib 6.4, *) -extension BorrowingSequence -where - Self: ~Copyable & ~Escapable, - Element: ~Copyable +extension BorrowingSequence_ + where Self: ~Copyable & ~Escapable, Element_: ~Copyable { @inlinable - public func elementsEqual( + public func elementsEqual( _ other: borrowing OtherSequence, - by areEquivalent: (borrowing Element, borrowing OtherSequence.Element) throws -> Bool + by areEquivalent: (borrowing Element_, borrowing OtherSequence.Element_) throws -> Bool ) rethrows -> Bool - where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element: ~Copyable + where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element_: ~Copyable { // FIXME: Forward to the iterator's implementation of same - var iter1 = makeBorrowingIterator() - var iter2 = other.makeBorrowingIterator() + var iter1 = makeBorrowingIterator_() + var iter2 = other.makeBorrowingIterator_() while true { - var el1 = iter1.nextSpan() + var el1 = iter1.nextSpan_() if el1.isEmpty { // LHS is empty - sequences are equal iff RHS is also empty - let el2 = iter2.nextSpan(maximumCount: 1) + let el2 = iter2.nextSpan_(maximumCount: 1) return el2.isEmpty } while el1.count > 0 { - let el2 = iter2.nextSpan(maximumCount: el1.count) + let el2 = iter2.nextSpan_(maximumCount: el1.count) if el2.isEmpty { return false } for i in 0..>( + public func elementsEqual>( _ other: borrowing OtherSequence ) -> Bool where OtherSequence: ~Copyable & ~Escapable, - OtherSequence.Element: ~Copyable + OtherSequence.Element_: ~Copyable { return self.elementsEqual(other, by: ==) } diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift index f54beb74..06733ba0 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Standard Conformances.swift @@ -13,33 +13,31 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // Use the stdlib's conformance @available(SwiftStdlib 6.4, *) -extension Span: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = SpanIterator +extension Span: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = SpanIterator + public typealias Element_ = Element @inlinable - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } @_lifetime(borrow self) @inlinable - public func makeBorrowingIterator() -> SpanIterator { + public func makeBorrowingIterator_() -> SpanIterator { SpanIterator(self) } } -#endif -#if false // Use the stdlib's conformance @available(SwiftStdlib 6.4, *) -extension MutableSpan: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = SpanIterator +extension MutableSpan: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = SpanIterator @inlinable - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } @_lifetime(borrow self) @inlinable - public func makeBorrowingIterator() -> SpanIterator { + public func makeBorrowingIterator_() -> SpanIterator { // FIXME: This should be declared to return BorrowingIterator, but it // clashes with the stdlib's alternate definition: // error: 'BorrowingIterator' is ambiguous for type lookup in this context @@ -47,63 +45,59 @@ extension MutableSpan: BorrowingSequence where Element: ~Copyable { SpanIterator(self.span) } } -#endif -#if false // Use the stdlib's conformance @available(SwiftStdlib 6.4, *) -extension OutputSpan: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = SpanIterator +extension OutputSpan: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = SpanIterator @inlinable - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } @_lifetime(borrow self) @inlinable - public func makeBorrowingIterator() -> BorrowingIterator { - SpanIterator(self.span) - } -} -#endif - -@available(SwiftStdlib 6.4, *) -extension InputSpan: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = SpanIterator - - @inlinable - public var underestimatedCount: Int { count } - - @_lifetime(borrow self) - @inlinable - public func makeBorrowingIterator() -> BorrowingIterator { + public func makeBorrowingIterator_() -> BorrowingIterator_ { SpanIterator(self.span) } } @available(SwiftStdlib 6.4, *) -extension Array: @retroactive BorrowingSequence { - public typealias BorrowingIterator = SpanIterator +extension InputSpan: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = SpanIterator @inlinable - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } + + @_lifetime(borrow self) + @inlinable + public func makeBorrowingIterator_() -> BorrowingIterator_ { + SpanIterator(self.span) + } +} + +@available(SwiftStdlib 6.4, *) +extension Array: BorrowingSequence_ { + public typealias BorrowingIterator_ = SpanIterator + + @inlinable + public var underestimatedCount_: Int { count } @_lifetime(borrow self) @inlinable - public func makeBorrowingIterator() -> BorrowingIterator { + public func makeBorrowingIterator_() -> BorrowingIterator_ { SpanIterator(self.span) } } -#if false // Use the stdlib's conformance @available(SwiftStdlib 6.4, *) -extension InlineArray: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = SpanIterator +extension InlineArray: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = SpanIterator @inlinable - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } @_lifetime(borrow self) @inlinable - public func makeBorrowingIterator() -> SpanIterator { + public func makeBorrowingIterator_() -> SpanIterator { // FIXME: This should be declared to return BorrowingIterator, but it // clashes with the stdlib's alternate definition: // error: 'BorrowingIterator' is ambiguous for type lookup in this context @@ -111,17 +105,15 @@ extension InlineArray: BorrowingSequence where Element: ~Copyable { SpanIterator(self.span) } } -#endif -#if false // Use the stdlib's conformance @available(SwiftStdlib 6.4, *) -extension Range: BorrowingSequence +extension Range: BorrowingSequence_ where Bound: Strideable, Bound.Stride: SignedInteger { public typealias Element = Bound @frozen - public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable { + public struct BorrowingIterator_: BorrowingIteratorProtocol_, ~Copyable { @usableFromInline internal var _current: InlineArray<1, Bound> @@ -139,7 +131,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger } @inlinable @_lifetime(&self) - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { if _progress { _current[0] = _current[0].advanced(by: 1) } @@ -162,23 +154,22 @@ where Bound: Strideable, Bound.Stride: SignedInteger } @inlinable - public var underestimatedCount: Int { _borrowingUnderestimatedCount } + public var underestimatedCount_: Int { _borrowingUnderestimatedCount } @inlinable - public func makeBorrowingIterator() -> BorrowingIterator { - BorrowingIterator(self) + public func makeBorrowingIterator_() -> BorrowingIterator_ { + BorrowingIterator_(self) } } -#endif @available(SwiftStdlib 6.4, *) -extension ClosedRange: @retroactive BorrowingSequence +extension ClosedRange: BorrowingSequence_ where Bound: Strideable, Bound.Stride: SignedInteger { public typealias Element = Bound @frozen - public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable { + public struct BorrowingIterator_: BorrowingIteratorProtocol_, ~Copyable { @usableFromInline internal var _current: InlineArray<1, Bound> @@ -196,7 +187,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger } @inlinable @_lifetime(&self) - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { if _progress { _current[0] = _current[0].advanced(by: 1) } @@ -220,11 +211,11 @@ where Bound: Strideable, Bound.Stride: SignedInteger } @inlinable - public var underestimatedCount: Int { _borrowingUnderestimatedCount } + public var underestimatedCount_: Int { _borrowingUnderestimatedCount } @inlinable - public func makeBorrowingIterator() -> BorrowingIterator { - BorrowingIterator(self) + public func makeBorrowingIterator_() -> BorrowingIterator_ { + BorrowingIterator_(self) } } diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift index 0b587d27..8ac56666 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence+Utilities.swift @@ -18,21 +18,21 @@ import InternalCollectionsUtilities #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -extension BorrowingSequence where Self: ~Copyable & ~Escapable, Element: Copyable { +extension BorrowingSequence_ where Self: ~Copyable & ~Escapable, Element_: Copyable { @inlinable package func _copyContents( - intoPrefixOf buffer: UnsafeMutableBufferPointer + intoPrefixOf buffer: UnsafeMutableBufferPointer ) -> Int { var target = buffer - var it = self.makeBorrowingIterator() + var it = self.makeBorrowingIterator_() while target.count != 0 { - let span = it.nextSpan(maximumCount: target.count) + let span = it.nextSpan_(maximumCount: target.count) if span.isEmpty { return buffer.count - target.count } target._initializeAndDropPrefix(copying: span) } - let test = it.nextSpan() + let test = it.nextSpan_() precondition(test.isEmpty, "Contents do not fit in target buffer") return buffer.count } diff --git a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift index 45dcadf2..4ebd1b0e 100644 --- a/Sources/ContainersPreview/Protocols/BorrowingSequence.swift +++ b/Sources/ContainersPreview/Protocols/BorrowingSequence.swift @@ -13,59 +13,57 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // Use the stdlib's definition - @available(SwiftStdlib 5.0, *) -public protocol BorrowingSequence: ~Copyable, ~Escapable { - associatedtype Element: ~Copyable - associatedtype BorrowingIterator: BorrowingIteratorProtocol & ~Copyable & ~Escapable +public protocol BorrowingSequence_: ~Copyable, ~Escapable { + associatedtype Element_: ~Copyable + associatedtype BorrowingIterator_: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable - var underestimatedCount: Int { get } + var underestimatedCount_: Int { get } @_lifetime(borrow self) - borrowing func makeBorrowingIterator() -> BorrowingIterator + borrowing func makeBorrowingIterator_() -> BorrowingIterator_ - func _customContainsEquatableElement( - _ element: borrowing Element + func _customContainsEquatableElement_( + _ element: borrowing Element_ ) -> Bool? } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence +extension BorrowingSequence_ where - Self: ~Copyable & ~Escapable, Element: ~Copyable + Self: ~Copyable & ~Escapable, Element_: ~Copyable { @inlinable - public var underestimatedCount: Int { 0 } + public var underestimatedCount_: Int { 0 } @inlinable - public func _customContainsEquatableElement(_ element: borrowing Element) -> Bool? { + public func _customContainsEquatableElement_(_ element: borrowing Element_) -> Bool? { nil } } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence where Self: Sequence { +extension BorrowingSequence_ where Self: Sequence { @inlinable - public func _customContainsEquatableElement(_ element: borrowing Element) -> Bool? { + public func _customContainsEquatableElement_(_ element: borrowing Element) -> Bool? { nil } } @available(SwiftStdlib 5.0, *) -extension BorrowingSequence +extension BorrowingSequence_ where Self: ~Copyable & ~Escapable, - Element: ~Copyable + Element_: ~Copyable { /// Implementation demo of what borrowing for-in loops would need to expand into. @inlinable public func _borrowingForEach( - _ body: (borrowing Element) throws(E) -> Void + _ body: (borrowing Element_) throws(E) -> Void ) throws(E) -> Void { - var it = makeBorrowingIterator() + var it = makeBorrowingIterator_() while true { - let span = it.nextSpan() + let span = it.nextSpan_() if span.isEmpty { break } var i = 0 while i < span.count { @@ -77,5 +75,3 @@ where } #endif - -#endif diff --git a/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift b/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift index ce353930..8a4734ee 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container+Filter.swift @@ -31,7 +31,7 @@ extension Container where Self: ~Copyable /*& ~Escapable*/, Element: ~Copyable { extension ContainerIterator where Base.Element: ~Copyable { @_lifetime(copy self) public func filter( - _ isIncluded: @escaping (borrowing Element) -> Bool + _ isIncluded: @escaping (borrowing Element_) -> Bool ) -> ContainerFilter { ContainerFilter(_base: _base, index: _position, isIncluded: isIncluded) } diff --git a/Sources/ContainersPreview/Protocols/Container/Container.swift b/Sources/ContainersPreview/Protocols/Container/Container.swift index d21e387b..db4781c1 100644 --- a/Sources/ContainersPreview/Protocols/Container/Container.swift +++ b/Sources/ContainersPreview/Protocols/Container/Container.swift @@ -14,9 +14,10 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) -public protocol Container: BorrowingSequence, ~Copyable, ~Escapable -where Element: ~Copyable +public protocol Container: BorrowingSequence_, ~Copyable, ~Escapable +where Element: ~Copyable, Element == Element_ { + associatedtype Element: ~Copyable associatedtype Index: Comparable // FIXME: Ideally Index should also be required to be Hashable. // FIXME: If we discard the separate BorrowingSequence abstraction, then we diff --git a/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift b/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift index 381647e1..56987c93 100644 --- a/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift +++ b/Sources/ContainersPreview/Protocols/Container/ContainerIterator.swift @@ -18,10 +18,10 @@ extension Container where Self: ~Copyable /*FIXME: & ~Escapable*/, Element: ~Copyable, - BorrowingIterator == ContainerIterator + BorrowingIterator_ == ContainerIterator { @_lifetime(borrow self) - public func makeBorrowingIterator() -> BorrowingIterator { + public func makeBorrowingIterator_() -> BorrowingIterator_ { ContainerIterator(_borrowing: self, from: self.startIndex) } } @@ -43,16 +43,16 @@ where Base.Element: ~Copyable } @available(SwiftStdlib 6.4, *) -extension ContainerIterator: BorrowingIteratorProtocol +extension ContainerIterator: BorrowingIteratorProtocol_ where Base: ~Copyable /*FIXME: & ~Escapable*/, Base.Element: ~Copyable { - public typealias Element = Base.Element + public typealias Element_ = Base.Element @_unsafeNonescapableResult // FIXME: we cannot convert from a borrow to an inout dependence?! @_lifetime(&self) - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { _base.value.nextSpan(after: &self._position, maximumCount: maximumCount) } @@ -69,7 +69,7 @@ where // } @_lifetime(self: copy self) - public mutating func skip(by maximumOffset: Int) -> Int { + public mutating func skip_(by maximumOffset: Int) -> Int { // FIXME: If we aren't modeling bidirectional iterators, then this should // trap on negative maximumOffsets var n = maximumOffset diff --git a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift index 2c286b86..5502a926 100644 --- a/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift +++ b/Sources/ContainersPreview/Protocols/Container/RangeReplaceableContainer.swift @@ -425,13 +425,13 @@ where @inlinable public mutating func append< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() while true { - let span = it.nextSpan() + let span = it.nextSpan_() guard !span.isEmpty else { break } self.append(copying: span) } diff --git a/Sources/ContainersPreview/Types/SpanIterator.swift b/Sources/ContainersPreview/Types/SpanIterator.swift index 06378069..d1e4a2ed 100644 --- a/Sources/ContainersPreview/Types/SpanIterator.swift +++ b/Sources/ContainersPreview/Types/SpanIterator.swift @@ -13,23 +13,21 @@ #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW -#if false // Use the stdlib's definition - /// A borrowing iterator that provides access to the elements of a single /// span through a `BorrowingIteratorProtocol` interface. @available(SwiftStdlib 6.4, *) -public struct SpanIterator: BorrowingIteratorProtocol, ~Copyable, ~Escapable - where Element: ~Copyable +public struct SpanIterator: BorrowingIteratorProtocol_, ~Copyable, ~Escapable + where Element_: ~Copyable { @usableFromInline - internal var _span: Span + internal var _span: Span @usableFromInline internal var _start: Int @usableFromInline internal var _count: Int @_lifetime(copy elements) - public init(_ elements: Span) { + public init(_ elements: Span) { _span = elements _start = 0 _count = elements.count @@ -39,7 +37,7 @@ public struct SpanIterator: BorrowingIteratorProtocol, ~Copyable, ~Esca @_lifetime(&self) @_lifetime(self: copy self) @_transparent - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { let c = Swift.min(maximumCount, _count) defer { _start &+= c @@ -50,7 +48,7 @@ public struct SpanIterator: BorrowingIteratorProtocol, ~Copyable, ~Esca @_alwaysEmitIntoClient @_lifetime(self: copy self) - public mutating func skip(by offset: Int) -> Int { + public mutating func skip_(by offset: Int) -> Int { let c = Swift.min(offset, _count) defer { _start &+= c @@ -61,4 +59,3 @@ public struct SpanIterator: BorrowingIteratorProtocol, ~Copyable, ~Esca } #endif -#endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift index 71e0df20..7bfc2385 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Append.swift @@ -314,11 +314,11 @@ extension RigidDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient internal mutating func _append< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >(copying items: borrowing S) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() while true { - let span = it.nextSpan() + let span = it.nextSpan_() if span.isEmpty { break } self.append(copying: span) } @@ -336,7 +336,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// - Complexity: O(*m*), where *m* is the length of `newElements`. @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient - public mutating func append & ~Copyable & ~Escapable>( + public mutating func append & ~Copyable & ~Escapable>( copying newElements: borrowing S ) { self._append(copying: newElements) @@ -378,7 +378,7 @@ extension RigidDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public mutating func append< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( copying items: S ) { diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift index b58eb69c..e887e280 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Container.swift @@ -23,7 +23,7 @@ import ContainersPreview extension RigidDeque where Element: ~Copyable { #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @frozen - public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol { + public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol_ { @usableFromInline internal var _currentSegment: Span @@ -46,7 +46,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(copy self) @_lifetime(self: copy self) - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { let result = _currentSegment._trim(first: maximumCount) if _currentSegment.isEmpty { _currentSegment = _nextSegment @@ -58,7 +58,7 @@ extension RigidDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) - public borrowing func makeBorrowingIterator() -> BorrowingIterator { + public borrowing func makeBorrowingIterator_() -> BorrowingIterator { BorrowingIterator(_deque: self) } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift index ba902590..eb8e82bb 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Initializers.swift @@ -133,7 +133,7 @@ extension RigidDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( capacity: Int, copying contents: borrowing S @@ -189,7 +189,7 @@ extension RigidDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( capacity: Int, copying contents: borrowing S @@ -211,7 +211,7 @@ extension RigidDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & Collection + S: BorrowingSequence_ & Collection >( capacity: Int? = nil, copying contents: S diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift index 5dd41bd5..c522029e 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Insertions.swift @@ -365,12 +365,12 @@ extension RigidDeque /* where Element: Copyable */ { newCount: Int ) { let expectedCount = self.count + newCount - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() insert(addingCount: newCount, at: index) { target in - it._copyContents(into: &target) + it._copyContents_(into: &target) } precondition( - it.nextSpan().isEmpty && self.count == expectedCount, + it.nextSpan_().isEmpty && self.count == expectedCount, "Broken Container: count doesn't match contents") } #endif diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift index 8c9671ac..bc7d92de 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Prepend.swift @@ -291,13 +291,13 @@ extension RigidDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @inlinable internal mutating func _prepend< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >(copying items: borrowing S) { // We don't know the exact count of new elements, so we cannot initialize // them in place. Append them to the end of the deque first, then rotate // them to their correct location. // - // FIXME: If we get a BorrowingSequence.estimatedCount with an exact case, + // FIXME: If we get a BorrowingSequence_.estimatedCount with an exact case, // then we should use that when possible to copy items to their final // location in a single pass. let oldCount = self.count @@ -308,14 +308,14 @@ extension RigidDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @inlinable internal mutating func _prepend< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S, exactCount: Int ) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() self.prepend(addingCount: exactCount) { target in - let span = it.nextSpan(maximumCount: target.freeCapacity) + let span = it.nextSpan_(maximumCount: target.freeCapacity) target._append(copying: span) } } @@ -336,7 +336,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// - Complexity: O(*m*), where *m* is the length of `items`. @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient - public mutating func prepend & ~Copyable & ~Escapable>( + public mutating func prepend & ~Copyable & ~Escapable>( copying items: borrowing S ) { self._prepend(copying: items) @@ -442,7 +442,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// - Complexity: O(*m*), where *m* is the length of `items`. @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient - public mutating func prepend & Sequence>( + public mutating func prepend & Sequence>( copying items: borrowing S ) { self._prepend(copying: items) @@ -459,7 +459,7 @@ extension RigidDeque /*where Element: Copyable*/ { /// - Complexity: O(*m*), where *m* is the length of `items`. @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient - public mutating func prepend & Collection>( + public mutating func prepend & Collection>( copying items: borrowing S ) { self._prepend(copying: items, exactCount: items.count) diff --git a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift index 5b8239db..8ee33e45 100644 --- a/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift +++ b/Sources/DequeModule/RigidDeque/RigidDeque+Replacements.swift @@ -467,12 +467,12 @@ extension RigidDeque /* where Element: Copyable */ { ) { let expectedCount = self.count - subrange.count + newCount - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() self.replace(removing: subrange, addingCount: newCount) { target in - it._copyContents(into: &target) + it._copyContents_(into: &target) } precondition( - it.nextSpan().isEmpty && count == expectedCount, + it.nextSpan_().isEmpty && count == expectedCount, "Broken Container: count doesn't match contents") } #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift index 8f84ad3e..ec12e540 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Append.swift @@ -301,11 +301,11 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient internal mutating func _append< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >(copying items: borrowing S) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() while true { - let span = it.nextSpan() + let span = it.nextSpan_() if span.isEmpty { break } self.append(copying: span) } @@ -325,7 +325,7 @@ extension UniqueDeque /*where Element: Copyable*/ { /// over many similar invocations on the same deque @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient - public mutating func append & ~Copyable & ~Escapable>( + public mutating func append & ~Copyable & ~Escapable>( copying items: borrowing S ) { self._append(copying: items) @@ -377,7 +377,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public mutating func append< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( copying items: S ) { diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift index dcce942d..ffeb440a 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Container.swift @@ -26,7 +26,7 @@ extension UniqueDeque where Element: ~Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) - public borrowing func makeBorrowingIterator() -> BorrowingIterator { + public borrowing func makeBorrowingIterator_() -> BorrowingIterator { BorrowingIterator(_deque: self._storage) } #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift index b75b3e6c..e9a15363 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Initializers.swift @@ -155,7 +155,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( capacity: Int? = nil, copying contents: borrowing S @@ -195,7 +195,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( capacity: Int? = nil, copying contents: S @@ -215,7 +215,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @_alwaysEmitIntoClient @inline(__always) public init< - S: BorrowingSequence & Collection + S: BorrowingSequence_ & Collection >( capacity: Int? = nil, copying contents: S diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift index a9b985c1..7ce32388 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Insertions.swift @@ -383,12 +383,12 @@ extension UniqueDeque /* where Element: Copyable */ { newCount: Int ) { let expectedCount = self.count + newCount - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() insert(addingCount: newCount, at: index) { target in - it._copyContents(into: &target) + it._copyContents_(into: &target) } precondition( - it.nextSpan().isEmpty && count == expectedCount, + it.nextSpan_().isEmpty && count == expectedCount, "Broken Container: count doesn't match contents") } #endif diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift index 565593c6..936a5205 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Prepend.swift @@ -323,7 +323,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @inlinable internal mutating func _prepend< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >(copying items: borrowing S) { // We don't know the exact count of new elements, so we cannot initialize // them in place. Append them to the end of the deque first, then rotate @@ -340,14 +340,14 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @inlinable internal mutating func _prepend< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S, exactCount: Int ) { - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() self.prepend(addingCount: exactCount) { target in - let span = it.nextSpan(maximumCount: target.freeCapacity) + let span = it.nextSpan_(maximumCount: target.freeCapacity) target._append(copying: span) } } @@ -370,7 +370,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public mutating func prepend< - S: BorrowingSequence & ~Copyable & ~Escapable + S: BorrowingSequence_ & ~Copyable & ~Escapable >( copying items: borrowing S ) { @@ -482,7 +482,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public mutating func prepend< - S: BorrowingSequence & Sequence + S: BorrowingSequence_ & Sequence >( copying items: borrowing S ) { @@ -502,7 +502,7 @@ extension UniqueDeque /*where Element: Copyable*/ { @available(SwiftStdlib 6.4, *) @_alwaysEmitIntoClient public mutating func prepend< - S: BorrowingSequence & Collection + S: BorrowingSequence_ & Collection >( copying items: borrowing S ) { diff --git a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift index 9a276934..3a3838d2 100644 --- a/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift +++ b/Sources/DequeModule/UniqueDeque/UniqueDeque+Replacements.swift @@ -476,12 +476,12 @@ extension UniqueDeque /* where Element: Copyable */ { ) { let expectedCount = self.count - subrange.count + newCount - var it = items.makeBorrowingIterator() + var it = items.makeBorrowingIterator_() self.replace(removing: subrange, addingCount: newCount) { target in - it._copyContents(into: &target) + it._copyContents_(into: &target) } precondition( - it.nextSpan().isEmpty && count == expectedCount, + it.nextSpan_().isEmpty && count == expectedCount, "Broken Container: count doesn't match contents") } #endif diff --git a/Tests/BasicContainersTests/RigidArrayTests.swift b/Tests/BasicContainersTests/RigidArrayTests.swift index b3e57d4e..8c701dee 100644 --- a/Tests/BasicContainersTests/RigidArrayTests.swift +++ b/Tests/BasicContainersTests/RigidArrayTests.swift @@ -1365,7 +1365,7 @@ class RigidArrayTests: CollectionTestCase { func test_borrowing_map() { let c = 100 let items = RigidArray(capacity: c, copying: 0 ..< c) - let transformed = items.makeBorrowingIterator() + let transformed = items.makeBorrowingIterator_() .map { 2 * $0 } .collect(into: UniqueArray.self) expectEqual(transformed.count, c) @@ -1379,7 +1379,7 @@ class RigidArrayTests: CollectionTestCase { func test_borrowing_filter() { let c = 100 let items = RigidArray(capacity: c, copying: 0 ..< c) - let transformed = items.makeBorrowingIterator() + let transformed = items.makeBorrowingIterator_() .filter { !$0.isMultiple(of: 6) } .copy() .collect(into: UniqueArray.self) diff --git a/Tests/ContainersTests/BorrowingSequenceTests.swift b/Tests/ContainersTests/BorrowingSequenceTests.swift index a2ea6a5f..11b40b2d 100644 --- a/Tests/ContainersTests/BorrowingSequenceTests.swift +++ b/Tests/ContainersTests/BorrowingSequenceTests.swift @@ -34,8 +34,7 @@ final class BorrowingSequenceTests: XCTestCase { // XCTAssertTrue(spanCollected.elementsEqual(spanCollected)) XCTAssertEqual(array.reduce(0, +), span.reduce(0, +)) - // Using 'borrowingReduce' to avoid ambiguity: - XCTAssertEqual(array._borrowingReduce(into: 0, +=), span.reduce(into: 0, +=)) + XCTAssertEqual(array.reduce(into: 0, +=), span.reduce(into: 0, +=)) let inline: [8 of Int] = [1, 2, 3, 4, 5, 6, 7, 8] let inlineCollected = inline.collectViaBorrowing() diff --git a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift index 7034a6b9..7155c925 100644 --- a/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift +++ b/Tests/_CollectionsTestSupport/AssertionContexts/Assertions+Containers.swift @@ -127,7 +127,7 @@ public func expectIterableContents< @available(SwiftStdlib 6.4, *) public func expectIterablePayloads< Payload: Equatable, - E1: BorrowingSequence> & ~Copyable & ~Escapable, + E1: BorrowingSequence_> & ~Copyable & ~Escapable, C2: Collection, >( _ left: borrowing E1, @@ -136,12 +136,12 @@ public func expectIterablePayloads< trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line -) where E1.Element: ~Copyable { - var it1 = left.makeBorrowingIterator() +) where E1.Element_: ~Copyable { + var it1 = left.makeBorrowingIterator_() var it2 = right.makeIterator() var i = 0 while true { - let next1 = it1.nextSpan(maximumCount: 1) + let next1 = it1.nextSpan_(maximumCount: 1) let next2 = it2.next() switch (next1.isEmpty, next2) { case (true, nil): @@ -174,7 +174,7 @@ public func expectIterablePayloads< @available(SwiftStdlib 6.4, *) public func expectIterablePayloads< Payload: Equatable, - E1: BorrowingSequence> & ~Copyable & ~Escapable, + E1: BorrowingSequence_> & ~Copyable & ~Escapable, C2: Collection, >( _ left: borrowing E1, @@ -184,11 +184,11 @@ public func expectIterablePayloads< file: StaticString = #filePath, line: UInt = #line ) { - var it1 = left.makeBorrowingIterator() + var it1 = left.makeBorrowingIterator_() var it2 = right.makeIterator() var i = 0 while true { - let next1 = it1.nextSpan(maximumCount: 1) + let next1 = it1.nextSpan_(maximumCount: 1) let next2 = it2.next() switch (next1.isEmpty, next2) { case (true, nil): @@ -220,20 +220,20 @@ public func expectIterablePayloads< #if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW @available(SwiftStdlib 6.4, *) public func expectIterablesWithEquivalentElements< - S1: BorrowingSequence & ~Copyable & ~Escapable, - S2: BorrowingSequence & ~Copyable & ~Escapable + S1: BorrowingSequence_ & ~Copyable & ~Escapable, + S2: BorrowingSequence_ & ~Copyable & ~Escapable >( _ left: borrowing S1, _ right: borrowing S2, - by areEquivalent: (borrowing S1.Element, borrowing S2.Element) -> Bool, + by areEquivalent: (borrowing S1.Element_, borrowing S2.Element_) -> Bool, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line ) where - S1.Element: ~Copyable, - S2.Element: ~Copyable + S1.Element_: ~Copyable, + S2.Element_: ~Copyable { if left._elementsEqual(right, by: areEquivalent) { return } _expectFailure( @@ -245,8 +245,8 @@ where @available(SwiftStdlib 6.4, *) public func expectIterablesWithEqualElements< Element: Equatable, - S1: BorrowingSequence & ~Copyable & ~Escapable, - S2: BorrowingSequence & ~Copyable & ~Escapable, + S1: BorrowingSequence_ & ~Copyable & ~Escapable, + S2: BorrowingSequence_ & ~Copyable & ~Escapable, >( _ left: borrowing S1, _ right: borrowing S2, @@ -256,8 +256,8 @@ public func expectIterablesWithEqualElements< line: UInt = #line ) where - S1.Element: ~Copyable, - S2.Element: ~Copyable + S1.Element_: ~Copyable, + S2.Element_: ~Copyable { if left._elementsEqual(right) { return } _expectFailure( @@ -269,7 +269,7 @@ where @available(SwiftStdlib 6.4, *) public func expectIterableContents< Element: Equatable, - S1: BorrowingSequence & ~Copyable & ~Escapable, + S1: BorrowingSequence_ & ~Copyable & ~Escapable, C2: Collection, >( _ left: borrowing S1, @@ -279,10 +279,10 @@ public func expectIterableContents< file: StaticString = #filePath, line: UInt = #line ) { - var it1 = left.makeBorrowingIterator() + var it1 = left.makeBorrowingIterator_() var it2 = right.makeIterator() while true { - let span = it1.nextSpan() + let span = it1.nextSpan_() if span.isEmpty { break } for i in 0 ..< span.count { guard let b = it2.next() else { @@ -310,23 +310,23 @@ public func expectIterableContents< /// Check if `left` and `right` contain equal elements in the same order. @available(SwiftStdlib 6.4, *) public func expectIterableContents< - S1: BorrowingSequence & ~Copyable & ~Escapable, + S1: BorrowingSequence_ & ~Copyable & ~Escapable, C2: Collection, >( _ left: borrowing S1, equivalentTo right: C2, - by areEquivalent: (borrowing S1.Element, C2.Element) -> Bool, - printer: (borrowing S1.Element) -> String, + by areEquivalent: (borrowing S1.Element_, C2.Element) -> Bool, + printer: (borrowing S1.Element_) -> String, _ message: @autoclosure () -> String = "", trapping: Bool = false, file: StaticString = #filePath, line: UInt = #line -) where S1.Element: ~Copyable { - var it1 = left.makeBorrowingIterator() +) where S1.Element_: ~Copyable { + var it1 = left.makeBorrowingIterator_() var it2 = right.makeIterator() var offset = 0 while true { - let span = it1.nextSpan() + let span = it1.nextSpan_() if span.isEmpty { break } for i in 0 ..< span.count { guard let b = it2.next() else { diff --git a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift index 5c95911d..a1b380d1 100644 --- a/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift +++ b/Tests/_CollectionsTestSupport/ConformanceCheckers/CheckContainer.swift @@ -22,14 +22,14 @@ import ContainersPreview @available(SwiftStdlib 6.4, *) @inlinable public func checkIterable< - S: BorrowingSequence & ~Copyable & ~Escapable, - Expected: Sequence + S: BorrowingSequence_ & ~Copyable & ~Escapable, + Expected: Sequence >( _ iterable: borrowing S, expectedContents: Expected, file: StaticString = #filePath, line: UInt = #line -) where S.Element: Equatable { +) where S.Element_: Equatable { checkIterable( iterable, expectedContents: expectedContents, @@ -40,30 +40,30 @@ public func checkIterable< @available(SwiftStdlib 6.4, *) @inlinable public func checkIterable< - S: BorrowingSequence & ~Copyable & ~Escapable, - Expected: Sequence + S: BorrowingSequence_ & ~Copyable & ~Escapable, + Expected: Sequence >( _ iterable: borrowing S, expectedContents: Expected, - by areEquivalent: (S.Element, S.Element) -> Bool, + by areEquivalent: (S.Element_, S.Element_) -> Bool, file: StaticString = #filePath, line: UInt = #line -) where S.Element: Equatable { +) where S.Element_: Equatable { let entry = TestContext.current.push("checkIterable", file: file, line: line) defer { TestContext.current.pop(entry) } let expectedContents = Array(expectedContents) - expectLessThanOrEqual(iterable.underestimatedCount, expectedContents.count) + expectLessThanOrEqual(iterable.underestimatedCount_, expectedContents.count) // Check that the spans seem plausibly sized and that the indices are monotonic. let spanShapes: [Range] = { var r: [Range] = [] var pos = 0 - var it = iterable.makeBorrowingIterator() + var it = iterable.makeBorrowingIterator_() while true { let origPos = pos - let span = it.nextSpan() + let span = it.nextSpan_() pos += span.count if span.isEmpty { break @@ -79,10 +79,10 @@ public func checkIterable< // Check that the spans have stable sizes and the expected contents. do { var pos = 0 - var it = iterable.makeBorrowingIterator() + var it = iterable.makeBorrowingIterator_() var spanIndex = 0 while true { - let span = it.nextSpan() + let span = it.nextSpan_() if span.isEmpty { break } expectEqual( span.count, spanShapes[spanIndex].count, @@ -100,9 +100,9 @@ public func checkIterable< // Check that we can iterate one by one. do { var pos = 0 - var it = iterable.makeBorrowingIterator() + var it = iterable.makeBorrowingIterator_() while true { - let span = it.nextSpan(maximumCount: 1) + let span = it.nextSpan_(maximumCount: 1) if span.isEmpty { break } expectEqual(span.count, 1) for i in 0 ..< span.count { @@ -116,10 +116,10 @@ public func checkIterable< // Check that we can iterate with huge maximum counts do { var pos = 0 - var it = iterable.makeBorrowingIterator() + var it = iterable.makeBorrowingIterator_() var spanIndex = 0 while true { - let span = it.nextSpan(maximumCount: Int.max) + let span = it.nextSpan_(maximumCount: Int.max) if span.isEmpty { break } expectEqual( span.count, spanShapes[spanIndex].count, diff --git a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift index 37d68b59..4bf7b5dd 100644 --- a/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift +++ b/Tests/_CollectionsTestSupport/MinimalTypes/StaccatoContainer.swift @@ -76,7 +76,7 @@ package struct _StaccatoParameters { } @available(SwiftStdlib 5.0, *) -public struct _StaccatoBorrowingIterator: BorrowingIteratorProtocol, ~Escapable { +public struct _StaccatoBorrowingIterator: BorrowingIteratorProtocol_, ~Escapable { internal let _contents: Span internal let _params: _StaccatoParameters internal var _offset: Int @@ -89,7 +89,7 @@ public struct _StaccatoBorrowingIterator: BorrowingIteratorP } @_lifetime(copy self) - public mutating func nextSpan(maximumCount: Int) -> Span { + public mutating func nextSpan_(maximumCount: Int) -> Span { let endOffset = _params.endOffset(fromOffset: _offset, maximumCount: maximumCount) let startOffset = _offset _offset = endOffset @@ -114,13 +114,13 @@ public struct _StaccatoIndex: Comparable { } @available(SwiftStdlib 5.0, *) -extension StaccatoContainer: BorrowingSequence where Element: ~Copyable { - public typealias BorrowingIterator = _StaccatoBorrowingIterator // FIXME rdar://150240032 +extension StaccatoContainer: BorrowingSequence_ where Element: ~Copyable { + public typealias BorrowingIterator_ = _StaccatoBorrowingIterator // FIXME rdar://150240032 - public var underestimatedCount: Int { count } + public var underestimatedCount_: Int { count } - public func makeBorrowingIterator() -> BorrowingIterator { - BorrowingIterator(contents: _contents.span, params: _params) + public func makeBorrowingIterator_() -> BorrowingIterator_ { + BorrowingIterator_(contents: _contents.span, params: _params) } }