Disambiguate ContainersPreview and stdlib

Adds trailing underscores to the BorrowingSequence protocols and
requirements, in order to allow both parallel conformances and
the ability to evolve the requirements in this package.
This commit is contained in:
Nate Cook committed 2026-03-27 07:41:32 -05:00
1 parent 4c04822689
commit a99a015934
49 files changed
+350 -363

No files matched your search

+2 -2
View File
@@ -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"
@@ -350,7 +350,7 @@ extension RigidArray {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _append<
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) {
@@ -373,7 +373,7 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) {
@@ -416,7 +416,7 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: BorrowingSequence<Element> & Sequence<Element>
Source: BorrowingSequence_<Element> & Sequence<Element>
>(copying newElements: Source) {
_append(copying: newElements)
}
@@ -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<Element>
extension RigidArray: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = SpanIterator<Element>
@_alwaysEmitIntoClient
@inline(__always)
public func makeBorrowingIterator() -> BorrowingIterator {
public func makeBorrowingIterator_() -> BorrowingIterator_ {
SpanIterator(self.span)
}
}
@@ -125,7 +125,7 @@ extension RigidArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
public init<Source: BorrowingSequence_<Element> & ~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<Source: BorrowingSequence<Element> & Sequence<Element>>(
public init<Source: BorrowingSequence_<Element> & Sequence<Element>>(
capacity: Int,
copying contents: Source
) {
@@ -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
@@ -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")
}
}
@@ -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
@@ -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)
@@ -86,7 +86,7 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
capacity: Int,
copying contents: borrowing S
@@ -121,7 +121,7 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
capacity: Int,
copying contents: borrowing S
@@ -134,7 +134,7 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & Collection<Element>
S: BorrowingSequence_<Element> & Collection<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -224,7 +224,7 @@ extension RigidSet /* where Element: Copyable */ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
package mutating func _insert<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing S
) {
@@ -242,7 +242,7 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing S
) {
@@ -264,7 +264,7 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: BorrowingSequence<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
copying items: borrowing S
) {
@@ -311,14 +311,14 @@ extension UniqueArray {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _append<
Source: BorrowingSequence<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence_<Element> & ~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<Element> & ~Copyable & ~Escapable
Source: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) {
@@ -400,7 +400,7 @@ extension UniqueArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: BorrowingSequence<Element> & Sequence<Element>
Source: BorrowingSequence_<Element> & Sequence<Element>
>(copying newElements: Source) {
self._append(copying: newElements)
}
@@ -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<Element>.BorrowingIterator
extension UniqueArray: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = RigidArray<Element>.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
@@ -105,7 +105,7 @@ extension UniqueArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
public init<Source: BorrowingSequence_<Element> & ~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<Source: BorrowingSequence<Element> & Sequence<Element>>(
public init<Source: BorrowingSequence_<Element> & Sequence<Element>>(
capacity: Int? = nil,
copying contents: Source
) {
@@ -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<Element>.BorrowingIterator
@inlinable
public var underestimatedCount: Int { count }
@inlinable
public func _customContainsEquatableElement(
public func _customContainsEquatableElement_(
_ element: borrowing Element
) -> Bool? {
self.contains(element)
@@ -78,7 +78,7 @@ extension UniqueSet where Element: Copyable {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public init<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing S
) {
@@ -97,7 +97,7 @@ extension UniqueSet where Element: Copyable {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public init<
S: BorrowingSequence<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
copying items: borrowing S
) {
@@ -133,7 +133,7 @@ extension UniqueSet /* where Element: Copyable */ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
package mutating func _insert<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing S
) {
@@ -152,7 +152,7 @@ extension UniqueSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing S
) {
@@ -175,7 +175,7 @@ extension UniqueSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: BorrowingSequence<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
copying items: borrowing S
) {
@@ -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<Self, Element, Never> {
public consuming func copy() -> BorrowingMapProducer<Self, Element_, Never> {
// FIXME: We could also just define a direct implementation that avoids the closure.
BorrowingMapProducer(_base: self, transform: { $0 })
}
@@ -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<Element> & ~Copyable & ~Escapable
Other: BorrowingSequence_<Element_> & ~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<Element> & ~Copyable & ~Escapable
Other: BorrowingIteratorProtocol_<Element_> & ~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<Element> & ~Copyable & ~Escapable
Other: BorrowingIteratorProtocol_<Element_> & ~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
@@ -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<Self> {
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<Element> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Element_> {
// 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 }
@@ -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<E: Error, T: ~Copyable>(
_ transform: @escaping (borrowing Element) throws(E) -> T
_ transform: @escaping (borrowing Element_) throws(E) -> T
) throws(E) -> BorrowingMapProducer<Self, T, E> {
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
@@ -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<Result: ~Copyable, E: Error>(
_ 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<Result: ~Copyable, E: Error>(
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 {
@@ -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<Element>, Span<Other.Element>) throws(E) -> Bool
by process: (inout State, Span<Element_>, Span<Other.Element_>) 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 {
@@ -17,11 +17,9 @@
import InternalCollectionsUtilities
#endif
#if false // Use the stdlib's definition
@available(SwiftStdlib 5.0, *)
public protocol BorrowingIteratorProtocol<Element>: ~Copyable, ~Escapable {
associatedtype Element: ~Copyable
public protocol BorrowingIteratorProtocol_<Element_>: ~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<Element>: ~Copyable, ~Escapable {
/// method may vary between different borrows of the same container.)
@_lifetime(&self)
@_lifetime(self: copy self)
mutating func nextSpan(maximumCount: Int) -> Span<Element>
mutating func nextSpan_(maximumCount: Int) -> Span<Element_>
/// 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<Element>: ~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<Element>: ~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<Element> {
nextSpan(maximumCount: Int.max)
public mutating func nextSpan_() -> Span<Element_> {
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<Element>) {
package mutating func _copyContents_(into target: inout OutputSpan<Element_>) {
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
@@ -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<Result: ~Copyable>(
_ 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<Result>(
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<Result: ~Copyable>(
_ initialResult: consuming Result,
_ nextPartialResult:
(_ partialResult: consuming Result, borrowing Element_) throws -> Result
) rethrows -> Result {
try makeBorrowingIterator_().reduce(initialResult, nextPartialResult)
}
@inlinable
public func _borrowingReduce<Result>(
public func reduce<Result>(
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<OtherSequence: BorrowingSequence>(
public func elementsEqual<OtherSequence: BorrowingSequence_>(
_ 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..<el2.count {
if try !areEquivalent(el1[i], el2[i]) { return false }
@@ -86,15 +93,15 @@ where
}
@available(SwiftStdlib 6.4, *)
extension BorrowingSequence
where Self: ~Copyable & ~Escapable, Element: ~Copyable & Equatable {
extension BorrowingSequence_
where Self: ~Copyable & ~Escapable, Element_: ~Copyable & Equatable {
@inlinable
public func elementsEqual<OtherSequence: BorrowingSequence<Element>>(
public func elementsEqual<OtherSequence: BorrowingSequence_<Element_>>(
_ other: borrowing OtherSequence
) -> Bool
where
OtherSequence: ~Copyable & ~Escapable,
OtherSequence.Element: ~Copyable
OtherSequence.Element_: ~Copyable
{
return self.elementsEqual(other, by: ==)
}
@@ -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<Element>
extension Span: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = SpanIterator<Element>
public typealias Element_ = Element
@inlinable
public var underestimatedCount: Int { count }
public var underestimatedCount_: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator() -> SpanIterator<Element> {
public func makeBorrowingIterator_() -> SpanIterator<Element> {
SpanIterator(self)
}
}
#endif
#if false // Use the stdlib's conformance
@available(SwiftStdlib 6.4, *)
extension MutableSpan: BorrowingSequence where Element: ~Copyable {
public typealias BorrowingIterator = SpanIterator<Element>
extension MutableSpan: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = SpanIterator<Element>
@inlinable
public var underestimatedCount: Int { count }
public var underestimatedCount_: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator() -> SpanIterator<Element> {
public func makeBorrowingIterator_() -> SpanIterator<Element> {
// 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<Element>
extension OutputSpan: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = SpanIterator<Element>
@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<Element>
@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<Element>
extension InputSpan: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = SpanIterator<Element>
@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<Element>
@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<Element>
extension InlineArray: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = SpanIterator<Element>
@inlinable
public var underestimatedCount: Int { count }
public var underestimatedCount_: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator() -> SpanIterator<Element> {
public func makeBorrowingIterator_() -> SpanIterator<Element> {
// 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<Bound> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Bound> {
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<Bound> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Bound> {
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)
}
}
@@ -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<Element>
intoPrefixOf buffer: UnsafeMutableBufferPointer<Element_>
) -> 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
}
@@ -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<Element>: ~Copyable, ~Escapable {
associatedtype Element: ~Copyable
associatedtype BorrowingIterator: BorrowingIteratorProtocol<Element> & ~Copyable & ~Escapable
public protocol BorrowingSequence_<Element_>: ~Copyable, ~Escapable {
associatedtype Element_: ~Copyable
associatedtype BorrowingIterator_: BorrowingIteratorProtocol_<Element_> & ~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<E: Error>(
_ 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
@@ -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<Base> {
ContainerFilter(_base: _base, index: _position, isIncluded: isIncluded)
}
@@ -14,9 +14,10 @@
#if compiler(>=6.4) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 6.4, *)
public protocol Container<Element>: BorrowingSequence, ~Copyable, ~Escapable
where Element: ~Copyable
public protocol Container<Element>: 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
@@ -18,10 +18,10 @@ extension Container
where
Self: ~Copyable /*FIXME: & ~Escapable*/,
Element: ~Copyable,
BorrowingIterator == ContainerIterator<Self>
BorrowingIterator_ == ContainerIterator<Self>
{
@_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<Base.Element> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Base.Element> {
_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
@@ -425,13 +425,13 @@ where
@inlinable
public mutating func append<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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)
}
@@ -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<Element>: BorrowingIteratorProtocol, ~Copyable, ~Escapable
where Element: ~Copyable
public struct SpanIterator<Element_>: BorrowingIteratorProtocol_, ~Copyable, ~Escapable
where Element_: ~Copyable
{
@usableFromInline
internal var _span: Span<Element>
internal var _span: Span<Element_>
@usableFromInline
internal var _start: Int
@usableFromInline
internal var _count: Int
@_lifetime(copy elements)
public init(_ elements: Span<Element>) {
public init(_ elements: Span<Element_>) {
_span = elements
_start = 0
_count = elements.count
@@ -39,7 +37,7 @@ public struct SpanIterator<Element>: BorrowingIteratorProtocol, ~Copyable, ~Esca
@_lifetime(&self)
@_lifetime(self: copy self)
@_transparent
public mutating func nextSpan(maximumCount: Int) -> Span<Element> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Element_> {
let c = Swift.min(maximumCount, _count)
defer {
_start &+= c
@@ -50,7 +48,7 @@ public struct SpanIterator<Element>: 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<Element>: BorrowingIteratorProtocol, ~Copyable, ~Esca
}
#endif
#endif
@@ -314,11 +314,11 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
internal mutating func _append<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<S: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
public mutating func append<S: BorrowingSequence_<Element> & ~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<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
copying items: S
) {
@@ -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<Element>
@@ -46,7 +46,7 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(copy self)
@_lifetime(self: copy self)
public mutating func nextSpan(maximumCount: Int) -> Span<Element> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Element> {
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
@@ -133,7 +133,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~Copyable & ~Escapable
>(
capacity: Int,
copying contents: borrowing S
@@ -189,7 +189,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
capacity: Int,
copying contents: borrowing S
@@ -211,7 +211,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & Collection<Element>
S: BorrowingSequence_<Element> & Collection<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -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
@@ -291,13 +291,13 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _prepend<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<S: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
public mutating func prepend<S: BorrowingSequence_<Element> & ~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<S: BorrowingSequence<Element> & Sequence<Element>>(
public mutating func prepend<S: BorrowingSequence_<Element> & Sequence<Element>>(
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<S: BorrowingSequence<Element> & Collection<Element>>(
public mutating func prepend<S: BorrowingSequence_<Element> & Collection<Element>>(
copying items: borrowing S
) {
self._prepend(copying: items, exactCount: items.count)
@@ -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
@@ -301,11 +301,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
internal mutating func _append<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<S: BorrowingSequence<Element> & ~Copyable & ~Escapable>(
public mutating func append<S: BorrowingSequence_<Element> & ~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<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
copying items: S
) {
@@ -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
@@ -155,7 +155,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -215,7 +215,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: BorrowingSequence<Element> & Collection<Element>
S: BorrowingSequence_<Element> & Collection<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -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
@@ -323,7 +323,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _prepend<
S: BorrowingSequence<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<Element> & ~Copyable & ~Escapable
S: BorrowingSequence_<Element> & ~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<Element> & Sequence<Element>
S: BorrowingSequence_<Element> & Sequence<Element>
>(
copying items: borrowing S
) {
@@ -502,7 +502,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func prepend<
S: BorrowingSequence<Element> & Collection<Element>
S: BorrowingSequence_<Element> & Collection<Element>
>(
copying items: borrowing S
) {
@@ -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
@@ -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)
@@ -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()
@@ -127,7 +127,7 @@ public func expectIterableContents<
@available(SwiftStdlib 6.4, *)
public func expectIterablePayloads<
Payload: Equatable,
E1: BorrowingSequence<LifetimeTrackedStruct<Payload>> & ~Copyable & ~Escapable,
E1: BorrowingSequence_<LifetimeTrackedStruct<Payload>> & ~Copyable & ~Escapable,
C2: Collection<Payload>,
>(
_ 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<LifetimeTracked<Payload>> & ~Copyable & ~Escapable,
E1: BorrowingSequence_<LifetimeTracked<Payload>> & ~Copyable & ~Escapable,
C2: Collection<Payload>,
>(
_ 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<Element> & ~Copyable & ~Escapable,
S2: BorrowingSequence<Element> & ~Copyable & ~Escapable,
S1: BorrowingSequence_<Element> & ~Copyable & ~Escapable,
S2: BorrowingSequence_<Element> & ~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<Element> & ~Copyable & ~Escapable,
S1: BorrowingSequence_<Element> & ~Copyable & ~Escapable,
C2: Collection<Element>,
>(
_ 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 {
@@ -22,14 +22,14 @@ import ContainersPreview
@available(SwiftStdlib 6.4, *)
@inlinable
public func checkIterable<
S: BorrowingSequence & ~Copyable & ~Escapable,
Expected: Sequence<S.Element>
S: BorrowingSequence_ & ~Copyable & ~Escapable,
Expected: Sequence<S.Element_>
>(
_ 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.Element>
S: BorrowingSequence_ & ~Copyable & ~Escapable,
Expected: Sequence<S.Element_>
>(
_ 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<Int>] = {
var r: [Range<Int>] = []
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,
@@ -76,7 +76,7 @@ package struct _StaccatoParameters {
}
@available(SwiftStdlib 5.0, *)
public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorProtocol, ~Escapable {
public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorProtocol_, ~Escapable {
internal let _contents: Span<Element>
internal let _params: _StaccatoParameters
internal var _offset: Int
@@ -89,7 +89,7 @@ public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorP
}
@_lifetime(copy self)
public mutating func nextSpan(maximumCount: Int) -> Span<Element> {
public mutating func nextSpan_(maximumCount: Int) -> Span<Element> {
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<Element> // FIXME rdar://150240032
extension StaccatoContainer: BorrowingSequence_ where Element: ~Copyable {
public typealias BorrowingIterator_ = _StaccatoBorrowingIterator<Element> // 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)
}
}