842f125c removed the trait conditions around the Iterable APIs, but
UniqueDeque only got its conformance through Container in ContainersPreview.
RigidDeque had no underestimatedCount, so it was 0 through Iterable.
* [ContainersPreview] Fix append(copying:) recursion and wrapped insert(copying:at:)
The RangeReplaceableContainer extension's append(copying:) passed a
contiguous source's buffer back to itself and never returned.
_insertCollection copied the whole buffer on every initializer call, which
trapped when a deque's gap wrapped around the end of its storage. Copy only
what fits on each call, as replaceSubrange(_:copying:) already does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Delete Tests/DequeTests/RangeReplaceableContainerCopyingTests.swift
Let's drop the tests for now; we'll need a less involved way to exercise such algorithms.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
UniqueDeque's only stored property is RigidDeque<Element>, which is
already Sendable when Element is, so the compiler can verify the
conformance without @unchecked. This mirrors UniqueArray over RigidArray.
remove(at:) recursed into the child holding the offset and returned
without balancing it, so repeated removals could empty a leaf. Iterating
then read a stale slot, which returned already-removed elements and read
released references in release builds, and trapped in debug builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
converting a negative bit array to `Int128` lost the sign above the first
64 bits , so `Int128(truncatingIfNeeded: "1" as BitArray)` gave
18446744073709551615 , not -1 , `Int128(exactly:)` gave nil , and
`Int128(_:)` trapped . a negative value now starts out as all ones , so the
words shifted in keep the sign .
the trap message also named `BitArray` as the type it could not convert
to , it names the integer type now .
Run the mutable container checker, which also runs the bidirectional
one, against UniqueDeque over every storage layout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the mutable container checker, which also runs the bidirectional
one, against RigidDeque over every storage layout. With #793's
spanBoundary fix reverted, it fails with a negated distance.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the mutable container checker, which also runs the bidirectional
one, against RigidArray. With #793's nextMutableSpan fix reverted, it
fails with the index not advancing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the bidirectional container checker against BidirectionalContainer's
default implementations. With #793's formIndex(_:offsetBy:limitedBy:)
fix reverted, it fails.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check that nextMutableSpan and previousMutableSpan, with and without
maxCount and a limit, return the expected span from every index, move
the index past it, and write through to exactly those elements.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check a BidirectionalContainer's backward navigation against its forward
navigation: index(before:), spanBoundary(before:) and previousSpan(before:)
with and without maxDistance or maxCount and a limit, negative offsets and
distances, and formIndex(_:offsetBy:limitedBy:) in both directions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The prepend(copying:) examples on RigidDeque build a capacity-10 deque and then insert 11 items, which traps with 'RigidDeque capacity overflow' -- the type never grows and the docs' own fixed-capacity section says a full deque traps. Capacity 11 holds the documented result. Also fix five copy-paste direction errors in prose summaries (append described as going to the front, prepend described as going to the end).
* [BorrowingMapProducer] Fix skip(by:) hanging at end of iterator
When a BorrowingMapProducer's Failure is not Never, skip(by:) drove a
loop over nextSpan calls. Once the base iterator was exhausted,
nextSpan kept returning an empty span (count == 0), so the counter
never decremented and the loop ran forever.
Add a guard that exits the loop when the span is empty, matching the
skip(by:) contract: return with the remaining count when the iterator
runs out of elements before n reaches 0.
Adds a regression test that builds a RigidArray from a
mapError+map chain. RigidArray.init(capacity:from:) calls _expectEnd,
which exercises exactly the exhausted-iterator code path.
Fixes#773
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: guard InputSpan methods against nil base address in debug builds
removeFirst(_:), prepend(repeating:count:), and consumePrefix(upTo:) each
call _unsafeRawAddressOfSlot(uncheckedOffset:) before checking whether
there is anything to do. That helper calls _start(), which calls
_pointer.unsafelyUnwrapped and traps in debug builds when the base
address is nil — which happens for InputSpan(), for empty ranges handed
to consumeSubrange closures, and for SubrangeConsumer drains once the
range is exhausted.
Add an early return for the zero-work case in each method, the same
pattern that removeAll() and deinit already use. Release builds were
unaffected in practice because unsafelyUnwrapped skips the nil check
under -O, but the behaviour is formally undefined; this fix makes both
build modes consistent and safe.
Fixes#788
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* Resolve conflict
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
* Prefer guard for succinct exit conditionals
This follows our preferred coding style, and also syncs this code with OutputSpan's implementation in the stdlib.
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
* Check OrderedSet.UnorderedView with checkHashable
The equivalence classes hold permutations of the same members, sets
that differ by one member or by count, and sets on both sides of the
hash table threshold, including small sets that carry a hash table or
reserved capacity.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Check OrderedSet.SubSequence with checkHashable
The equivalence classes hold equal slices taken from different base
sets, at different offsets, and from bases with and without a hash
table, alongside slices that differ in order, members or count.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Check OrderedDictionary.Values with checkHashable
The equivalence classes hold dictionaries with different keys but the
same value sequence, alongside values that differ in order, contents
or count, including repeated values.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The examples for `intersection(_ other: Range<Int>)` and
`formIntersection(_ other: Range<Int>)` (on both `BitSet` and
`BitSet.Counted`) showed the result of the corresponding `subtract`
example instead: intersecting `[1, 2, 3, 4]` with `-10 ..< 3` yields
`[1, 2]`, not `[3, 4]`.
_resizingShiftRight(by:) copied the surviving suffix down to index 0 and
then removed `count &- amount` trailing bits instead of `amount`, so it
truncated the result to `amount` stale bits rather than keeping
`count - amount` valid ones. resizingShiftLeft(by: -n) was affected via
the same path, and the API had no test coverage at all.
Also fix the doc examples, which demonstrated the resizing shifts with
the masking shift function names (and, in one case, a result whose bit
count contradicted the documented growth by `amount`).
Add regression tests asserting parity with the documented semantics
(dropFirst / prepending false values) across word-boundary counts,
negative amounts, boundary `amount` values, and the doc examples
verbatim.