Align Iterable with proposal

Adds throwing and ~Escapable elements
This commit is contained in:
Nate Cook authored and Karoy Lorentey committed 2026-06-17 14:27:29 -07:00
1 parent 4bda43f4a9
commit dca015d7e8
37 files changed
+234 -221

No files matched your search

@@ -313,11 +313,11 @@ extension RigidDeque /*where Element: Copyable*/ {
#if compiler(>=6.4) && UnstableContainersPreview
@_alwaysEmitIntoClient
internal mutating func _append<
S: Iterable_<Element> & ~Copyable & ~Escapable
>(copying items: borrowing S) {
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(copying items: borrowing S) throws(E) {
var it = items.makeIterableIterator_()
while true {
let span = it.nextSpan_()
let span = try it.nextSpan_()
if span.isEmpty { break }
self.append(copying: span)
}
@@ -334,10 +334,10 @@ extension RigidDeque /*where Element: Copyable*/ {
///
/// - Complexity: O(*m*), where *m* is the length of `newElements`.
@_alwaysEmitIntoClient
public mutating func append<S: Iterable_<Element> & ~Copyable & ~Escapable>(
public mutating func append<S: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
copying newElements: borrowing S
) {
self._append(copying: newElements)
) throws(E) {
try self._append(copying: newElements)
}
#endif
@@ -375,11 +375,11 @@ extension RigidDeque /*where Element: Copyable*/ {
/// - Complexity: O(*m*), where *m* is the length of `items`. @available(SwiftStdlib 5.0, *)
@_alwaysEmitIntoClient
public mutating func append<
S: Iterable_<Element> & Sequence<Element>
S: Iterable_<Element, Never> & Sequence<Element>
>(
copying items: S
) {
self._append(copying: items)
try self._append(copying: items)
}
#endif
}
@@ -132,13 +132,13 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_<Element> & ~Copyable & ~Escapable
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(
capacity: Int,
copying contents: borrowing S
) {
) throws(E) {
self.init(capacity: capacity)
self._append(copying: contents)
try self._append(copying: contents)
}
#endif
@@ -187,7 +187,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_<Element> & Sequence<Element>
S: Iterable_<Element, Never> & Sequence<Element>
>(
capacity: Int,
copying contents: borrowing S
@@ -208,7 +208,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_<Element> & Collection<Element>
S: Iterable_<Element, Never> & Collection<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -363,7 +363,7 @@ extension RigidDeque /* where Element: Copyable */ {
at index: Int,
copying items: borrowing C,
newCount: Int
) {
) where C.Failure == Never {
let expectedCount = self.count + newCount
var it = items.makeIterableIterator_()
insert(addingCount: newCount, at: index) { target in
@@ -424,7 +424,7 @@ extension RigidDeque /* where Element: Copyable */ {
C: Container<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing C, at index: Int
) {
) where C.Failure == Never {
_insertContainer(
at: index, copying: items, newCount: items.count)
}
@@ -486,7 +486,7 @@ extension RigidDeque /* where Element: Copyable */ {
C: Container<Element> & Collection<Element>
>(
copying items: borrowing C, at index: Int
) {
) where C.Failure == Never {
_insertContainer(
at: index, copying: items, newCount: items.count)
}
@@ -290,8 +290,8 @@ extension RigidDeque /*where Element: Copyable*/ {
#if compiler(>=6.4) && UnstableContainersPreview
@inlinable
internal mutating func _prepend<
S: Iterable_<Element> & ~Copyable & ~Escapable
>(copying items: borrowing S) {
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(copying items: borrowing S) throws(E) {
// 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.
@@ -300,20 +300,20 @@ extension RigidDeque /*where Element: Copyable*/ {
// then we should use that when possible to copy items to their final
// location in a single pass.
let oldCount = self.count
self._append(copying: items) // Not a typo!
try self._append(copying: items) // Not a typo!
_handle.rotate(toStartAtOffset: oldCount)
}
@inlinable
internal mutating func _prepend<
S: Iterable_<Element> & ~Copyable & ~Escapable
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(
copying items: borrowing S,
exactCount: Int
) {
) throws(E) {
var it = items.makeIterableIterator_()
self.prepend(addingCount: exactCount) { target in
let span = it.nextSpan_(maximumCount: target.freeCapacity)
try self.prepend(addingCount: exactCount) { (target) throws(E) in
let span = try it.nextSpan_(maximumCount: target.freeCapacity)
target._append(copying: span)
}
}
@@ -333,10 +333,10 @@ extension RigidDeque /*where Element: Copyable*/ {
///
/// - Complexity: O(*m*), where *m* is the length of `items`.
@_alwaysEmitIntoClient
public mutating func prepend<S: Iterable_<Element> & ~Copyable & ~Escapable>(
public mutating func prepend<S: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
copying items: borrowing S
) {
self._prepend(copying: items)
) throws(E) {
try self._prepend(copying: items)
}
/// Copies the elements of a container and prepends them to the front
@@ -352,7 +352,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
public mutating func prepend<C: Container<Element> & ~Copyable & ~Escapable>(
copying items: borrowing C
) {
) where C.Failure == Never {
self._prepend(copying: items, exactCount: items.count)
}
#endif
@@ -437,7 +437,7 @@ extension RigidDeque /*where Element: Copyable*/ {
///
/// - Complexity: O(*m*), where *m* is the length of `items`.
@_alwaysEmitIntoClient
public mutating func prepend<S: Iterable_<Element> & Sequence<Element>>(
public mutating func prepend<S: Iterable_<Element, Never> & Sequence<Element>>(
copying items: borrowing S
) {
self._prepend(copying: items)
@@ -453,7 +453,7 @@ extension RigidDeque /*where Element: Copyable*/ {
///
/// - Complexity: O(*m*), where *m* is the length of `items`.
@_alwaysEmitIntoClient
public mutating func prepend<S: Iterable_<Element> & Collection<Element>>(
public mutating func prepend<S: Iterable_<Element, Never> & Collection<Element>>(
copying items: borrowing S
) {
self._prepend(copying: items, exactCount: items.count)
@@ -471,7 +471,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
public mutating func prepend<C: Container<Element> & Sequence<Element>>(
copying items: borrowing C
) {
) where C.Failure == Never {
self._prepend(copying: items, exactCount: items.count)
}
@@ -487,7 +487,7 @@ extension RigidDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
public mutating func prepend<C: Container<Element> & Collection<Element>>(
copying items: borrowing C
) {
) where C.Failure == Never {
self._prepend(copying: items, exactCount: items.count)
}
#endif
@@ -463,7 +463,7 @@ extension RigidDeque /* where Element: Copyable */ {
removing subrange: Range<Int>,
copyingContainer items: borrowing C,
newCount: Int
) {
) where C.Failure == Never {
let expectedCount = self.count - subrange.count + newCount
var it = items.makeIterableIterator_()
@@ -536,7 +536,7 @@ extension RigidDeque /* where Element: Copyable */ {
>(
removing subrange: Range<Int>,
copying items: borrowing C
) {
) where C.Failure == Never {
_replace(
removing: subrange, copyingContainer: items, newCount: items.count)
}
@@ -613,7 +613,7 @@ extension RigidDeque /* where Element: Copyable */ {
>(
removing subrange: Range<Int>,
copying items: C
) {
) where C.Failure == Never {
_replace(
removing: subrange, copyingContainer: items, newCount: items.count)
}
@@ -300,11 +300,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
#if compiler(>=6.4) && UnstableContainersPreview
@_alwaysEmitIntoClient
internal mutating func _append<
S: Iterable_<Element> & ~Copyable & ~Escapable
>(copying items: borrowing S) {
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(copying items: borrowing S) throws(E) {
var it = items.makeIterableIterator_()
while true {
let span = it.nextSpan_()
let span = try it.nextSpan_()
if span.isEmpty { break }
self.append(copying: span)
}
@@ -323,10 +323,10 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// - Complexity: O(*m*), where *m* is the length of `items`, when amortized
/// over many similar invocations on the same deque
@_alwaysEmitIntoClient
public mutating func append<S: Iterable_<Element> & ~Copyable & ~Escapable>(
public mutating func append<S: Iterable_<Element, E> & ~Copyable & ~Escapable, E>(
copying items: borrowing S
) {
self._append(copying: items)
) throws(E) {
try self._append(copying: items)
}
#endif
@@ -374,11 +374,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// amortized over many similar invocations over the same deque.
@_alwaysEmitIntoClient
public mutating func append<
S: Iterable_<Element> & Sequence<Element>
S: Iterable_<Element, Never> & Sequence<Element>
>(
copying items: S
) {
self._append(copying: items)
try self._append(copying: items)
}
#endif
@@ -145,13 +145,13 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_<Element> & ~Copyable & ~Escapable
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(
capacity: Int? = nil,
copying contents: borrowing S
) {
) throws(E) {
self.init(minimumCapacity: capacity ?? 0)
self._append(copying: contents)
try self._append(copying: contents)
}
#endif
@@ -184,7 +184,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_<Element> & Sequence<Element>
S: Iterable_<Element, Never> & Sequence<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -203,7 +203,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
@inline(__always)
public init<
S: Iterable_<Element> & Collection<Element>
S: Iterable_<Element, Never> & Collection<Element>
>(
capacity: Int? = nil,
copying contents: S
@@ -381,7 +381,7 @@ extension UniqueDeque /* where Element: Copyable */ {
at index: Int,
copying items: borrowing C,
newCount: Int
) {
) where C.Failure == Never {
let expectedCount = self.count + newCount
var it = items.makeIterableIterator_()
insert(addingCount: newCount, at: index) { target in
@@ -445,7 +445,7 @@ extension UniqueDeque /* where Element: Copyable */ {
C: Container<Element> & ~Copyable & ~Escapable
>(
copying items: borrowing C, at index: Int
) {
) where C.Failure == Never {
_insertContainer(
at: index, copying: items, newCount: items.count)
}
@@ -511,7 +511,7 @@ extension UniqueDeque /* where Element: Copyable */ {
C: Container<Element> & Collection<Element>
>(
copying items: borrowing C, at index: Int
) {
) where C.Failure == Never {
_insertContainer(
at: index, copying: items, newCount: items.count)
}
@@ -322,8 +322,8 @@ extension UniqueDeque /*where Element: Copyable*/ {
#if compiler(>=6.4) && UnstableContainersPreview
@inlinable
internal mutating func _prepend<
S: Iterable_<Element> & ~Copyable & ~Escapable
>(copying items: borrowing S) {
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(copying items: borrowing S) throws(E) {
// 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.
@@ -332,20 +332,20 @@ extension UniqueDeque /*where Element: Copyable*/ {
// then we should use that when possible to copy items to their final
// location in a single pass.
let oldCount = self.count
self._append(copying: items) // Not a typo!
try self._append(copying: items) // Not a typo!
_storage._handle.rotate(toStartAtOffset: oldCount)
}
@inlinable
internal mutating func _prepend<
S: Iterable_<Element> & ~Copyable & ~Escapable
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(
copying items: borrowing S,
exactCount: Int
) {
) throws(E) {
var it = items.makeIterableIterator_()
self.prepend(addingCount: exactCount) { target in
let span = it.nextSpan_(maximumCount: target.freeCapacity)
try self.prepend(addingCount: exactCount) { (target) throws(E) in
let span = try it.nextSpan_(maximumCount: target.freeCapacity)
target._append(copying: span)
}
}
@@ -367,11 +367,11 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque.
@_alwaysEmitIntoClient
public mutating func prepend<
S: Iterable_<Element> & ~Copyable & ~Escapable
S: Iterable_<Element, E> & ~Copyable & ~Escapable, E
>(
copying items: borrowing S
) {
self._prepend(copying: items)
) throws(E) {
try self._prepend(copying: items)
}
/// Copies the elements of a container and prepends them to the front
@@ -388,7 +388,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
public mutating func prepend<C: Container<Element> & ~Copyable & ~Escapable>(
copying items: borrowing C
) {
) where C.Failure == Never {
self._prepend(copying: items, exactCount: items.count)
}
#endif
@@ -479,7 +479,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque.
@_alwaysEmitIntoClient
public mutating func prepend<
S: Iterable_<Element> & Sequence<Element>
S: Iterable_<Element, Never> & Sequence<Element>
>(
copying items: borrowing S
) {
@@ -498,7 +498,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
/// over many similar invocations on the same deque.
@_alwaysEmitIntoClient
public mutating func prepend<
S: Iterable_<Element> & Collection<Element>
S: Iterable_<Element, Never> & Collection<Element>
>(
copying items: borrowing S
) {
@@ -518,7 +518,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
public mutating func prepend<C: Container<Element> & Sequence<Element>>(
copying items: borrowing C
) {
) where C.Failure == Never {
self._prepend(copying: items, exactCount: items.count)
}
@@ -535,7 +535,7 @@ extension UniqueDeque /*where Element: Copyable*/ {
@_alwaysEmitIntoClient
public mutating func prepend<C: Container<Element> & Collection<Element>>(
copying items: C
) {
) where C.Failure == Never {
self._prepend(copying: items, exactCount: items.count)
}
#endif
@@ -472,7 +472,7 @@ extension UniqueDeque /* where Element: Copyable */ {
removing subrange: Range<Int>,
copyingContainer items: borrowing C,
newCount: Int
) {
) where C.Failure == Never {
let expectedCount = self.count - subrange.count + newCount
var it = items.makeIterableIterator_()
@@ -546,7 +546,7 @@ extension UniqueDeque /* where Element: Copyable */ {
>(
removing subrange: Range<Int>,
copying items: borrowing C
) {
) where C.Failure == Never {
_replace(
removing: subrange, copyingContainer: items, newCount: items.count)
}
@@ -625,7 +625,7 @@ extension UniqueDeque /* where Element: Copyable */ {
>(
removing subrange: Range<Int>,
copying items: C
) {
) where C.Failure == Never {
_replace(
removing: subrange, copyingContainer: items, newCount: items.count)
}