Commit Graph
1325 Commits
Author SHA1 Message Date
Tolga Unal 68fd4f2cc8 [DequeModule] Make UniqueDeque Iterable without ContainersPreview
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.
2026-11-05 09:09:48 -05:00
e7d8cd2203 [ContainersPreview] Fix append(copying:) recursion and wrapped insert(copying:at:) (#819)
* [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>
2026-11-03 14:57:43 -08:00
Karoy Lorentey 5bb5daddbb Merge pull request #807 from SwastikTripathi/docs-examples
Fix doc comment examples in OrderedDictionary, BitArray and SortedDictionary
2026-11-03 14:22:34 -08:00
Karoy Lorentey 9d026ae383 Merge pull request #808 from HuzaifaChaudary/fix/bitarray-wide-signed-conversion
[BitCollections] sign extend BitArray conversions to integers wider than a word
2026-11-03 14:22:18 -08:00
Karoy Lorentey a8b9b249a8 Merge pull request #818 from SwastikTripathi/fix/sorted-remove-at-rebalance
[SortedCollections] Balance the child after remove(at:)
2026-11-03 14:16:32 -08:00
Daiki Matsudate 16710713be Make UniqueDeque's Sendable conformance checked
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.
2026-11-02 16:56:23 +09:00
Swastik TripathiandClaude Opus 5.5 93745231f1 [SortedCollections] Balance the child after remove(at:)
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>
2026-11-01 09:43:22 +05:30
HuzaifaChaudary ed61a95cc8 [BitCollections] sign extend BitArray conversions to integers wider than a word
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 .
2026-10-30 20:22:20 +05:00
Swastik TripathiandClaude Opus 5.5 8da3cafe2e Fix doc comment examples in OrderedDictionary, BitArray and SortedDictionary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:04:13 +05:30
Karoy Lorentey e13f175180 Review RigidDeque/UniqueDeque tests; add better tests for prepends 2026-10-26 18:01:57 -07:00
Awais Rehman d45bd52372 Merge pull request #796 from awaisdev5765/fix-prepend-multi-span
Fix prepend(copying:) dropping items from multi-span sources
2026-10-26 12:40:35 -07:00
Karoy Lorentey a06a685e32 Merge pull request #801 from aashish254/hunt-doc-examples
[DequeModule] Fix RigidDeque prepend example capacity and direction-word slips
2026-10-26 12:02:22 -07:00
Karoy Lorentey 93b0a28178 [OrderedCollections] Resolve filename ambiguity with InternalCollectionsUtilities/UnsafeBitSet/_UnsafeBitSet.swift
This only affects some build setups using the single-module configuration on
case-insensitive filesystems, but let’s get rid of it anyway.
2026-10-26 11:37:41 -07:00
Aashish d04fe0cd79 Fix DequeModule doc comments: capacity-overflow example and prepend/append direction wording
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).
2026-10-23 16:45:05 +05:45
844289ac45 fix: guard InputSpan methods against nil base address in debug builds (#795)
* [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>
2026-10-22 18:10:28 -07:00
Karoy Lorentey 885d9a7a7e Merge pull request #798 from aashish254/fix-bitarray-resizing-shift
[BitCollections] Fix BitArray.resizingShiftRight leaving stale bits
2026-10-22 18:09:51 -07:00
Karoy Lorentey 24b83c18c4 Merge pull request #799 from aashish254/fix-bitset-intersection-docs
[BitCollections] Fix BitSet intersection doc examples for Range inputs
2026-10-22 16:21:10 -07:00
Karoy Lorentey e6196f9c7a Merge pull request #797 from aashish254/cmake-add-rigidset-extras
[ContainersPreview] Add missing RigidSet+Extras.swift to CMake source list
2026-10-22 16:00:28 -07:00
SwastikTripathi 0b51424337 Merge pull request #794 from SwastikTripathi/fix/borrowing-map-skip-infinite-loop
[BorrowingMapProducer] Fix skip(by:) hanging at end of iterator
2026-10-22 11:02:24 -07:00
Aashish fc31ca4a29 [BitCollections] Fix BitSet intersection doc examples for Range inputs
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]`.
2026-10-22 16:34:53 +05:45
Aashish 297ffa296b [BitCollections] Fix BitArray.resizingShiftRight leaving stale bits
_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.
2026-10-22 15:27:56 +05:45
Aashish b84aa036f3 ContainersPreview: Add missing RigidSet+Extras.swift to CMake source list 2026-10-22 14:49:35 +05:45
Karoy Lorentey bbdd37ada7 Fix a variety of issues in the nextSpan/previousSpan method family 2026-10-21 19:56:55 -07:00
Karoy Lorentey 1522a8a85d RigidArray, UniqueArray: Deprecate ancient span methods 2026-10-21 19:39:43 -07:00
Karoy Lorentey 1e51781091 UniqueSet.init(minimumCapacity:from:): Make sure we allocate storage for at least minimumCapacity items 2026-10-21 17:29:42 -07:00
Karoy Lorentey abddfb7ced Producer.map: Saturate generate(into:) target 2026-10-21 17:29:03 -07:00
Karoy Lorentey fcca0e3e2b Producer.filter: Saturate generate(into:) target, and fix underestimatedCount 2026-10-21 17:28:42 -07:00
Karoy Lorentey c314bdad78 Producer.skip(by:): Don’t skip fewer than n items unless we reach the end 2026-10-21 17:27:51 -07:00
Karoy Lorentey a67da2273b Merge pull request #784 from sebxt/fix/bigstring-removesubrange-stale-breaks
[BigString] Resync character breaks after removeSubrange
2026-10-21 16:34:13 -07:00
Karoy Lorentey 83e5f26fba Merge pull request #782 from aashish254/fix-774-rigidset-insert-hang
[BasicContainers] Fix RigidSet/UniqueSet batch insertion never terminating without the preview trait
2026-10-21 16:33:58 -07:00
Karoy Lorentey 4d092451ef Merge pull request #781 from aashish254/fix-772-replace-subrange-returned-range
[BasicContainers] Fix returned range of replaceSubrange(_:addingCount:initializingWith:)
2026-10-21 16:33:43 -07:00
Karoy Lorentey 6572a1b7f4 Merge pull request #777 from SwastikTripathi/fix/unique-deque-prepend-producer-order
[UniqueDeque] Fix prepend(from:) reversing batch order across producer passes
2026-10-21 16:33:30 -07:00
Karoy Lorentey 1209f9e410 Merge pull request #776 from aniketatgithub/fix-771-uniquearray-append-moving
[BasicContainers] Fix UniqueArray.append(moving:) dropping and leaking every element
2026-10-21 16:33:17 -07:00
Karoy Lorentey 156d116ec6 Merge pull request #768 from Joseph-Cursio/rigidset-hash-terminates
[BasicContainers] Fix RigidSet.hash(into:) never returning
2026-10-21 16:32:40 -07:00
Karoy Lorentey bf9b4623a1 UniqueDeque.prepend: Add perf FIXME 2026-10-21 16:04:49 -07:00
Sebastian Turner 6f8f55a5ad [BigString] Resync character breaks after removeSubrange
Signed-off-by: Sebastian Turner <sebastiant3484@gmail.com>
2026-10-20 16:18:03 -07:00
Aashish bd5960886c [BasicContainers] Fix RigidSet batch-insertion loop never terminating
insert(addingCount:initializingWith:) batches elements through a
temporary OutputSpan and loops while `remainder > 0`. When the
`UnstableContainersPreview` trait is disabled, the span's `defer`
handler moved elements out of the temporary buffer but never decremented
`remainder`, so the loop spun forever whenever the initializer didn't
fill every batch. Update `remainder` the same way the preview branch
already does, and add a regression test (issue #774).
2026-10-20 21:18:09 +05:45
Aashish 96648ca1d8 Fix replaceSubrange(_:addingCount:initializingWith:) returning a range sized by the requested count
The closure-based replaceSubrange overloads on RigidArray (and, through
them, UniqueArray and the generic RangeReplaceableContainer overloads)
returned subrange.lowerBound ..< subrange.lowerBound + newItemCount even
when the initializer performed a short fill, so the returned range could
cover old elements that were never replaced and extend past endIndex.
Return the number of items actually initialized (span.count), matching
insert(addingCount:at:initializingWith:).

Fixes #772
2026-10-20 19:45:05 +05:45
Swastik TripathiandClaude Opus 5.5 5d4a707373 [UniqueDeque] Fix prepend(from:) reversing batch order when producer needs multiple passes
prepend(from:) looped calling uncheckedPrepend, which each time placed the
new batch at index 0 of the deque. Later batches ended up in front of earlier
ones, producing items in the wrong order.

Fix: use uncheckedInsert(addingCount:at:added) so each new batch is inserted
immediately after the items already prepended in earlier passes. Promote the
overload from internal to package so ContainersPreview can reach it.

Adds a regression test covering single- and multi-batch producers prepending
into empty and non-empty deques. Fixes #763.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 08:35:03 +05:30
Aniket 80d8052b4b [BasicContainers] Fix UniqueArray.append(moving:) dropping and leaking every element
Signed-off-by: Aniket <aniketkomailkro@gmail.com>
2026-10-17 02:21:15 -07:00
Guillaume Lessard ff3c6e58ce Empty OutputSpan before closure can throw in _consumeAll() 2026-10-16 17:58:04 -07:00
Karoy Lorentey f0c713391c Merge pull request #761 from aniketatgithub/fix-sortedset-insert-update-760
SortedSet: keep the existing member on insert, replace it on update(with:)
2026-10-15 12:38:55 -07:00
Joseph CursioandClaude Opus 5.5 c65469e45f Fix RigidSet.hash(into:) never returning
_rawHashValue(seed:) looped on nextSpan() without checking for the
empty span the iterator returns once it is exhausted, so hashing any
RigidSet or UniqueSet spun forever. Break on an empty span, as == does.

Add test_hashable for both types, modeled on RigidArrayTests: equal
sets built with different capacities and insertion orders must hash
equally. Both tests hang without the fix.

Fixes #765.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 07:29:43 -05:00
Guillaume Lessard 4ff4e75436 Fix implementation of removeAll() 2026-10-14 17:28:49 -07:00
Aniket 7353b0ca86 SortedSet: keep the existing member on insert, replace it on update(with:)
Signed-off-by: Aniket <aniketkomailkro@gmail.com>
2026-10-14 08:21:27 +00:00
Karoy Lorentey 24339ad6a3 CMake: Remove obsolete references to source variables 2026-10-12 12:24:03 -07:00
Karoy Lorentey 35aedf3937 Remove unnecessary explanation 2026-10-12 11:29:41 -07:00
hamedandCursor a4f5085a7c Copy every source span in replaceSubrange(copying:).
The replacement callback took a single span and then required the source count to be exhausted, so a container stored in more than one span trapped.

Fixes #751

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 22:56:07 +03:30
Karoy Lorentey 961043b4b2 Fix _RopeModule’s CMake config in single-module mode 2026-10-08 18:51:51 -07:00
Karoy Lorentey 463946edae ContainersPreview: Adjust import statements in Foundation toolchain module mode 2026-10-08 18:32:47 -07:00