Use Iterable from the Standard Library, replacing the local definition

This commit is contained in:
Karoy Lorentey committed 2026-07-27 13:32:46 -07:00
1 parent 0afc8e0e16
commit 669eb09cea
68 files changed
+565 -921

No files matched your search

+1
View File
@@ -58,6 +58,7 @@ set(collections_swift_flags
"-enable-experimental-feature AddressableParameters"
"-enable-experimental-feature AddressableTypes"
"-enable-experimental-feature SuppressedAssociatedTypesWithDefaults"
"-enable-experimental-feature BorrowingSequence"
)
foreach(flag ${collections_swift_flags})
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:${flag}>")
+1
View File
@@ -116,6 +116,7 @@ let extraSettings: [SwiftSetting] = [
.enableExperimentalFeature("AddressableParameters"),
.enableExperimentalFeature("AddressableTypes"),
.enableExperimentalFeature("SuppressedAssociatedTypesWithDefaults"), // Requires Swift 6.4
.enableExperimentalFeature("BorrowingSequence"), // 6.4
// Note: if you touch these, please make sure to also update the similar lists in
// CMakeLists.txt and Xcode/Shared.xcconfig.
]
@@ -256,11 +256,11 @@ extension RigidArray {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _append<
Source: Iterable_ & ~Copyable & ~Escapable
Source: Iterable & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
let target = _freeSpace
_count += try newElements._copyContents(intoPrefixOf: target)
}
@@ -280,11 +280,11 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable_ & ~Copyable & ~Escapable
Source: Iterable & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try _append(copying: newElements)
}
#endif
@@ -324,11 +324,11 @@ extension RigidArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable_ & Sequence<Element>
Source: Iterable & Sequence<Element>
>(
copying newElements: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try _append(copying: newElements)
}
#endif
@@ -20,16 +20,13 @@ import ContainersPreview
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension RigidArray: Iterable_ where Element: ~Copyable {
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
extension RigidArray: Iterable where Element: ~Copyable {
public typealias BorrowingIterator = Span<Element>.BorrowingIterator
@_alwaysEmitIntoClient
@inline(__always)
public func makeBorrowingIterator_() -> BorrowingIterator_ {
let span = self.span
let it = span.makeBorrowingIterator_()
// FIXME: `it` is borrowing `span`, not self
return _overrideLifetime(it, borrowing: self)
public func makeBorrowingIterator() -> BorrowingIterator {
self.span._makeBorrowingIterator(from: 0, to: count)
}
}
#endif
@@ -41,17 +38,14 @@ extension RigidArray: Container where Element: ~Copyable {
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Index, to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
// FIXME: `makeBorrowingIterator` would be borrowing the temporary `span`, not self
self.span._makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
precondition(
iterator._span.isTriviallyIdentical(to: self.span),
"Invalid iterator instance")
return iterator._start
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
self.span.currentIndex(of: &iterator)
}
}
@@ -73,7 +67,7 @@ extension RigidArray: RangeReplaceableContainer where Element: ~Copyable {}
@available(SwiftStdlib 5.0, *)
extension RigidArray where Element: ~Copyable {
@inlinable
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
/// A Boolean value indicating whether this array contains no elements.
///
@@ -128,11 +128,11 @@ extension RigidArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable_ & ~Copyable & ~Escapable>(
public init<Source: Iterable & ~Copyable & ~Escapable>(
capacity: Int,
copying contents: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
self.init(capacity: capacity)
try self.append(copying: contents)
}
@@ -151,11 +151,11 @@ extension RigidArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable_ & Sequence<Element>>(
public init<Source: Iterable & Sequence<Element>>(
capacity: Int,
copying contents: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
self.init(capacity: capacity)
try self.append(copying: contents)
}
@@ -592,17 +592,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_(maxCount: target.freeCapacity)
let source = it.nextSpan(maxCount: 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")
}
}
@@ -43,14 +43,13 @@ extension RigidDictionary where Key: ~Copyable, Value: ~Copyable {
}
@available(SwiftStdlib 6.4, *)
extension RigidDictionary.Indices: Iterable_
extension RigidDictionary.Indices: Iterable
where Key: ~Copyable, Value: ~Copyable
{
public typealias Element = RigidDictionary.Index
public typealias Element_ = Element
@frozen
public struct BorrowingIterator_: ~Escapable {
public struct BorrowingIterator: ~Escapable {
public typealias Element = RigidDictionary.Index
@usableFromInline
@@ -70,24 +69,22 @@ where Key: ~Copyable, Value: ~Copyable
}
@inlinable
public var underestimatedCount_: Int { self._base.value.count }
public var underestimatedCount: Int { self._base.value.count }
@_lifetime(borrow self) // FIXME: Should be @_lifetime(copy self)
public func makeBorrowingIterator_() -> BorrowingIterator_ {
@_lifetime(borrow self)
public func makeBorrowingIterator() -> BorrowingIterator {
let bit = self._base.value.makeBucketIterator()
// FIXME: This override really should not be necessary. Check if the real `struct Borrow` fixes it.
let override = _overrideLifetime(bit, copying: self)
return BorrowingIterator_(_it: override)
return BorrowingIterator(_it: override)
}
}
@available(SwiftStdlib 6.4, *)
extension RigidDictionary.Indices.BorrowingIterator_: BorrowingIteratorProtocol_
extension RigidDictionary.Indices.BorrowingIterator: BorrowingIteratorProtocol
where Key: ~Copyable, Value: ~Copyable {
public typealias Element_ = Element
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) -> Span<Element> {
public mutating func nextSpan(maxCount: Int) -> Span<Element> {
guard _it.advanceToOccupied() else { return .init() }
_current[0] = Element(_bucket: _it.currentBucket)
_it.advanceToNextBit()
@@ -18,14 +18,12 @@ import ContainersPreview
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension RigidSet: Iterable_ where Element: ~Copyable {
public typealias Element_ = Element
extension RigidSet: Iterable where Element: ~Copyable {
@inlinable
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
@inlinable
public func _customContainsEquatableElement_(
public func _customContainsEquatableElement(
_ element: borrowing Element
) -> Bool? {
self.contains(element)
@@ -33,20 +31,18 @@ extension RigidSet: Iterable_ where Element: ~Copyable {
@inlinable
@_lifetime(borrow self)
public borrowing func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(_set: self)
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(_set: self)
}
@frozen
public struct BorrowingIterator_:
BorrowingIteratorProtocol_,
public struct BorrowingIterator:
BorrowingIteratorProtocol,
~Copyable,
~Escapable
{
public typealias Element_ = Element
@_alwaysEmitIntoClient
internal var _baseAddress: UnsafePointer<Element_>?
internal var _baseAddress: UnsafePointer<Element>?
@_alwaysEmitIntoClient
internal var _bucketIterator: _HTable.BucketIterator
@@ -54,7 +50,7 @@ extension RigidSet: Iterable_ where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(borrow _set)
internal init(
_set: borrowing RigidSet<Element_>
_set: borrowing RigidSet<Element>
) {
self._baseAddress = .init(_set._members)
self._bucketIterator = _set._table.makeBucketIterator()
@@ -62,7 +58,7 @@ extension RigidSet: Iterable_ where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(copy self)
internal func _span(over buckets: Range<_Bucket>) -> Span<Element_> {
internal func _span(over buckets: Range<_Bucket>) -> Span<Element> {
let items = UnsafeBufferPointer(
start: _baseAddress.unsafelyUnwrapped + buckets.lowerBound.offset,
count: buckets.upperBound.offset - buckets.lowerBound.offset)
@@ -71,7 +67,7 @@ extension RigidSet: Iterable_ where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) -> Span<Element_> {
public mutating func nextSpan(maxCount: Int = .max) -> Span<Element> {
precondition(maxCount > 0, "maxCount must be positive")
guard
let next = _bucketIterator.nextOccupiedRegion(maxCount: maxCount)
@@ -40,9 +40,9 @@ extension RigidSet where Element: ~Copyable {
guard left.count == right.count else { return false }
#if UnstableContainersPreview
var lit = left.makeBorrowingIterator_()
var lit = left.makeBorrowingIterator()
while true {
let l = lit.nextSpan_()
let l = lit.nextSpan(maxCount: .max)
if l.isEmpty { break }
var i = 0
while i < l.count {
@@ -37,9 +37,9 @@ extension RigidSet where Element: ~Copyable {
public func _rawHashValue(seed: Int) -> Int {
#if UnstableContainersPreview
var hash = 0
var it = self.makeBorrowingIterator_()
var it = self.makeBorrowingIterator()
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
var i = 0
while i < next.count {
hash ^= next[unchecked: i]._rawHashValue(seed: seed)
@@ -86,12 +86,12 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
capacity: Int,
copying contents: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(capacity: capacity)
try self._insert(copying: contents)
}
@@ -122,12 +122,12 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_ & Sequence<Element>
S: Iterable & Sequence<Element>
>(
capacity: Int,
copying contents: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(capacity: capacity)
try self._insert(copying: contents)
}
@@ -136,12 +136,12 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_ & Collection<Element>
S: Iterable & Collection<Element>
>(
capacity: Int? = nil,
copying contents: S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(capacity: capacity ?? contents.count)
try self._insert(copying: contents)
}
@@ -239,14 +239,14 @@ extension RigidSet /* where Element: Copyable */ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
package mutating func _insert<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
var it = items.makeBorrowingIterator_()
) throws(S.Failure)
where S.Element == Element {
var it = items.makeBorrowingIterator()
while true {
let span = try it.nextSpan_()
let span = try it.nextSpan()
guard !span.isEmpty else { break }
self.insert(copying: span)
}
@@ -258,11 +258,11 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try _insert(copying: items)
}
#endif
@@ -281,11 +281,11 @@ extension RigidSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: Iterable_ & Sequence<Element>
S: Iterable & Sequence<Element>
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try _insert(copying: items)
}
#endif
@@ -261,15 +261,15 @@ extension UniqueArray {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _append<
Source: Iterable_ & ~Copyable & ~Escapable
Source: Iterable & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
_ensureFreeCapacity(newElements.underestimatedCount_)
var it = newElements.makeBorrowingIterator_()
) throws(Source.Failure)
where Source.Element == Element {
_ensureFreeCapacity(newElements.underestimatedCount)
var it = newElements.makeBorrowingIterator()
while true {
let span = try it.nextSpan_()
let span = try it.nextSpan()
if span.isEmpty { break }
_ensureFreeCapacity(span.count)
_storage.append(copying: span)
@@ -296,11 +296,11 @@ extension UniqueArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable_ & ~Copyable & ~Escapable
Source: Iterable & ~Copyable & ~Escapable
>(
copying newElements: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try self._append(copying: newElements)
}
@@ -352,11 +352,11 @@ extension UniqueArray {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func append<
Source: Iterable_ & Sequence<Element>
Source: Iterable & Sequence<Element>
>(
copying newElements: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try self._append(copying: newElements)
}
#endif
@@ -20,16 +20,16 @@ import ContainersPreview
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension UniqueArray: Iterable_ where Element: ~Copyable {
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
extension UniqueArray: Iterable where Element: ~Copyable {
public typealias BorrowingIterator = Span<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
@@ -41,13 +41,13 @@ extension UniqueArray: Container where Element: ~Copyable {
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Index, to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
_storage.makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
_storage.currentIndex(of: iterator)
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
_storage.currentIndex(of: &iterator)
}
}
@@ -97,11 +97,11 @@ extension UniqueArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable_ & ~Copyable & ~Escapable>(
public init<Source: Iterable & ~Copyable & ~Escapable>(
capacity: Int? = nil,
copying contents: borrowing Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
self.init(minimumCapacity: capacity ?? 0)
try self.append(copying: contents)
}
@@ -135,11 +135,11 @@ extension UniqueArray /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<Source: Iterable_ & Sequence<Element>>(
public init<Source: Iterable & Sequence<Element>>(
capacity: Int? = nil,
copying contents: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
self.init(minimumCapacity: capacity ?? 0)
try self.append(copying: contents)
}
@@ -19,15 +19,14 @@ import ContainersPreview
#if compiler(>=6.4) && UnstableHashedContainers && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension UniqueSet: Iterable_ where Element: ~Copyable {
public typealias Element_ = Element
public typealias BorrowingIterator_ = RigidSet<Element>.BorrowingIterator_
extension UniqueSet: Iterable where Element: ~Copyable {
public typealias BorrowingIterator = RigidSet<Element>.BorrowingIterator
@inlinable
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
@inlinable
public func _customContainsEquatableElement_(
public func _customContainsEquatableElement(
_ element: borrowing Element
) -> Bool? {
self.contains(element)
@@ -35,8 +34,8 @@ extension UniqueSet: Iterable_ where Element: ~Copyable {
@inlinable
@_lifetime(borrow self)
public borrowing func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(_set: _storage)
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(_set: _storage)
}
}
#endif
@@ -77,12 +77,10 @@ extension UniqueSet where Element: Copyable {
#if UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public init<
S: Iterable_ & ~Copyable & ~Escapable
>(
public init<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init()
try self.insert(copying: items)
}
@@ -97,12 +95,10 @@ extension UniqueSet where Element: Copyable {
#if UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public init<
S: Iterable_ & Sequence<Element>
>(
public init<S: Iterable & Sequence<Element>>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init()
try self._insert(copying: items)
}
@@ -134,15 +134,15 @@ extension UniqueSet /* where Element: Copyable */ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
package mutating func _insert<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
_ensureFreeCapacity(items.underestimatedCount_)
var it = items.makeBorrowingIterator_()
) throws(S.Failure)
where S.Element == Element {
_ensureFreeCapacity(items.underestimatedCount)
var it = items.makeBorrowingIterator()
while true {
let span = try it.nextSpan_()
let span = try it.nextSpan()
guard !span.isEmpty else { break }
self.insert(copying: span)
}
@@ -154,10 +154,10 @@ extension UniqueSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_) where S.Element_ == Element {
) throws(S.Failure) where S.Element == Element {
try _insert(copying: items)
}
#endif
@@ -177,11 +177,11 @@ extension UniqueSet /* where Element: Copyable */ {
@_alwaysEmitIntoClient
@inline(__always)
public mutating func insert<
S: Iterable_ & Sequence<Element>
S: Iterable & Sequence<Element>
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try _insert(copying: items)
}
#endif
-5
View File
@@ -27,16 +27,12 @@ endif()
target_sources(${module_name} PRIVATE
"Conformances/Array+Iterable.swift"
"Conformances/ClosedRange+Iterable.swift"
"Conformances/InlineArray+Iterable.swift"
"Conformances/InputSpan+Container.swift"
"Conformances/InputSpan+Iterable.swift"
"Conformances/MutableSpan+Container.swift"
"Conformances/MutableSpan+Iterable.swift"
"Conformances/OutputSpan+Container.swift"
"Conformances/OutputSpan+Iterable.swift"
"Conformances/Range+Iterable.swift"
"Conformances/Span+Container.swift"
"Conformances/Span+Iterable.swift"
"Protocols/Container/BidirectionalContainer.swift"
"Protocols/Container/Container.swift"
"Protocols/Container/Container+Filter.swift"
@@ -57,7 +53,6 @@ target_sources(${module_name} PRIVATE
"Protocols/BorrowingIteratorProtocol+MapError.swift"
"Protocols/BorrowingIteratorProtocol+Reduce.swift"
"Protocols/BorrowingIteratorProtocol+SpanwiseZip.swift"
"Protocols/Iterable.swift"
"Protocols/Iterable+Algorithms.swift"
"Protocols/Iterable+Utilities.swift"
"Protocols/CountedProducer.swift"
@@ -14,17 +14,16 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Array: Iterable_ {
public typealias Element_ = Element
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
extension Array: @retroactive Iterable {
public typealias BorrowingIterator = Span<Element>.BorrowingIterator
@inlinable
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self.span)
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self.span)
}
}
@@ -14,13 +14,13 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.2, *)
extension ClosedRange: Iterable_
extension ClosedRange: @retroactive Iterable
where Bound: Strideable, Bound.Stride: SignedInteger
{
public typealias Element_ = Bound
public typealias Element = Bound
@frozen
public struct BorrowingIterator_: BorrowingIteratorProtocol_, ~Copyable {
public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable {
@usableFromInline
internal var _current: InlineArray<1, Bound>
@@ -38,7 +38,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger
}
@inlinable
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) -> Span<Bound> {
public mutating func nextSpan(maxCount: Int) -> Span<Bound> {
if _progress {
_current[0] = _current[0].advanced(by: 1)
}
@@ -52,7 +52,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger
}
@inlinable
public var underestimatedCount_: Int {
public var underestimatedCount: Int {
guard let distance = Int(exactly: lowerBound.distance(to: upperBound))
else { return 0 }
let advanced = distance.addingReportingOverflow(1)
@@ -61,8 +61,8 @@ where Bound: Strideable, Bound.Stride: SignedInteger
}
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self)
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self)
}
}
@@ -1,31 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension InlineArray: Iterable_ where Element: ~Copyable {
public typealias Element_ = Element
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
@inlinable
public var underestimatedCount_: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self.span)
}
}
#endif
@@ -25,7 +25,7 @@ where Element: ~Copyable
public func makeBorrowingIterator(
from start: Index,
to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
let span = self.span
let it = span.makeBorrowingIterator(from: start, to: end)
// FIXME: `it` is borrowing `span`, not self
@@ -33,8 +33,8 @@ where Element: ~Copyable
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
self.span.currentIndex(of: iterator)
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
self.span.currentIndex(of: &iterator)
}
}
#endif
@@ -14,16 +14,16 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension InputSpan: Iterable_ where Element: ~Copyable {
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
extension InputSpan: Iterable where Element: ~Copyable {
public typealias BorrowingIterator = Span<Element>.BorrowingIterator
@inlinable
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self.span)
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self.span)
}
}
@@ -22,19 +22,16 @@ extension MutableSpan: RandomAccessContainer where Element: ~Copyable {
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Int, to end: Int
) -> BorrowingIterator_ {
) -> BorrowingIterator {
// FIXME: `makeBorrowingIterator` would be borrowing the temporary `span`, not self
self.span._makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(
of iterator: borrowing BorrowingIterator_
of iterator: inout BorrowingIterator
) -> Int {
precondition(
self.span.isTriviallyIdentical(to: iterator._span),
"Invalid iterator")
return iterator._start
self.span.currentIndex(of: &iterator)
}
}
#endif
@@ -1,35 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension MutableSpan: Iterable_ where Element: ~Copyable {
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
public typealias Element_ = Element
@inlinable
public var underestimatedCount_: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
// 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
// Two different typealiases with the same name wreaks havoc with inference?
BorrowingIterator_(self.span)
}
}
#endif
@@ -18,20 +18,20 @@ import InternalCollectionsUtilities
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension OutputSpan: RandomAccessContainer, MutableContainer
where Element: ~Copyable
/*where Element: ~Copyable*/ // FIXME: rdar://183153655 OutputSpan's Iterable conformance requires Element to be Copyable
{
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Index, to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
// FIXME: `makeBorrowingIterator` would be borrowing the temporary `span`, not self
self.span._makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
self.span.currentIndex(of: iterator)
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
self.span.currentIndex(of: &iterator)
}
@_alwaysEmitIntoClient
@@ -1,31 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension OutputSpan: Iterable_ where Element: ~Copyable {
public typealias Element_ = Element
public typealias BorrowingIterator_ = Span<Element>.BorrowingIterator_
@inlinable
public var underestimatedCount_: Int { count }
@_lifetime(borrow self)
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self.span)
}
}
#endif
@@ -14,13 +14,13 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Range: Iterable_
extension Range: @retroactive Iterable
where Bound: Strideable, Bound.Stride: SignedInteger
{
public typealias Element_ = Bound
public typealias Element = Bound
@frozen
public struct BorrowingIterator_: BorrowingIteratorProtocol_, ~Copyable {
public struct BorrowingIterator: BorrowingIteratorProtocol, ~Copyable {
@usableFromInline
internal var _current: InlineArray<1, Bound>
@@ -38,7 +38,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger
}
@inlinable
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) -> Span<Bound> {
public mutating func nextSpan(maxCount: Int) -> Span<Bound> {
if _progress {
_current[0] = _current[0].advanced(by: 1)
}
@@ -52,7 +52,7 @@ where Bound: Strideable, Bound.Stride: SignedInteger
}
@inlinable
public var underestimatedCount_: Int {
public var underestimatedCount: Int {
guard let count = Int(exactly: lowerBound.distance(to: upperBound)) else {
return 0
}
@@ -60,8 +60,8 @@ where Bound: Strideable, Bound.Stride: SignedInteger
}
@inlinable
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self)
public func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(self)
}
}
@@ -11,30 +11,66 @@
//
//===----------------------------------------------------------------------===//
@_frozen
@usableFromInline
package struct _ShamSpanIterator {
// FIXME: Remove this when `Span.BorrowingIterator` becomes actually usable.
@_alwaysEmitIntoClient
internal var _basePointer: UnsafeRawPointer?
@_alwaysEmitIntoClient
internal var _baseCount: Int
@_alwaysEmitIntoClient
internal var _start: Int
@_alwaysEmitIntoClient
internal var _count: Int
}
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Span: RandomAccessContainer where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(copy self)
package func _makeBorrowingIterator(from start: Int, to end: Int) -> BorrowingIterator_ {
package func _makeBorrowingIterator(from start: Int, to end: Int) -> BorrowingIterator {
// Note: This is declared `copy self` so that types can forward to it without having to override lifetimes.
// FIXME: SpanIterator needs to have a public "slicing" initializer
BorrowingIterator_(self, from: start, to: end)
#if false // FIXME: Span's iterator needs to provide a public "slicing" initializer
return BorrowingIterator(self, from: start, to: end)
#else
var it = BorrowingIterator(self.extracting(first: end))
let c = it.skip(by: start)
precondition(c == start)
return it
#endif
}
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public func makeBorrowingIterator(from start: Int, to end: Int) -> BorrowingIterator_ {
public func makeBorrowingIterator(from start: Int, to end: Int) -> BorrowingIterator {
_makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Int {
// FIXME: SpanIterator needs to have public `base` and `position` properties
public func currentIndex(of iterator: inout BorrowingIterator) -> Int {
#if false // FIXME: SpanIterator needs to provide public `base` and `position` properties
precondition(
self.isTriviallyIdentical(to: iterator._span),
"Invalid iterator")
"Iterator does not belong to this container")
return iterator._start
#else
precondition(MemoryLayout<BorrowingIterator>.stride == MemoryLayout<_ShamSpanIterator>.stride)
return self.withUnsafeBufferPointer { ourBuffer in
Swift.withUnsafeBytes(of: &iterator) { buffer in
buffer.withMemoryRebound(to: _ShamSpanIterator.self) { shamBuffer in
precondition(
shamBuffer[0]._basePointer == UnsafeRawPointer(ourBuffer.baseAddress) && shamBuffer[0]._baseCount <= ourBuffer.count,
"Iterator does not belong to this container")
return shamBuffer[0]._start
}
}
}
#endif
}
}
#endif
@@ -1,89 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Span: Iterable_ where Element: ~Copyable {
public typealias Element_ = Element
@inlinable
public var underestimatedCount_: Int { count }
@inlinable
@_lifetime(borrow self)
public func makeBorrowingIterator_() -> BorrowingIterator_ {
BorrowingIterator_(self)
}
}
@available(SwiftStdlib 5.0, *)
extension Span where Element: ~Copyable {
/// A borrowing iterator that provides access to the elements of a single
/// span through a `BorrowingIteratorProtocol` interface.
@available(SwiftStdlib 6.4, *)
public struct BorrowingIterator_:
BorrowingIteratorProtocol_, ~Copyable, ~Escapable
{
public typealias Element_ = Element
@usableFromInline
package var _span: Span<Element_>
@usableFromInline
package var _start: Int
@usableFromInline
package var _count: Int
@_lifetime(copy elements)
public init(_ elements: Span<Element_>) {
_span = elements
_start = 0
_count = elements.count
}
@_lifetime(copy elements)
public init(_ elements: Span<Element_>, from start: Int, to end: Int) {
precondition(start >= 0 && start <= elements.count, "Index out of bounds")
precondition(end >= 0 && end <= elements.count, "Index out of bounds")
precondition(start <= end, "start index must be less than or equal to end index")
_span = elements
_start = start
_count = end &- start
}
@_alwaysEmitIntoClient
@_lifetime(&self)
@_lifetime(self: copy self)
@_transparent
public mutating func nextSpan_(maxCount: Int) -> Span<Element_> {
let c = Swift.min(maxCount, _count)
defer {
_start &+= c
_count &-= c
}
return _span.extracting(droppingFirst: _start).extracting(first: c)
}
@_alwaysEmitIntoClient
@_lifetime(self: copy self)
public mutating func skip_(by offset: Int) -> Int {
let c = Swift.min(offset, _count)
defer {
_start &+= c
_count &-= c
}
return c
}
}
}
#endif
@@ -13,11 +13,11 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
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_> {
public consuming func copy() -> BorrowingMapProducer<Self, Element> {
// FIXME: We could also just define a direct implementation that avoids the closure.
self.map { $0 }
}
@@ -18,30 +18,30 @@ import InternalCollectionsUtilities
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Iterable_
extension Iterable
where
Self: ~Copyable & ~Escapable, Element_: Equatable,
Element_: ~Copyable
Self: ~Copyable & ~Escapable, Element: Equatable,
Element: ~Copyable
{
@inlinable
package func _elementsEqual<
Other: Iterable_<Element_, Failure_> & ~Copyable & ~Escapable
Other: Iterable<Element, Failure> & ~Copyable & ~Escapable
>(
_ other: borrowing Other,
) throws(Failure_) -> Bool
where Other.Element_: ~Copyable
) throws(Failure) -> Bool
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)
}
}
@available(SwiftStdlib 6.4, *)
extension Iterable_
extension Iterable
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
@@ -66,32 +66,32 @@ where
/// - Complexity: O(*m*), where *m* is the count of the longer of the input sequences.
@inlinable
package func _elementsEqual<
Other: Iterable_ & ~Copyable & ~Escapable
Other: Iterable & ~Copyable & ~Escapable
>(
_ other: borrowing Other,
by areEquivalent: (borrowing Element_, borrowing Other.Element_) throws(Failure_) -> Bool
) throws(Failure_) -> Bool
where Other.Element_: ~Copyable, Other.Failure_ == Failure_
by areEquivalent: (borrowing Element, borrowing Other.Element) throws(Failure) -> Bool
) throws(Failure) -> Bool
where Other.Element: ~Copyable, Other.Failure == Failure
{
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_, Failure_> & ~Copyable & ~Escapable
Other: BorrowingIteratorProtocol<Element, Failure> & ~Copyable & ~Escapable
>(
_ other: consuming Other,
) throws(Failure_) -> Bool
where Other.Element_: ~Copyable
) throws(Failure) -> Bool
where Other.Element: ~Copyable
{
var result = true
try _spanwiseZip(state: &result, with: other) { state, a, b in
@@ -113,11 +113,11 @@ where
@inlinable
package consuming func _directElementsEqual<
Other: BorrowingIteratorProtocol_<Element_, Failure_> & ~Copyable & ~Escapable
Other: BorrowingIteratorProtocol<Element, Failure> & ~Copyable & ~Escapable
>(
_ other: consuming Other,
) throws(Failure_) -> Bool
where Other.Element_: ~Copyable
) throws(Failure) -> Bool
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
@@ -125,13 +125,13 @@ where
// (It lets the two iterators run at their native speeds, with no artificial
// maxCounts.)
while true {
let a = try self.nextSpan_()
let a = try self.nextSpan()
var i = 0
if a.isEmpty {
return try other.nextSpan_().isEmpty
return try other.nextSpan().isEmpty
}
while i < a.count {
let b = try other.nextSpan_(maxCount: a.count - i)
let b = try other.nextSpan(maxCount: a.count - i)
if b.isEmpty {
return false
}
@@ -174,22 +174,22 @@ where
}
@available(SwiftStdlib 6.4, *)
extension BorrowingIteratorProtocol_
extension BorrowingIteratorProtocol
where
Self: ~Copyable & ~Escapable,
Element_: ~Copyable
Element: ~Copyable
{
@inlinable
package consuming func elementsEqual<
Other: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable
Other: BorrowingIteratorProtocol & ~Copyable & ~Escapable
>(
_ other: consuming Other,
by areEquivalent: (borrowing Element_, borrowing Other.Element_) throws(Failure_) -> Bool
) throws(Failure_) -> Bool
where Other.Element_: ~Copyable, Other.Failure_ == Failure_
by areEquivalent: (borrowing Element, borrowing Other.Element) throws(Failure) -> Bool
) throws(Failure) -> Bool
where Other.Element: ~Copyable, Other.Failure == Failure
{
var result = true
try _spanwiseZip(state: &result, with: other) { state, a, b throws(Failure_) in
try _spanwiseZip(state: &result, with: other) { state, a, b throws(Failure) in
assert(a.count == b.count || a.isEmpty || b.isEmpty)
if a.isEmpty || b.isEmpty {
state = false
@@ -13,31 +13,31 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
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)
}
}
@available(SwiftStdlib 5.0, *)
@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_
public typealias Failure = Base.Failure_
where Base.Element: ~Copyable {
public typealias Element = Base.Element
public typealias Failure = Base.Failure
@_alwaysEmitIntoClient
public let _isIncluded: (borrowing Element_) throws(Failure) -> Bool
public let _isIncluded: (borrowing Element) throws(Failure) -> Bool
@_alwaysEmitIntoClient
public var _base: Base
@@ -46,7 +46,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,14 +55,14 @@ where Base.Element_: ~Copyable {
// FIXME: Sendable
@available(SwiftStdlib 5.0, *)
extension BorrowingFilter: BorrowingIteratorProtocol_
where Base: ~Copyable & ~Escapable, Base.Element_: ~Copyable {
@available(SwiftStdlib 6.4, *)
extension BorrowingFilter: BorrowingIteratorProtocol
where Base: ~Copyable & ~Escapable, Base.Element: ~Copyable {
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) throws(Failure) -> Span<Element_> {
public mutating func nextSpan(maxCount: Int) throws(Failure) -> Span<Element> {
// FIXME: This is quite inefficient compared to Container's filter
while true {
let span = try _base.nextSpan_(maxCount: 1)
let span = try _base.nextSpan(maxCount: 1)
if span.isEmpty { return span }
precondition(span.count == 1, "Invalid BorrowingIterator")
if try _isIncluded(span[unchecked: 0]) { return span }
@@ -13,20 +13,20 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
extension BorrowingIteratorProtocol
where
Self: ~Copyable & ~Escapable,
Element_: ~Copyable
Element: ~Copyable
{
@inlinable
@_lifetime(copy self)
public consuming func map<T: ~Copyable>(
_ transform: @escaping (borrowing Element_) -> T
_ transform: @escaping (borrowing Element) -> T
) -> BorrowingMapProducer<Self, T> {
BorrowingMapProducer(
_base: self,
transform: { v throws(Failure_) in
transform: { v throws(Failure) in
// FIXME: Conversion from non-throwing to throwing closure should be implicit
transform(v)
})
@@ -35,7 +35,7 @@ where
@inlinable
@_lifetime(copy self)
public consuming func map2<T: ~Copyable>( // FIXME: We can't overload on the type of error thrown.
_ transform: @escaping (borrowing Element_) throws(Failure_) -> T
_ transform: @escaping (borrowing Element) throws(Failure) -> T
) -> BorrowingMapProducer<Self, T> {
BorrowingMapProducer(_base: self, transform: transform)
}
@@ -43,20 +43,20 @@ where
@inlinable
@_lifetime(copy self)
public consuming func map2<T: ~Copyable, E: Error>( // FIXME: We can't overload on the type of error thrown.
_ transform: @escaping (borrowing Element_) throws(E) -> T
_ transform: @escaping (borrowing Element) throws(E) -> T
) -> BorrowingMapProducer<ErrorMappedIterator<Self, E>, T>
where Failure_ == Never {
where Failure == Never {
BorrowingMapProducer(_base: self.mapError(), transform: transform)
}
}
@available(SwiftStdlib 5.0, *)
@available(SwiftStdlib 6.4, *)
public struct BorrowingMapProducer<
Base: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable,
Base: BorrowingIteratorProtocol & ~Copyable & ~Escapable,
Element: ~Copyable,
>: ~Copyable, ~Escapable {
@_alwaysEmitIntoClient
public let _transform: (borrowing Base.Element_) throws(Failure) -> Element
public let _transform: (borrowing Base.Element) throws(Failure) -> Element
@_alwaysEmitIntoClient
public var _it: Base
@@ -65,7 +65,7 @@ public struct BorrowingMapProducer<
@_lifetime(copy _base)
internal init(
_base: consuming Base,
transform: @escaping (borrowing Base.Element_) throws(Failure) -> Element
transform: @escaping (borrowing Base.Element) throws(Failure) -> Element
) {
self._transform = transform
self._it = _base
@@ -74,13 +74,13 @@ public struct BorrowingMapProducer<
// FIXME: Sendable
@available(SwiftStdlib 5.0, *)
@available(SwiftStdlib 6.4, *)
extension BorrowingMapProducer: Producer
where
Base: ~Copyable & ~Escapable,
Element: ~Copyable
{
public typealias Failure = Base.Failure_
public typealias Failure = Base.Failure
@inlinable
public var underestimatedCount: Int {
@@ -90,7 +90,7 @@ where
@inlinable
@_lifetime(self: copy self)
public mutating func next() throws(Failure) -> Element? {
let span = try _it.nextSpan_(maxCount: 1)
let span = try _it.nextSpan(maxCount: 1)
guard !span.isEmpty else { return nil }
return try _transform(span[unchecked: 0])
}
@@ -104,7 +104,7 @@ where
) throws(Failure) -> Bool {
var success = false
while !target.isFull {
let span = try _it.nextSpan_(maxCount: target.freeCapacity)
let span = try _it.nextSpan(maxCount: target.freeCapacity)
guard !span.isEmpty else { break }
success = true
var i = 0
@@ -121,18 +121,18 @@ where
public mutating func skip(by n: inout Int) throws(Failure) {
precondition(n > 0, "Can't skip a negative number of elements")
if Failure.self == Never.self {
n -= try! _it.skip_(by: n)
n -= try! _it.skip(by: n)
return
}
#if false
// FIXME: Iterator's ill-conceived skip(by:) fails to report the position that triggers errors
try _it.skip_(by: &n)
try _it.skip(by: &n)
#else
// We have no choice other than skipping items one by one, or allowing
// the base to materialize every element. The latter performs better in
// the common case of containers, so let's do that.
while n > 0 {
let span = try _it.nextSpan_(maxCount: n)
let span = try _it.nextSpan(maxCount: n)
n -= span.count
}
#endif
@@ -13,16 +13,16 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
extension BorrowingIteratorProtocol
where
Self: ~Copyable & ~Escapable,
Element_: ~Copyable
Element: ~Copyable
{
@inlinable
@_lifetime(copy self)
public consuming func mapError<NewFailure: Error>(
_ transform: @escaping (Failure_) -> NewFailure
_ transform: @escaping (Failure) -> NewFailure
) -> ErrorMappedIterator<Self, NewFailure> {
ErrorMappedIterator(base: self, transform: transform)
}
@@ -32,21 +32,22 @@ where
public consuming func mapError<NewFailure: Error>(
to error: NewFailure.Type = NewFailure.self
) -> ErrorMappedIterator<Self, NewFailure>
where Failure_ == Never {
where Failure == Never {
ErrorMappedIterator(base: self, transform: { _ in
fatalError("Unreachable")
})
}
}
@available(SwiftStdlib 6.4, *)
@frozen
public struct ErrorMappedIterator<
Base: BorrowingIteratorProtocol_ & ~Copyable & ~Escapable,
Base: BorrowingIteratorProtocol & ~Copyable & ~Escapable,
Failure: Error
>: ~Copyable, ~Escapable
where Base.Element_: ~Copyable {
where Base.Element: ~Copyable {
@usableFromInline
internal let _transform: (Base.Failure_) -> Failure
internal let _transform: (Base.Failure) -> Failure
@usableFromInline
internal var _base: Base
@@ -55,27 +56,28 @@ where Base.Element_: ~Copyable {
@_lifetime(copy base)
public init(
base: consuming Base,
transform: @escaping (Base.Failure_) -> Failure
transform: @escaping (Base.Failure) -> Failure
) {
self._base = base
self._transform = transform
}
}
extension ErrorMappedIterator: BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
extension ErrorMappedIterator: BorrowingIteratorProtocol
where
Base: ~Copyable & ~Escapable,
Base.Element_: ~Copyable
Base.Element: ~Copyable
{
public typealias Element_ = Base.Element_
public typealias Failure_ = Failure
public typealias Element = Base.Element
public typealias Failure = Failure
@inlinable
@_lifetime(&self)
@_lifetime(self: copy self)
public mutating func nextSpan_(maxCount: Int) throws(Failure_) -> Span<Element_> {
public mutating func nextSpan(maxCount: Int) throws(Failure) -> Span<Element> {
do {
return try _base.nextSpan_(maxCount: maxCount)
return try _base.nextSpan(maxCount: maxCount)
} catch {
throw _transform(error)
}
@@ -83,9 +85,9 @@ where
@inlinable
@_lifetime(self: copy self)
public mutating func skip_(by maximumOffset: Int) throws(Failure_) -> Int {
public mutating func skip(by maximumOffset: Int) throws(Failure) -> Int {
do {
return try _base.skip_(by: maximumOffset)
return try _base.skip(by: maximumOffset)
} catch {
throw _transform(error)
}
@@ -13,20 +13,20 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
extension BorrowingIteratorProtocol
where
Self: ~Copyable & ~Escapable,
Element_: ~Copyable
Element: ~Copyable
{
@inlinable
public consuming func reduce<Result: ~Copyable>(
_ initialResult: consuming Result,
_ nextPartialResult: (consuming Result, borrowing Element_) throws(Failure_) -> Result
) throws(Failure_) -> Result {
_ nextPartialResult: (consuming Result, borrowing Element) throws(Failure) -> Result
) throws(Failure) -> Result {
var result = initialResult
while true {
let span = try self.nextSpan_()
let span = try 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>(
into initialResult: consuming Result,
_ updateAccumulatingResult: (inout Result, borrowing Element_) throws(Failure_) -> Void
) throws(Failure_) -> Result {
_ updateAccumulatingResult: (inout Result, borrowing Element) throws(Failure) -> Void
) throws(Failure) -> Result {
var result = initialResult
while true {
let span = try self.nextSpan_()
let span = try self.nextSpan()
guard !span.isEmpty else { break }
var i = 0
while i < span.count {
@@ -17,22 +17,22 @@ import InternalCollectionsUtilities
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
@available(SwiftStdlib 6.4, *)
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
>(
state: inout State,
with other: consuming Other,
by process: (inout State, Span<Element_>, Span<Other.Element_>) throws(Failure_) -> Bool
) throws(Failure_)
where Other.Element_: ~Copyable, Other.Failure_ == Failure_
by process: (inout State, Span<Element>, Span<Other.Element>) throws(Failure) -> Bool
) throws(Failure)
where Other.Element: ~Copyable, Other.Failure == Failure
{
#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
// maxCounts.)
loop:
while true {
var a = try self.nextSpan_()
var a = try self.nextSpan()
if a.isEmpty {
while true {
let b = try other.nextSpan_()
let b = try other.nextSpan()
guard !b.isEmpty else { break }
guard try process(&state, a, b) else { break }
}
return
}
repeat {
let b = try other.nextSpan_(maxCount: a.count)
let b = try other.nextSpan(maxCount: a.count)
if b.isEmpty {
guard try process(&state, a, b) else { return }
} else {
@@ -17,126 +17,32 @@
import InternalCollectionsUtilities
#endif
@available(SwiftStdlib 5.0, *)
public protocol BorrowingIteratorProtocol_<Element_, Failure_>: ~Copyable, ~Escapable {
associatedtype Element_: ~Copyable
associatedtype Failure_: Error = Never
/// Advance the iterator, returning an ephemeral span over the elements
/// that are ready to be visited.
///
/// If the underlying sequence is a container type, then the returned span
/// typically directly addresses one of its storage buffers. On the other
/// hand, if the underlying sequence materializes its elements on demand,
/// then the returned span addresses some temporary buffer associated with
/// the iterator itself. Consequently, the returned span is tied to this
/// particular invocation of `nextSpan`, and it cannot survive until the next
/// invocation of it.
///
/// If the iterator has not yet reached the end of the underlying sequence,
/// then this method returns a non-empty span of at most `maxCount`
/// elements, and updates the iterator's current position to the element
/// following the last item in the returned span (or the end, if there is
/// none). The `maxCount` argument allows callers to avoid getting more
/// items that they are able to process in one go, simplifying usage, and
/// avoiding materializing more elements than needed.
///
/// If the iterator's current position is at the end of the container, then
/// this method returns an empty span without updating the position.
///
/// This method can be used to efficiently process the items of a container
/// in bulk, by directly iterating over its piecewise contiguous pieces of
/// storage:
///
/// var it = items.makeBorrowingIterator()
/// while true {
/// let span = it.nextSpan(after: &index)
/// if span.isEmpty { break }
/// // Process items in `span`
/// }
///
/// Note: The spans returned by this method are not guaranteed to be disjunct.
/// Iterators that materialize elements on demand typically reuse the same
/// buffer over and over again; and even some proper containers may link to a
/// single storage chunk (or parts of a storage chunk) multiple times, for
/// example to repeat their contents.
///
/// Note: Repeatedly iterating over the same container is expected to return
/// the same items (collected in similarly sized span instances), but the
/// returned spans are not guaranteed to be identical. For example, this is
/// the case with containers that store some of their contents within their
/// direct representation. Such containers may not always have a unique
/// address in memory, and so the locations of the spans exposed by this
/// method may vary between different borrows of the same container.)
@_lifetime(&self)
@_lifetime(self: copy self)
mutating func nextSpan_(maxCount: Int) throws(Failure_) -> Span<Element_>
/// Advance the position of this iterator by the specified offset, or until
/// the end of the underlying sequence.
///
/// Returns the number of items that were skipped. If this is less than
/// `maximumOffset`, then the sequence did not have enough elements left to
/// skip the requested number of items. In this case, the iterator's current
/// position is set to the end of the sequence.
///
/// `maximumOffset` must be nonnegative.
@_lifetime(self: copy self)
mutating func skip_(by maximumOffset: Int) throws(Failure_) -> Int
}
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
where Self: ~Copyable & ~Escapable, Element_: ~Copyable {
@_lifetime(&self)
@_lifetime(self: copy self)
@_transparent
public mutating func nextSpan_() throws(Failure_) -> Span<Element_> {
try nextSpan_(maxCount: Int.max)
}
}
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
where Self: ~Copyable & ~Escapable, Element_: ~Copyable {
@_lifetime(self: copy self)
@inlinable
public mutating func skip_(by maxDistance: Int) throws(Failure_) -> Int {
var remainder = maxDistance
while remainder > 0 {
let span = try nextSpan_(maxCount: remainder)
if span.isEmpty { break }
remainder &-= span.count
}
return maxDistance &- remainder
}
}
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_ where Self: ~Copyable & ~Escapable {
@available(SwiftStdlib 6.4, *)
extension BorrowingIteratorProtocol
where Self: ~Copyable & ~Escapable, Element: ~Copyable {
@available(SwiftStdlib 6.4, *)
@_unsafeNonescapableResult // FIXME: Eep; _overrideLifetime(_:mutating:) doesn't work
@_lifetime(&self)
@_lifetime(self: copy self)
public mutating func next() throws(Failure_) -> Ref<Element_>? {
let span = try nextSpan_(maxCount: 1)
public mutating func next() throws(Failure) -> Ref<Element>? {
let span = try nextSpan(maxCount: 1)
guard !span.isEmpty else { return nil }
return Ref(span[unchecked: 0])
}
}
@available(SwiftStdlib 5.0, *)
extension BorrowingIteratorProtocol_
where Self: ~Copyable & ~Escapable, Element_: Copyable
@available(SwiftStdlib 6.4, *)
extension BorrowingIteratorProtocol
where Self: ~Copyable & ~Escapable, Element: Copyable
{
@_lifetime(self: copy self)
@inlinable
@_transparent
package mutating func _copyContents_(into target: inout OutputSpan<Element_>) throws(Failure_) {
try target.withUnsafeMutableBufferPointer { (dst, dstCount) throws(Failure_) -> Void in
package mutating func _copyContents(into target: inout OutputSpan<Element>) throws(Failure) {
try target.withUnsafeMutableBufferPointer { (dst, dstCount) throws(Failure) -> Void in
var tail = dst._extracting(droppingFirst: dstCount)
while !tail.isEmpty {
let src = try nextSpan_(maxCount: tail.count)
let src = try nextSpan(maxCount: tail.count)
if src.isEmpty { break }
tail._initializeAndDropPrefix(copying: src)
dstCount += src.count
@@ -24,7 +24,7 @@ extension Container where Self: ~Copyable /*& ~Escapable*/, Element: ~Copyable {
public func _filter(
_ isIncluded: @escaping (borrowing Element) -> Bool
) -> ContainerFilter<Self> {
ContainerFilter(_base: self, isIncluded: isIncluded)
ContainerFilter<Self>(_base: self, isIncluded: isIncluded)
}
}
@@ -35,7 +35,7 @@ extension ContainerIterator where Base.Element: ~Copyable {
public func filter(
_ isIncluded: @escaping (borrowing Element) -> Bool
) -> ContainerFilter<Base> {
ContainerFilter(_base: _base, index: _position, isIncluded: isIncluded)
ContainerFilter<Base>(_base: _base, index: _position, isIncluded: isIncluded)
}
}
@@ -88,11 +88,9 @@ where Base.Element: ~Copyable
// FIXME: Sendable
@available(SwiftStdlib 6.4, *)
extension ContainerFilter: BorrowingIteratorProtocol_ where Element: ~Copyable {
public typealias Element_ = Base.Element
@_lifetime(&self) // FIXME: This should be `@_lifetime(copy self)`
public mutating func nextSpan_(maxCount: Int) -> Span<Element> {
extension ContainerFilter: BorrowingIteratorProtocol where Element: ~Copyable {
@_lifetime(&self)
public mutating func nextSpan(maxCount: Int) -> Span<Element> {
precondition(maxCount > 0)
while true {
// Drop filtered out items from prefix of _remainder
@@ -19,8 +19,8 @@
/// nondestructively, and efficiently accessed.
@available(SwiftStdlib 6.4, *)
public protocol Container<Element>:
Iterable_, ~Copyable, ~Escapable
where Element: ~Copyable, Element == Element_, Failure_ == Never
Iterable, ~Copyable, ~Escapable
where Element: ~Copyable, Failure == Never
{
override associatedtype Element: ~Copyable
@@ -45,11 +45,12 @@ public protocol Container<Element>:
/// - Complexity: Recommended to be O(1); conforming types must clearly
/// document deviations from this expectation.
@_lifetime(borrow self)
func makeBorrowingIterator(from start: Index, to end: Index) -> BorrowingIterator_
func makeBorrowingIterator(from start: Index, to end: Index) -> BorrowingIterator
/// - Complexity: Recommended to be O(1); conforming types must clearly
/// document deviations from this expectation.
func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index
func currentIndex(of iterator: inout BorrowingIterator) -> Index
// FIXME: `inout` needs to be `borrowing`, but Span's needlessly limited iterator makes that unworkable.
/// Complexity: O(1)
var isEmpty: Bool { get }
@@ -279,19 +280,19 @@ public protocol Container<Element>:
extension Container where Self: ~Copyable & ~Escapable, Element: ~Copyable {
@_alwaysEmitIntoClient
@_transparent
public var underestimatedCount_: Int { count }
public var underestimatedCount: Int { count }
@_alwaysEmitIntoClient
@_transparent
@_lifetime(borrow self)
public func makeBorrowingIterator_() -> BorrowingIterator_ {
public func makeBorrowingIterator() -> BorrowingIterator {
self.makeBorrowingIterator(from: self.startIndex, to: self.endIndex)
}
@_alwaysEmitIntoClient
@_transparent
@_lifetime(borrow self)
public func makeBorrowingIterator_(from start: Index) -> BorrowingIterator_ {
public func makeBorrowingIterator(from start: Index) -> BorrowingIterator {
self.makeBorrowingIterator(from: start, to: self.endIndex)
}
}
@@ -18,11 +18,11 @@ extension Container
where
Self: ~Copyable /*FIXME: & ~Escapable*/,
Element: ~Copyable,
BorrowingIterator_ == ContainerIterator<Self>
BorrowingIterator == ContainerIterator<Self>
{
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public func makeBorrowingIterator_() -> BorrowingIterator_ {
public func makeBorrowingIterator() -> BorrowingIterator {
ContainerIterator(
_borrowing: self,
from: self.startIndex,
@@ -31,12 +31,13 @@ where
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public func makeBorrowingIterator(from start: Index, to end: Index) -> BorrowingIterator_ {
public func makeBorrowingIterator(from start: Index, to end: Index) -> BorrowingIterator {
ContainerIterator(_borrowing: self, from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
// FIXME: This should validate that the iterator belongs to this container.
iterator._position
}
}
@@ -68,17 +69,15 @@ 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
@_alwaysEmitIntoClient
@_unsafeNonescapableResult // FIXME: we cannot convert from a borrow to an inout dependence?!
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) -> Span<Base.Element> {
public mutating func nextSpan(maxCount: Int) -> Span<Base.Element> {
_base.value
.nextSpan(
after: &self._position,
@@ -88,7 +87,7 @@ where
@_alwaysEmitIntoClient
@_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
@@ -692,15 +692,15 @@ where
copying items: borrowing C,
at index: Index
) {
var it = items.makeBorrowingIterator_()
var it = items.makeBorrowingIterator()
insert(addingCount: newCount, at: index) { target in
while !target.isFull {
let source = it.nextSpan_(maxCount: target.freeCapacity)
let source = it.nextSpan(maxCount: 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")
}
@_alwaysEmitIntoClient
@@ -813,14 +813,14 @@ where
@_alwaysEmitIntoClient
package mutating func _appendIterable<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
var it = items.makeBorrowingIterator_()
) throws(S.Failure)
where S.Element == Element {
var it = items.makeBorrowingIterator()
while true {
let span = try it.nextSpan_()
let span = try it.nextSpan()
guard !span.isEmpty else { break }
self.append(copying: span)
}
@@ -828,11 +828,11 @@ where
@_alwaysEmitIntoClient
public mutating func append<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try _appendIterable(copying: items)
}
@@ -863,11 +863,11 @@ where
/// - newElements: The new elements to copy into the container.
@_alwaysEmitIntoClient
public mutating func append<
Source: Iterable_ & Sequence<Element>
Source: Iterable & Sequence<Element>
>(
copying newElements: Source
) throws(Source.Failure_)
where Source.Element_ == Element {
) throws(Source.Failure)
where Source.Element == Element {
try self._appendIterable(copying: newElements)
}
}
@@ -14,74 +14,74 @@
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Iterable_
where Self: ~Copyable & ~Escapable, Element_: ~Copyable
extension Iterable
where Self: ~Copyable & ~Escapable, Element: ~Copyable
{
@inlinable
public func reduce<Result: ~Copyable>(
_ initialResult: consuming Result,
_ nextPartialResult:
(_ partialResult: consuming Result, borrowing Element_) throws(Failure_) -> Result
) throws(Failure_) -> Result {
try makeBorrowingIterator_().reduce(initialResult, nextPartialResult)
(_ partialResult: consuming Result, borrowing Element) throws(Failure) -> Result
) throws(Failure) -> Result {
try makeBorrowingIterator().reduce(initialResult, nextPartialResult)
}
@inlinable
public func reduce<Result>(
into initialResult: consuming Result,
_ updateAccumulatingResult:
(_ partialResult: inout Result, borrowing Element_) throws(Failure_) -> ()
) throws(Failure_) -> Result {
try makeBorrowingIterator_().reduce(into: initialResult, updateAccumulatingResult)
(_ partialResult: inout Result, borrowing Element) throws(Failure) -> ()
) throws(Failure) -> Result {
try makeBorrowingIterator().reduce(into: initialResult, updateAccumulatingResult)
}
}
// Ambiguity breakers
@available(SwiftStdlib 6.4, *)
extension Sequence where Self: Iterable_ {
extension Sequence where Self: Iterable {
public func reduce<Result: ~Copyable>(
_ initialResult: consuming Result,
_ nextPartialResult:
(_ partialResult: consuming Result, borrowing Element_) throws(Failure_) -> Result
) throws(Failure_) -> Result {
try makeBorrowingIterator_().reduce(initialResult, nextPartialResult)
(_ partialResult: consuming Result, borrowing Element) throws(Failure) -> Result
) throws(Failure) -> Result {
try makeBorrowingIterator().reduce(initialResult, nextPartialResult)
}
@inlinable
public func reduce<Result>(
into initialResult: consuming Result,
_ updateAccumulatingResult:
(_ partialResult: inout Result, borrowing Element_) throws(Failure_) -> ()
) throws(Failure_) -> Result {
try makeBorrowingIterator_().reduce(into: initialResult, updateAccumulatingResult)
(_ partialResult: inout Result, borrowing Element) throws(Failure) -> ()
) throws(Failure) -> Result {
try makeBorrowingIterator().reduce(into: initialResult, updateAccumulatingResult)
}
}
@available(SwiftStdlib 6.4, *)
extension Iterable_
where Self: ~Copyable & ~Escapable, Element_: ~Copyable
extension Iterable
where Self: ~Copyable & ~Escapable, Element: ~Copyable
{
@inlinable
public func elementsEqual<OtherSequence: Iterable_>(
public func elementsEqual<OtherSequence: Iterable>(
_ other: borrowing OtherSequence,
by areEquivalent: (borrowing Element_, borrowing OtherSequence.Element_) throws(Failure_) -> Bool
) throws(Failure_) -> Bool
where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element_: ~Copyable, OtherSequence.Failure_ == Failure_
by areEquivalent: (borrowing Element, borrowing OtherSequence.Element) throws(Failure) -> Bool
) throws(Failure) -> Bool
where OtherSequence: ~Copyable & ~Escapable, OtherSequence.Element: ~Copyable, OtherSequence.Failure == Failure
{
// 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 = try iter1.nextSpan_()
var el1 = try iter1.nextSpan()
if el1.isEmpty {
// LHS is empty - sequences are equal iff RHS is also empty
let el2 = try iter2.nextSpan_(maxCount: 1)
let el2 = try iter2.nextSpan(maxCount: 1)
return el2.isEmpty
}
while el1.count > 0 {
let el2 = try iter2.nextSpan_(maxCount: el1.count)
let el2 = try iter2.nextSpan(maxCount: el1.count)
if el2.isEmpty { return false }
for i in 0..<el2.count {
if try !areEquivalent(el1[i], el2[i]) { return false }
@@ -93,15 +93,15 @@ extension Iterable_
}
@available(SwiftStdlib 6.4, *)
extension Iterable_
where Self: ~Copyable & ~Escapable, Element_: ~Copyable & Equatable {
extension Iterable
where Self: ~Copyable & ~Escapable, Element: ~Copyable & Equatable {
@inlinable
public func elementsEqual<OtherSequence: Iterable_<Element_, Failure_>>(
public func elementsEqual<OtherSequence: Iterable<Element, Failure>>(
_ other: borrowing OtherSequence
) throws(Failure_) -> Bool
) throws(Failure) -> Bool
where
OtherSequence: ~Copyable & ~Escapable,
OtherSequence.Element_: ~Copyable
OtherSequence.Element: ~Copyable
{
return try self.elementsEqual(other, by: ==)
}
@@ -18,21 +18,21 @@ import InternalCollectionsUtilities
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
extension Iterable_ where Self: ~Copyable & ~Escapable, Element_: Copyable {
extension Iterable where Self: ~Copyable & ~Escapable, Element: Copyable {
@inlinable
package func _copyContents(
intoPrefixOf buffer: UnsafeMutableBufferPointer<Element_>
) throws(Failure_) -> Int {
intoPrefixOf buffer: UnsafeMutableBufferPointer<Element>
) throws(Failure) -> Int {
var target = buffer
var it = self.makeBorrowingIterator_()
var it = self.makeBorrowingIterator()
while target.count != 0 {
let span = try it.nextSpan_(maxCount: target.count)
let span = try it.nextSpan(maxCount: target.count)
if span.isEmpty {
return buffer.count - target.count
}
target._initializeAndDropPrefix(copying: span)
}
let test = try it.nextSpan_()
let test = try it.nextSpan()
precondition(test.isEmpty, "Contents do not fit in target buffer")
return buffer.count
}
@@ -1,64 +0,0 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2024 - 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
public protocol Iterable_<Element_, Failure_>: ~Copyable, ~Escapable {
// FIXME: None of these names should not have trailing underscores, but that
// would clash with the stdlib's versions:
// error: 'BorrowingIterator' is ambiguous for type lookup in this context
//
// This is likely best resolved by removing these definitions as soon as they
// appear in the stdlib.
associatedtype Element_: ~Copyable
associatedtype Failure_: Error = Never
associatedtype BorrowingIterator_: BorrowingIteratorProtocol_<Element_, Failure_> & ~Copyable & ~Escapable
var underestimatedCount_: Int { get }
@_lifetime(borrow self)
borrowing func makeBorrowingIterator_() -> BorrowingIterator_
func _customContainsEquatableElement_(
_ element: borrowing Element_
) -> Bool?
}
@available(SwiftStdlib 6.4, *)
extension Iterable_
where
Self: ~Copyable & ~Escapable, Element_: ~Copyable
{
@inlinable
public var underestimatedCount_: Int { 0 }
@inlinable
public func _customContainsEquatableElement_(_ element: borrowing Element_) -> Bool? {
nil
}
}
@available(SwiftStdlib 6.4, *)
extension Iterable_ where Self: Sequence {
@inlinable
public var underestimatedCount_: Int { 0 }
@inlinable
public func _customContainsEquatableElement_(_ element: borrowing Element) -> Bool? {
nil
}
}
#endif
@@ -314,12 +314,12 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
internal mutating func _append<
S: Iterable_ & ~Copyable & ~Escapable
>(copying items: borrowing S) throws(S.Failure_)
where S.Element_ == Element {
var it = items.makeBorrowingIterator_()
S: Iterable & ~Copyable & ~Escapable
>(copying items: borrowing S) throws(S.Failure)
where S.Element == Element {
var it = items.makeBorrowingIterator()
while true {
let span = try it.nextSpan_()
let span = try it.nextSpan()
if span.isEmpty { break }
self.append(copying: span)
}
@@ -337,10 +337,10 @@ 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: Iterable_ & ~Copyable & ~Escapable>(
public mutating func append<S: Iterable & ~Copyable & ~Escapable>(
copying newElements: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._append(copying: newElements)
}
#endif
@@ -380,11 +380,11 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func append<
S: Iterable_ & Sequence<Element>
S: Iterable & Sequence<Element>
>(
copying items: S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._append(copying: items)
}
#endif
@@ -23,9 +23,7 @@ import ContainersPreview
extension RigidDeque where Element: ~Copyable {
#if compiler(>=6.4) && UnstableContainersPreview
@frozen
public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol_ {
public typealias Element_ = Element
public struct BorrowingIterator: ~Escapable, BorrowingIteratorProtocol {
@usableFromInline
internal var _currentSegment: Span<Element>
@@ -73,7 +71,7 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(&self)
@_lifetime(self: copy self)
public mutating func nextSpan_(maxCount: Int) -> Span<Element> {
public mutating func nextSpan(maxCount: Int) -> Span<Element> {
let result = _currentSegment._trim(first: maxCount)
if _currentSegment.isEmpty {
_currentSegment = _nextSegment
@@ -86,7 +84,7 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
@_lifetime(borrow self)
public borrowing func makeBorrowingIterator_() -> BorrowingIterator {
public borrowing func makeBorrowingIterator() -> BorrowingIterator {
BorrowingIterator(_deque: self)
}
#endif
@@ -99,12 +97,12 @@ extension RigidDeque: Container where Element: ~Copyable {
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Index, to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
BorrowingIterator(_deque: self, from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
// FIXME: This should validate that the iterator belongs to this deque.
return iterator._position
}
@@ -132,11 +132,11 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<S: Iterable_ & ~Copyable & ~Escapable>(
public init<S: Iterable & ~Copyable & ~Escapable>(
capacity: Int,
copying contents: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(capacity: capacity)
try self._append(copying: contents)
}
@@ -187,11 +187,11 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<S: Iterable_ & Sequence<Element>>(
public init<S: Iterable & Sequence<Element>>(
capacity: Int,
copying contents: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(capacity: capacity)
try self._append(copying: contents)
}
@@ -210,11 +210,11 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<S: Iterable_ & Collection<Element>>(
public init<S: Iterable & Collection<Element>>(
capacity: Int? = nil,
copying contents: S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(capacity: capacity ?? contents.count)
try self._append(copying: contents)
}
@@ -366,12 +366,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,16 +291,16 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _prepend<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
// 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 Iterable_.estimatedCount with an exact case,
// FIXME: If we get a Iterable.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
@@ -311,15 +311,15 @@ extension RigidDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _prepend<
S: Iterable_ & ~Copyable & ~Escapable
S: Iterable & ~Copyable & ~Escapable
>(
copying items: borrowing S,
exactCount: Int
) throws(S.Failure_)
where S.Element_ == Element {
var it = items.makeBorrowingIterator_()
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in
let span = try it.nextSpan_(maxCount: target.freeCapacity)
) throws(S.Failure)
where S.Element == Element {
var it = items.makeBorrowingIterator()
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure) in
let span = try it.nextSpan(maxCount: target.freeCapacity)
target._append(copying: span)
}
}
@@ -340,10 +340,10 @@ 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: Iterable_ & ~Copyable & ~Escapable>(
public mutating func prepend<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._prepend(copying: items)
}
@@ -447,10 +447,10 @@ 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: Iterable_ & Sequence<Element>>(
public mutating func prepend<S: Iterable & Sequence<Element>>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._prepend(copying: items)
}
@@ -465,10 +465,10 @@ 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: Iterable_ & Collection<Element>>(
public mutating func prepend<S: Iterable & Collection<Element>>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try 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
@@ -300,13 +300,13 @@ extension UniqueDeque /*where Element: Copyable*/ {
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
internal mutating func _append<S: Iterable_ & ~Copyable & ~Escapable>(
internal mutating func _append<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
var it = items.makeBorrowingIterator_()
) throws(S.Failure)
where S.Element == Element {
var it = items.makeBorrowingIterator()
while true {
let span = try it.nextSpan_()
let span = try it.nextSpan()
if span.isEmpty { break }
self.append(copying: span)
}
@@ -326,10 +326,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func append<S: Iterable_ & ~Copyable & ~Escapable>(
public mutating func append<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._append(copying: items)
}
#endif
@@ -378,10 +378,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// amortized over many similar invocations over the same deque.
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func append<S: Iterable_ & Sequence<Element>>(
public mutating func append<S: Iterable & Sequence<Element>>(
copying items: S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._append(copying: items)
}
#endif
@@ -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
@@ -39,13 +39,13 @@ extension UniqueDeque: Container where Element: ~Copyable {
@_lifetime(borrow self)
public func makeBorrowingIterator(
from start: Index, to end: Index
) -> BorrowingIterator_ {
) -> BorrowingIterator {
_storage.makeBorrowingIterator(from: start, to: end)
}
@_alwaysEmitIntoClient
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
_storage.currentIndex(of: iterator)
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
_storage.currentIndex(of: &iterator)
}
}
@@ -145,11 +145,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<S: Iterable_ & ~Copyable & ~Escapable>(
public init<S: Iterable & ~Copyable & ~Escapable>(
capacity: Int? = nil,
copying contents: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(minimumCapacity: capacity ?? 0)
try self._append(copying: contents)
}
@@ -184,11 +184,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<S: Iterable_ & Sequence<Element>>(
public init<S: Iterable & Sequence<Element>>(
capacity: Int? = nil,
copying contents: S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(minimumCapacity: capacity ?? contents.underestimatedCount)
try self._append(copying: contents)
}
@@ -203,11 +203,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
@inline(__always)
public init<S: Iterable_ & Collection<Element>>(
public init<S: Iterable & Collection<Element>>(
capacity: Int? = nil,
copying contents: S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
self.init(minimumCapacity: capacity ?? contents.count)
try self._append(copying: contents)
}
@@ -384,12 +384,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
@@ -322,10 +322,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _prepend<S: Iterable_ & ~Copyable & ~Escapable>(
internal mutating func _prepend<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element
) throws(S.Failure)
where S.Element == Element
{
// 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
@@ -341,14 +341,14 @@ extension UniqueDeque /*where Element: Copyable*/ {
@available(SwiftStdlib 6.4, *)
@inlinable
internal mutating func _prepend<S: Iterable_ & ~Copyable & ~Escapable>(
internal mutating func _prepend<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S,
exactCount: Int
) throws(S.Failure_)
where S.Element_ == Element {
var it = items.makeBorrowingIterator_()
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure_) in
let span = try it.nextSpan_(maxCount: target.freeCapacity)
) throws(S.Failure)
where S.Element == Element {
var it = items.makeBorrowingIterator()
try self.prepend(addingCount: exactCount) { (target) throws(S.Failure) in
let span = try it.nextSpan(maxCount: target.freeCapacity)
target._append(copying: span)
}
}
@@ -370,10 +370,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque.
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func prepend<S: Iterable_ & ~Copyable & ~Escapable>(
public mutating func prepend<S: Iterable & ~Copyable & ~Escapable>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._prepend(copying: items)
}
@@ -483,10 +483,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque.
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func prepend<S: Iterable_ & Sequence<Element>>(
public mutating func prepend<S: Iterable & Sequence<Element>>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._prepend(copying: items)
}
@@ -502,10 +502,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque.
@available(SwiftStdlib 6.4, *)
@_alwaysEmitIntoClient
public mutating func prepend<S: Iterable_ & Collection<Element>>(
public mutating func prepend<S: Iterable & Collection<Element>>(
copying items: borrowing S
) throws(S.Failure_)
where S.Element_ == Element {
) throws(S.Failure)
where S.Element == Element {
try self._prepend(copying: items, exactCount: items.count)
}
@@ -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
@@ -1483,7 +1483,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)
@@ -1497,7 +1497,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)
@@ -259,9 +259,9 @@ class RigidDictionaryTests: CollectionTestCase {
#if UnstableContainersPreview
var actual: Set<Int> = []
_with(d.keys) { keys in // FIXME: Sigh, borrow accessors are limited in 6.4
var it = keys.makeBorrowingIterator_()
var it = keys.makeBorrowingIterator()
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
guard !next.isEmpty else { break }
for i in next.indices {
expectTrue(
@@ -297,10 +297,10 @@ class RigidDictionaryTests: CollectionTestCase {
expectEqual(keys.count, i + 1)
expectEqual(keys.capacity, capacity)
#if UnstableContainersPreview
var it = keys.makeBorrowingIterator_()
var it = keys.makeBorrowingIterator()
var actual: Set<Int> = []
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
guard !next.isEmpty else { break }
for i in next.indices {
expectTrue(
@@ -362,9 +362,9 @@ class RigidDictionaryTests: CollectionTestCase {
var seen: Set<Int> = []
let indices = d.indices
var it = indices.makeBorrowingIterator_()
var it = indices.makeBorrowingIterator()
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
if next.isEmpty { break }
expectEqual(next.count, 1)
var i = 0
@@ -301,9 +301,9 @@ class RigidSetTests: CollectionTestCase {
s.insert(tracker.instance(for: i))
var expected = Set(0 ... i)
var it = s.makeBorrowingIterator_()
var it = s.makeBorrowingIterator()
while true {
let next = it.nextSpan_(maxCount: maxCount)
let next = it.nextSpan(maxCount: maxCount)
guard !next.isEmpty else { break }
expectLessThanOrEqual(next.count, maxCount)
for j in next.indices {
@@ -147,9 +147,9 @@ class UniqueDictionaryTests: CollectionTestCase {
#if UnstableContainersPreview
var actual: Set<Int> = []
_with(d.keys) { keys in // FIXME: Sigh, borrow accessors are limited in 6.4
var it = keys.makeBorrowingIterator_()
var it = keys.makeBorrowingIterator()
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
guard !next.isEmpty else { break }
for i in next.indices {
expectTrue(
@@ -185,10 +185,10 @@ class UniqueDictionaryTests: CollectionTestCase {
expectEqual(keys.count, i + 1)
expectEqual(keys.capacity, capacity)
#if UnstableContainersPreview
var it = keys.makeBorrowingIterator_()
var it = keys.makeBorrowingIterator()
var actual: Set<Int> = []
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
guard !next.isEmpty else { break }
for i in next.indices {
expectTrue(
@@ -249,9 +249,9 @@ class UniqueDictionaryTests: CollectionTestCase {
var seen: Set<Int> = []
let indices = d.indices
var it = indices.makeBorrowingIterator_()
var it = indices.makeBorrowingIterator()
while true {
let next = it.nextSpan_()
let next = it.nextSpan()
if next.isEmpty { break }
expectEqual(next.count, 1)
var i = 0
@@ -64,12 +64,12 @@ final class IterableTests: XCTestCase {
}
@available(SwiftStdlib 6.4, *)
extension Iterable_ where Self: ~Copyable & ~Escapable, Element_: Copyable {
func collectViaBorrowing() throws(Failure_) -> [Element_] {
var borrowIterator = makeBorrowingIterator_()
var result: [Element_] = []
extension Iterable where Self: ~Copyable & ~Escapable, Element: Copyable {
func collectViaBorrowing() throws(Failure) -> [Element] {
var borrowIterator = makeBorrowingIterator()
var result: [Element] = []
while true {
let span = try borrowIterator.nextSpan_(maxCount: .max)
let span = try borrowIterator.nextSpan(maxCount: .max)
if span.isEmpty { break }
for i in span.indices {
result.append(span[i])
@@ -127,7 +127,7 @@ public func expectIterableContents<
@available(SwiftStdlib 6.4, *)
public func expectIterablePayloads<
Payload: Equatable,
E1: Iterable_<LifetimeTrackedStruct<Payload>, E> & ~Copyable & ~Escapable,
E1: Iterable<LifetimeTrackedStruct<Payload>, E> & ~Copyable & ~Escapable,
C2: Collection<Payload>,
E,
>(
@@ -137,12 +137,12 @@ public func expectIterablePayloads<
trapping: Bool = false,
file: StaticString = #filePath,
line: UInt = #line
) throws(E) where E1.Element_: ~Copyable {
var it1 = left.makeBorrowingIterator_()
) throws(E) where E1.Element: ~Copyable {
var it1 = left.makeBorrowingIterator()
var it2 = right.makeIterator()
var i = 0
while true {
let next1 = try it1.nextSpan_(maxCount: 1)
let next1 = try it1.nextSpan(maxCount: 1)
let next2 = it2.next()
switch (next1.isEmpty, next2) {
case (true, nil):
@@ -175,7 +175,7 @@ public func expectIterablePayloads<
@available(SwiftStdlib 6.4, *)
public func expectIterablePayloads<
Payload: Equatable,
E1: Iterable_<LifetimeTracked<Payload>, E> & ~Copyable & ~Escapable,
E1: Iterable<LifetimeTracked<Payload>, E> & ~Copyable & ~Escapable,
C2: Collection<Payload>,
E,
>(
@@ -186,11 +186,11 @@ public func expectIterablePayloads<
file: StaticString = #filePath,
line: UInt = #line
) throws(E) {
var it1 = left.makeBorrowingIterator_()
var it1 = left.makeBorrowingIterator()
var it2 = right.makeIterator()
var i = 0
while true {
let next1 = try it1.nextSpan_(maxCount: 1)
let next1 = try it1.nextSpan(maxCount: 1)
let next2 = it2.next()
switch (next1.isEmpty, next2) {
case (true, nil):
@@ -222,21 +222,21 @@ public func expectIterablePayloads<
#if compiler(>=6.4) && UnstableContainersPreview
@available(SwiftStdlib 6.4, *)
public func expectIterablesWithEquivalentElements<
S1: Iterable_ & ~Copyable & ~Escapable,
S2: Iterable_ & ~Copyable & ~Escapable
S1: Iterable & ~Copyable & ~Escapable,
S2: Iterable & ~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
) throws(S1.Failure_)
) throws(S1.Failure)
where
S1.Element_: ~Copyable,
S2.Element_: ~Copyable,
S1.Failure_ == S2.Failure_
S1.Element: ~Copyable,
S2.Element: ~Copyable,
S1.Failure == S2.Failure
{
if try left._elementsEqual(right, by: areEquivalent) { return }
_expectFailure(
@@ -248,8 +248,8 @@ where
@available(SwiftStdlib 6.4, *)
public func expectIterablesWithEqualElements<
Element: Equatable,
S1: Iterable_<Element, E> & ~Copyable & ~Escapable,
S2: Iterable_<Element, E> & ~Copyable & ~Escapable,
S1: Iterable<Element, E> & ~Copyable & ~Escapable,
S2: Iterable<Element, E> & ~Copyable & ~Escapable,
E,
>(
_ left: borrowing S1,
@@ -260,8 +260,8 @@ public func expectIterablesWithEqualElements<
line: UInt = #line
) throws(E)
where
S1.Element_: ~Copyable,
S2.Element_: ~Copyable
S1.Element: ~Copyable,
S2.Element: ~Copyable
{
if try left._elementsEqual(right) { return }
_expectFailure(
@@ -273,7 +273,7 @@ where
@available(SwiftStdlib 6.4, *)
public func expectIterableContents<
Element: Equatable,
S1: Iterable_<Element, E> & ~Copyable & ~Escapable,
S1: Iterable<Element, E> & ~Copyable & ~Escapable,
C2: Collection<Element>,
E,
>(
@@ -284,10 +284,10 @@ public func expectIterableContents<
file: StaticString = #filePath,
line: UInt = #line
) throws(E) {
var it1 = left.makeBorrowingIterator_()
var it1 = left.makeBorrowingIterator()
var it2 = right.makeIterator()
while true {
let span = try it1.nextSpan_()
let span = try it1.nextSpan()
if span.isEmpty { break }
for i in 0 ..< span.count {
guard let b = it2.next() else {
@@ -315,23 +315,23 @@ public func expectIterableContents<
/// Check if `left` and `right` contain equal elements in the same order.
@available(SwiftStdlib 6.4, *)
public func expectIterableContents<
S1: Iterable_ & ~Copyable & ~Escapable,
S1: Iterable & ~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
) throws(S1.Failure_) where S1.Element_: ~Copyable {
var it1 = left.makeBorrowingIterator_()
) throws(S1.Failure) where S1.Element: ~Copyable {
var it1 = left.makeBorrowingIterator()
var it2 = right.makeIterator()
var offset = 0
while true {
let span = try it1.nextSpan_()
let span = try 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: Iterable_ & ~Copyable & ~Escapable,
Expected: Sequence<S.Element_>
S: Iterable & ~Copyable & ~Escapable,
Expected: Sequence<S.Element>
>(
_ iterable: borrowing S,
expectedContents: Expected,
file: StaticString = #filePath,
line: UInt = #line
) throws(S.Failure_) where S.Element_: Equatable {
) throws(S.Failure) where S.Element: Equatable {
try checkIterable(
iterable,
expectedContents: expectedContents,
@@ -40,30 +40,30 @@ public func checkIterable<
@available(SwiftStdlib 6.4, *)
@inlinable
public func checkIterable<
S: Iterable_ & ~Copyable & ~Escapable,
Expected: Sequence<S.Element_>
S: Iterable & ~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
) throws(S.Failure_) where S.Element_: Equatable {
) throws(S.Failure) 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>] = try { () throws(S.Failure_) in
let spanShapes: [Range<Int>] = try { () throws(S.Failure) in
var r: [Range<Int>] = []
var pos = 0
var it = iterable.makeBorrowingIterator_()
var it = iterable.makeBorrowingIterator()
while true {
let origPos = pos
let span = try it.nextSpan_()
let span = try 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 = try it.nextSpan_()
let span = try 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 = try it.nextSpan_(maxCount: 1)
let span = try it.nextSpan(maxCount: 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 = try it.nextSpan_(maxCount: Int.max)
let span = try it.nextSpan(maxCount: Int.max)
if span.isEmpty { break }
expectEqual(
span.count, spanShapes[spanIndex].count,
@@ -76,9 +76,7 @@ package struct _StaccatoParameters {
}
@available(SwiftStdlib 5.0, *)
public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorProtocol_, ~Escapable {
public typealias Element_ = Element
public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorProtocol, ~Escapable {
internal let _contents: Span<Element>
internal let _params: _StaccatoParameters
internal var _offset: Int
@@ -99,7 +97,7 @@ public struct _StaccatoBorrowingIterator<Element: ~Copyable>: BorrowingIteratorP
}
@_lifetime(&self)
public mutating func nextSpan_(maxCount: Int) -> Span<Element> {
public mutating func nextSpan(maxCount: Int) -> Span<Element> {
precondition(maxCount > 0)
let maxCount = Swift.min(maxCount, _end - _offset)
let endOffset = _params.endOffset(fromOffset: _offset, maxCount: maxCount)
@@ -134,13 +132,13 @@ public struct _StaccatoIndex: Comparable, Hashable{
}
@available(SwiftStdlib 5.0, *)
extension StaccatoContainer: Iterable_ where Element: ~Copyable {
public typealias BorrowingIterator_ = _StaccatoBorrowingIterator<Element> // FIXME rdar://150240032
extension StaccatoContainer: Iterable 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)
}
}
@@ -152,11 +150,11 @@ extension StaccatoContainer: Container where Element: ~Copyable {
public var count: Int { _params._count }
@_lifetime(borrow self)
public func makeBorrowingIterator(from start: Index, to end: Index) -> BorrowingIterator_ {
BorrowingIterator_(contents: _contents.span, params: _params, start: start, end: end)
public func makeBorrowingIterator(from start: Index, to end: Index) -> BorrowingIterator {
BorrowingIterator(contents: _contents.span, params: _params, start: start, end: end)
}
public func currentIndex(of iterator: borrowing BorrowingIterator_) -> Index {
public func currentIndex(of iterator: inout BorrowingIterator) -> Index {
iterator.currentIndex
}
@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
7D0DC7BF2FFD929900BEE8B2 /* Array+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0DC7BE2FFD929500BEE8B2 /* Array+Iterable.swift */; };
7D0DC7C12FFD92BB00BEE8B2 /* InlineArray+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0DC7C02FFD92B500BEE8B2 /* InlineArray+Iterable.swift */; };
7D0DC7C32FFD987800BEE8B2 /* Range+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0DC7C22FFD987400BEE8B2 /* Range+Iterable.swift */; };
7D0DC7C52FFD990E00BEE8B2 /* ClosedRange+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0DC7C42FFD990E00BEE8B2 /* ClosedRange+Iterable.swift */; };
7D0DC7C72FFDC40900BEE8B2 /* With.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D0DC7C62FFDC40600BEE8B2 /* With.swift */; };
@@ -163,9 +162,6 @@
7D77E6252FD0F880003FA63B /* UnsafePointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D77E6242FD0F87B003FA63B /* UnsafePointer+Extras.swift */; };
7D77E6272FD0F94B003FA63B /* UnsafeMutablePointer+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D77E6262FD0F940003FA63B /* UnsafeMutablePointer+Extras.swift */; };
7D945E6B2FF5E0D1001041A6 /* UniqueSet+Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D945E6A2FF5E0CB001041A6 /* UniqueSet+Deprecations.swift */; };
7D945E6D2FF71D76001041A6 /* Span+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D945E6C2FF71D76001041A6 /* Span+Iterable.swift */; };
7D945E6F2FF71DFF001041A6 /* MutableSpan+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D945E6E2FF71DF8001041A6 /* MutableSpan+Iterable.swift */; };
7D945E712FF71E58001041A6 /* OutputSpan+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D945E702FF71E53001041A6 /* OutputSpan+Iterable.swift */; };
7D945E732FF71E8C001041A6 /* InputSpan+Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D945E722FF71E86001041A6 /* InputSpan+Iterable.swift */; };
7D9748D42E9748930098631A /* BigString+Chunk+UTF16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D32E9748930098631A /* BigString+Chunk+UTF16.swift */; };
7D9748D52E9748930098631A /* BigString+Chunk+UnicodeScalar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D9748D12E9748930098631A /* BigString+Chunk+UnicodeScalar.swift */; };
@@ -221,7 +217,6 @@
7DC037BA2FE3492D00CF0CB8 /* BorrowingIteratorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037B02FE3492D00CF0CB8 /* BorrowingIteratorProtocol.swift */; };
7DC037BB2FE3492D00CF0CB8 /* Iterable+Algorithms.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037AD2FE3492D00CF0CB8 /* Iterable+Algorithms.swift */; };
7DC037BC2FE3492D00CF0CB8 /* BorrowingIteratorProtocol+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037B32FE3492D00CF0CB8 /* BorrowingIteratorProtocol+Filter.swift */; };
7DC037BD2FE3492D00CF0CB8 /* Iterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037AC2FE3492D00CF0CB8 /* Iterable.swift */; };
7DC037BE2FE3492D00CF0CB8 /* BorrowingIteratorProtocol+ElementsEqual.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037B22FE3492D00CF0CB8 /* BorrowingIteratorProtocol+ElementsEqual.swift */; };
7DC037BF2FE3492D00CF0CB8 /* BorrowingIteratorProtocol+Reduce.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037B52FE3492D00CF0CB8 /* BorrowingIteratorProtocol+Reduce.swift */; };
7DC037C02FE3492D00CF0CB8 /* BorrowingIteratorProtocol+SpanwiseZip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DC037B62FE3492D00CF0CB8 /* BorrowingIteratorProtocol+SpanwiseZip.swift */; };
@@ -628,7 +623,6 @@
/* Begin PBXFileReference section */
7D0DC7BE2FFD929500BEE8B2 /* Array+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+Iterable.swift"; sourceTree = "<group>"; };
7D0DC7C02FFD92B500BEE8B2 /* InlineArray+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InlineArray+Iterable.swift"; sourceTree = "<group>"; };
7D0DC7C22FFD987400BEE8B2 /* Range+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Range+Iterable.swift"; sourceTree = "<group>"; };
7D0DC7C42FFD990E00BEE8B2 /* ClosedRange+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ClosedRange+Iterable.swift"; sourceTree = "<group>"; };
7D0DC7C62FFDC40600BEE8B2 /* With.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = With.swift; sourceTree = "<group>"; };
@@ -797,9 +791,6 @@
7D77E6242FD0F87B003FA63B /* UnsafePointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafePointer+Extras.swift"; sourceTree = "<group>"; };
7D77E6262FD0F940003FA63B /* UnsafeMutablePointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeMutablePointer+Extras.swift"; sourceTree = "<group>"; };
7D945E6A2FF5E0CB001041A6 /* UniqueSet+Deprecations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueSet+Deprecations.swift"; sourceTree = "<group>"; };
7D945E6C2FF71D76001041A6 /* Span+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Span+Iterable.swift"; sourceTree = "<group>"; };
7D945E6E2FF71DF8001041A6 /* MutableSpan+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MutableSpan+Iterable.swift"; sourceTree = "<group>"; };
7D945E702FF71E53001041A6 /* OutputSpan+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OutputSpan+Iterable.swift"; sourceTree = "<group>"; };
7D945E722FF71E86001041A6 /* InputSpan+Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InputSpan+Iterable.swift"; sourceTree = "<group>"; };
7D9748CF2E9748930098631A /* BigString+Chunk+Character.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BigString+Chunk+Character.swift"; sourceTree = "<group>"; };
7D9748D02E9748930098631A /* BigString+Chunk+Index.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BigString+Chunk+Index.swift"; sourceTree = "<group>"; };
@@ -851,7 +842,6 @@
7DAD89AF2E8B09EC00DD5786 /* UnsafeRawBufferPointer+Extras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UnsafeRawBufferPointer+Extras.swift"; sourceTree = "<group>"; };
7DB257A02F58B1A3007B539F /* RigidDictionary+Debugging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RigidDictionary+Debugging.swift"; sourceTree = "<group>"; };
7DB257A22F58B1CC007B539F /* UniqueDictionary+Debugging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UniqueDictionary+Debugging.swift"; sourceTree = "<group>"; };
7DC037AC2FE3492D00CF0CB8 /* Iterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Iterable.swift; sourceTree = "<group>"; };
7DC037AD2FE3492D00CF0CB8 /* Iterable+Algorithms.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Iterable+Algorithms.swift"; sourceTree = "<group>"; };
7DC037AF2FE3492D00CF0CB8 /* Iterable+Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Iterable+Utilities.swift"; sourceTree = "<group>"; };
7DC037B02FE3492D00CF0CB8 /* BorrowingIteratorProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorrowingIteratorProtocol.swift; sourceTree = "<group>"; };
@@ -1345,7 +1335,6 @@
7D2A77312F27F1E4005780C7 /* Protocols */ = {
isa = PBXGroup;
children = (
7DC037AC2FE3492D00CF0CB8 /* Iterable.swift */,
7DC037AD2FE3492D00CF0CB8 /* Iterable+Algorithms.swift */,
7DC037AF2FE3492D00CF0CB8 /* Iterable+Utilities.swift */,
7DC037B02FE3492D00CF0CB8 /* BorrowingIteratorProtocol.swift */,
@@ -1533,15 +1522,11 @@
children = (
7D0DC7BE2FFD929500BEE8B2 /* Array+Iterable.swift */,
7D0DC7C42FFD990E00BEE8B2 /* ClosedRange+Iterable.swift */,
7D0DC7C02FFD92B500BEE8B2 /* InlineArray+Iterable.swift */,
7D945E722FF71E86001041A6 /* InputSpan+Iterable.swift */,
7D59D0612FE49C87005B5097 /* InputSpan+Container.swift */,
7D945E6E2FF71DF8001041A6 /* MutableSpan+Iterable.swift */,
7D59D0622FE49C87005B5097 /* MutableSpan+Container.swift */,
7D945E702FF71E53001041A6 /* OutputSpan+Iterable.swift */,
7D59D0632FE49C87005B5097 /* OutputSpan+Container.swift */,
7D0DC7C22FFD987400BEE8B2 /* Range+Iterable.swift */,
7D945E6C2FF71D76001041A6 /* Span+Iterable.swift */,
7D59D0642FE49C87005B5097 /* Span+Container.swift */,
);
path = Conformances;
@@ -2704,7 +2689,6 @@
7DC037BA2FE3492D00CF0CB8 /* BorrowingIteratorProtocol.swift in Sources */,
7DC037BB2FE3492D00CF0CB8 /* Iterable+Algorithms.swift in Sources */,
7DC037BC2FE3492D00CF0CB8 /* BorrowingIteratorProtocol+Filter.swift in Sources */,
7DC037BD2FE3492D00CF0CB8 /* Iterable.swift in Sources */,
7DC037BE2FE3492D00CF0CB8 /* BorrowingIteratorProtocol+ElementsEqual.swift in Sources */,
7DC037BF2FE3492D00CF0CB8 /* BorrowingIteratorProtocol+Reduce.swift in Sources */,
7DC037C02FE3492D00CF0CB8 /* BorrowingIteratorProtocol+SpanwiseZip.swift in Sources */,
@@ -2720,7 +2704,6 @@
7D2A777F2F27F2BF005780C7 /* RigidDeque+Container.swift in Sources */,
7D2A77802F27F2BF005780C7 /* Deque.swift in Sources */,
7D2A77812F27F2BF005780C7 /* UniqueDeque+Append.swift in Sources */,
7D945E712FF71E58001041A6 /* OutputSpan+Iterable.swift in Sources */,
7D2A77822F27F2BF005780C7 /* UniqueDeque+Initializers.swift in Sources */,
7D2A77832F27F2BF005780C7 /* Deque+Equatable.swift in Sources */,
7D2A77842F27F2BF005780C7 /* UniqueDeque+Container.swift in Sources */,
@@ -3105,7 +3088,6 @@
7DE9201829CA70F3004483EB /* OrderedDictionary+Invariants.swift in Sources */,
7DE920CD29CA70F4004483EB /* BitSet+CustomDebugStringConvertible.swift in Sources */,
7DE9212529CA70F4004483EB /* TreeSet+SetAlgebra isStrictSubset.swift in Sources */,
7D945E6F2FF71DFF001041A6 /* MutableSpan+Iterable.swift in Sources */,
7DE9209229CA70F4004483EB /* Rope+_Storage.swift in Sources */,
7DE9203929CA70F3004483EB /* OrderedSet+Partial RangeReplaceableCollection.swift in Sources */,
7DE9206329CA70F4004483EB /* BigString+Contents.swift in Sources */,
@@ -3173,13 +3155,11 @@
7D77E6122FCF810E003FA63B /* CountedProducer.swift in Sources */,
7DE920E829CA70F4004483EB /* BitArray+BitwiseOperations.swift in Sources */,
7DE9207829CA70F4004483EB /* BigString+Append.swift in Sources */,
7D0DC7C12FFD92BB00BEE8B2 /* InlineArray+Iterable.swift in Sources */,
7DE9217F29CA70F4004483EB /* _HeapNode.swift in Sources */,
7D479CB92F46A6DB00A8CB59 /* RigidSet+Debugging.swift in Sources */,
7DE9202929CA70F3004483EB /* OrderedSet+Codable.swift in Sources */,
7DE9204829CA70F3004483EB /* _HashTable+CustomStringConvertible.swift in Sources */,
7D479CE52F47D74500A8CB59 /* RigidDictionary+Resizing.swift in Sources */,
7D945E6D2FF71D76001041A6 /* Span+Iterable.swift in Sources */,
7DE9213029CA70F4004483EB /* TreeSet+SetAlgebra isSuperset.swift in Sources */,
7DE9217529CA70F4004483EB /* TreeDictionary+MapValues.swift in Sources */,
7DE9206C29CA70F4004483EB /* BigString+Chunk.swift in Sources */,
+1
View File
@@ -22,6 +22,7 @@ OTHER_SWIFT_FLAGS = $(inherited) \
-enable-experimental-feature AddressableParameters \
-enable-experimental-feature AddressableTypes \
-enable-experimental-feature SuppressedAssociatedTypesWithDefaults \
-enable-experimental-feature BorrowingSequence \
-enable-experimental-feature "AvailabilityMacro=SwiftStdlib 5.0: macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" \
-enable-experimental-feature "AvailabilityMacro=SwiftStdlib 5.1: macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" \
-enable-experimental-feature "AvailabilityMacro=SwiftStdlib 5.6: macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" \