Commit Graph
1303 Commits
Author SHA1 Message Date
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
Karoy Lorentey 9cabf522ec CMake: Fix building ContainersPreview as a Foundation toolchain module 2026-10-08 18:32:15 -07:00
Karoy Lorentey e9da0fb277 Merge pull request #752 from parkera/parkera/embedded_bigstring
Build BigString in Embedded Swift - with a custom implementation of grapheme walking instead of using the stdlib
2026-10-08 18:29:51 -07:00
Karoy Lorentey 34151d7731 Merge pull request #746 from aniketatgithub/fix-sortedset-sequence-setalgebra
SortedSet: generalize set operations to arbitrary Sequences
2026-10-08 17:31:51 -07:00
Tony Parker 500233e8c0 Use _addressString in debug description 2026-10-08 17:28:56 -07:00
Karoy Lorentey 75cd22c7aa Update comments
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-10-08 17:07:58 -07:00
Tony Parker d014985b5f Build BigString in Embedded Swift - with a custom implementation of grapheme walking instead of using the stdlib 2026-10-08 16:41:20 -07:00
kwy404 ea599358e6 [BitCollections] Fix BitSet.Counted.isEqualSet(to:) rejecting sequences with duplicates
The generic `isEqualSet(to: some Sequence<Int>)` overload returned false
whenever `other.underestimatedCount` exceeded `count`. A sequence with
duplicate items can be longer than the set it equals, so
`([1, 2, 3, 4] as BitSet.Counted).isEqualSet(to: [4, 1, 1, 2, 3, 3, 4] as [Int])`
returned false, contradicting the documented behavior.

Forward straight to `BitSet.isEqualSet(to:)`, which already handles
duplicates and keeps the count shortcut for unique collections.
2026-10-02 17:54:38 -03:00
Karoy Lorentey 1b936eda0b Disable strict memory safety on older toolchains
It would take too much effort to try to mitigate stdlib differences.

Fix low-hanging warnings, but turn off `.strictMemorySafety` on older toolchains by splitting the package manifest.
2026-10-01 13:40:27 -07:00
Karoy Lorentey 9e7949017a Tests: add unsafe keywords where needed 2026-10-01 11:44:47 -07:00
Karoy Lorentey d07dc32dfa Sources: Add unsafe keywords where needed 2026-10-01 11:14:29 -07:00
Aniket 0d731a673c SortedSet: generalize set operations to arbitrary Sequences
SortedSet's set operations only accepted another SortedSet, so
SortedSet([1, 2]).union(0 ..< 10) did not compile and the type could
not conform to SetAPIChecker.

Add the customary Sequence generalizations for all 13 operations,
keeping the existing Self overloads as the fast path (concrete beats
generic in overload resolution). Arbitrary sequences fall back through
a temporary SortedSet or, for the membership predicates, allSatisfy.

Fixes #743.

Signed-off-by: Aniket <aniketkomailkro@gmail.com>
2026-09-30 03:14:10 -07:00
Karoy Lorentey a5b094974f Merge pull request #745 from lorentey/migrate-from-spi-to-package
Stop using `@_spi` attribute and `@testable import`
2026-09-29 18:51:34 -07:00
Karoy Lorentey c991c8543a Update SortedCollections for un-@testable testing 2026-09-29 18:32:58 -07:00
Karoy Lorentey 0ec72a9532 Stop using @_spi attribute and @testable import 2026-09-29 18:32:55 -07:00
Karoy Lorentey c410b3cd3a Remove obsolete/disabled APIs 2026-09-29 15:41:06 -07:00
Karoy Lorentey 44b674265c Update import statements 2026-09-29 15:41:05 -07:00
Karoy Lorentey 1be474f795 Xcode, CMake: Spin off ContainersPreview into its own target 2026-09-29 15:41:03 -07:00
Karoy Lorentey 2ba0f6e59f Merge pull request #739 from lorentey/drop-unused-code
Avoid using `Ref` in Swift 6.4
2026-09-25 15:18:19 -07:00
Karoy Lorentey f1e675acd2 Turn off BorrowingIteratorProtocol.next()
The reference to `Ref` appears to trigger a broken strong linkage to `_swift_initBorrow`, despite the code being only available on macOS/iOS/etc 27.
2026-09-25 15:01:04 -07:00
Karoy Lorentey feef32596a Merge pull request #736 from Denimworld12/fix-bitset-counted-update-count
[BitCollections] Fix BitSet.Counted.update(with:) not maintaining the cached count
2026-09-25 14:07:45 -07:00
Karoy Lorentey 5448b9cdb1 Delete distracting comments
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-09-25 13:47:08 -07:00
Nikhil Gupta ab29aa793d [HashTreeCollections] Fix union misplacing items pushed into a new child
`copyNodeAndPushItemIntoNewChild` takes an existing item out of `self` and
pushes it into `newChild`, which is then installed as a child of `self` at
`bucket`. `newChild` therefore sits one level below `self`, but the item was
inserted into it using `self`'s level:

    let r = newChild.inserting(level, item, hash)

Navigating with the parent's level picks the wrong hash digit, so the item —
and the subtree it is merged with — end up filed under a path that doesn't
match their hash.

`TreeSet.union` reaches this when it merges an incoming collision node against
an item already occupying that bucket. The result is a set that still reports
the right `count` and still yields every element when iterated, but whose
misplaced members cannot be found by `contains`, since lookup navigates by
hash:

    let a1 = RawCollider(1, "A")
    let a2 = RawCollider(2, "B")
    let c1 = RawCollider(5, "ACAD")
    let c2 = RawCollider(6, "ACAD")

    let u = TreeSet([a1, a2]).union(TreeSet([c1, c2]))
    u.count          // 4
    Array(u)         // [2#B, 1#A, 5#ACAD, 6#ACAD]
    u.contains(c1)   // false
    u.contains(a1)   // false

Building the same set directly with `TreeSet([a1, a2, c1, c2])` is unaffected;
only the structural merge paths are.

Insert at `level.descend()` instead.

Enumerating every pair of subsets of the shared `testItems` fixture, 171 of
4096 unions contained at least one member that `contains` could not find.
With this change all 4096 are clean.

Also fix the full invariant check, which could not run on any tree containing
a collision node. Collision nodes store their item count in `itemMap` and
`childMap` rather than a set of occupied buckets, so treating those bitmaps as
buckets walks items that aren't there — a node holding 5 items has
`itemMap._value == 5`, whose bits nominate buckets 0 and 2. The bucket loop now
only runs for regular nodes. Before this, `swift test
-Xswiftc -DCOLLECTIONS_INTERNAL_CHECKS` trapped immediately in
HashTreeCollections; that trap was also what kept the invariant check from
reporting the misplaced nodes above.

Add a regression test alongside the existing `test_union_collision_node_ordering`.
2026-09-25 14:11:23 +05:30