1982 Commits
Author SHA1 Message Date
Karoy Lorentey 98ef3c9860 Merge pull request #740 from lorentey/release-prep
Version 1.7.1 release preparations
1.7.1
2026-09-25 16:44:01 -07:00
Karoy Lorentey a1f0f1411c Update README 2026-09-25 16:01:45 -07:00
Karoy Lorentey 935af54791 [Xcode] Remove obsolete file references 2026-09-25 16:01:42 -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 f57d12f86c Merge pull request #735 from Joseph-Cursio/validate-container-count-guard
validateContainer: report a mis-sized expectation instead of trapping or ignoring it
2026-09-25 15:13:24 -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 21807d9116 Merge pull request #737 from Denimworld12/fix-union-wrong-level
[HashTreeCollections] Fix union misplacing items pushed into a new child
2026-09-25 14:07:00 -07:00
Karoy Lorentey 99b82a4985 Apply batched suggestions from code review
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-09-25 13:48:39 -07:00
Karoy Lorentey 5448b9cdb1 Delete distracting comments
Co-authored-by: Karoy Lorentey <klorentey@apple.com>
2026-09-25 13:47:08 -07:00
Karoy Lorentey 882169ae00 Merge pull request #738 from apple/ospobot/code-of-conduct
Housekeeping: replace repo-level CODE_OF_CONDUCT
2026-09-25 13:34:09 -07:00
apple-ospo[bot] bb7c1a33d4 Replace repo-level CODE_OF_CONDUCT file with the inherited org-wide Code of Conduct in .github repo. 2026-09-25 17:41:17 +00: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
Nikhil Gupta 84e65e8b5a [BitCollections] Fix BitSet.Counted.update(with:) not maintaining the cached count
BitSet.Counted caches its size in `_count` so that `count` is O(1).
Every mutating operation is responsible for keeping that cache in sync
with the underlying bit set.

`update(with:)` forwarded straight to `BitSet.update(with:)` without
adjusting `_count`. That method inserts the member when it isn't already
present (it is defined as `insert(newMember).inserted ? nil : newMember`),
so inserting a new member this way left the cached count one too low.

The stale count is observable in a few ways:

- `count` under-reports the number of members.
- `isEmpty` is `_count == 0`, so a set that still contains members can
  report itself as empty.
- The `Collection` conformance promises `count` elements but iteration
  yields more, which breaks the standard library. `Array(set)` traps with
  "Fatal error: invalid Collection: more than 'count' elements in
  collection".

In builds with COLLECTIONS_INTERNAL_CHECKS this also violates
`_checkInvariants()`, which asserts `_count == _bits.count`.

Mirror what `insert(_:)` already does and bump `_count` when a new member
was inserted. `update(with:)` returns nil exactly in that case.

`BitSet` has had a `test_update` for this all along; `BitSet.Counted` did
not, which is how this went unnoticed. Add the matching test, following
the same combinatorial style and using `Set<Int>` as the oracle.
2026-09-25 13:02:10 +05:30
Karoy Lorentey 1a1818df8f Drop unused Optional._borrow, ._mutate and _insert definitions 2026-09-23 15:45:26 -07:00
Joseph CursioandClaude Opus 5 c0c4b3bfad Report a mis-sized expectation instead of trapping or ignoring it
validateContainer checked the container's own count, underestimatedCount
and isEmpty for consistency, but never compared count against the number
of expected contents. Every loop that follows is bounded by the
container's count and indexes expectedContents at the same offset, so the
two failure modes were:

- A short expectation ran off the end. Where the expectation is a prefix
  of the contents it matches its way to the end and then traps with
  "Fatal error: Index out of range", killing the test process instead of
  reporting a validation failure.

- A long expectation was accepted. Offsets past the container's count are
  never looked at, so an expectation of twice the length passed.

The second is the worse of the two: a test can assert far less than it
appears to, and nothing says so.

One guard fixes both, placed after the container's own count consistency
checks so that a container with a broken count still reports that rather
than a size mismatch.

The regression test uses dropLast rather than dropFirst, and the comment
says why: dropFirst shifts every element, so a content mismatch at offset
0 is reported before the out-of-bounds access happens. That masks the
defect by coincidence rather than guarding against it, and a test written
that way would have passed against the unfixed code for the wrong reason.

Watched failing before the fix: the short case trapped with signal 5, the
long case reported "an expectation of 8 items must not validate against a
container of 4". Full suite with --traits UnstableContainersPreview: 893
tests, 0 failures, so none of the six existing checkContainer call sites
was relying on either behaviour.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-23 08:02:40 -05:00
Karoy Lorentey a66de878e8 Merge pull request #731 from lorentey/release-prep
Finalize the 1.7.0 release
1.7.0
2026-09-22 19:44:20 -07:00
Karoy Lorentey 3cd6ca91d5 Drop bad Iterable tests 2026-09-22 19:19:20 -07:00
Karoy Lorentey e2c040bcaa BorrowingIteratorProtocol.map: Hide map2 and map3 behind underscores
`map2` and `map3` are merely illustrating problems with the throwing Iterable in higher-order functions in Swift 6.4; they aren’t really suitable for exposing as API, even behind a package trait.
2026-09-22 19:04:12 -07:00
Karoy Lorentey 2dcded505e Stop shipping retroactive Iterable conformances on standard types 2026-09-22 19:04:09 -07:00
Karoy Lorentey 021a54b8cc Update docs 2026-09-22 18:56:47 -07:00
Karoy Lorentey 9bf8a9763b Merge pull request #729 from lorentey/release-prep
1.7.0 release preparations
2026-09-22 12:42:05 -07:00
Karoy Lorentey 4e0c3576d5 Merge pull request #730 from Joseph-Cursio/check-set-algebra-twins
Check the mutating form* twins against their non-mutating originals
2026-09-22 11:28:31 -07:00
Karoy Lorentey edcbded708 Fix workflow spec 2026-09-22 11:15:48 -07:00
Karoy Lorentey 12dab234df Fix container validation on some 6.4 nightlies
6.4 branches don’t like the `throws(Never)` declarations that have slipped into the container validator. Get rid of them.
2026-09-22 11:15:46 -07:00
Joseph CursioandClaude Opus 5 de23cb86c8 Check the mutating form* twins against their non-mutating originals
formUnion against union, formIntersection against intersection,
subtract against subtracting, and formSymmetricDifference against
symmetricDifference, in both the Self-taking and Sequence-taking
overloads.

Each runs under withHiddenCopies at both sharing states, because a
mutating operation on a shared value is where copy-on-write bugs
live, and the original is checked afterwards to confirm it was not
mutated through the copy.

This is the highest-value law in the checker. The two implementations
should agree by construction, so a divergence is a real bug rather
than a debatable one — and nothing else here would catch a form*
method that is simply wrong: a formUnion that intersects passes every
law in the preceding commit.

Verified by injecting three defects into a stand-in conformance: a
formUnion that intersects, an isStrictSubset that drops strictness,
and a subtracting that returns a stale count. All three are caught,
and an unmodified control passes. The stale-count case is caught only
because contents and count are asserted separately.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 21:14:59 -05:00
Karoy Lorentey 8104faa3af Fix errors uncovered by new workflow configuration 2026-09-21 14:10:43 -07:00
Karoy Lorentey 0685a69944 Update workflows
- Stop testing Swift 6.0 and 6.1
- Run full unstable package trait test on 6.3 and nightly-6.4.x
- Use preconfigured install-cmake action that verifies SHA256 hash of downloaded tarball
2026-09-21 14:10:21 -07:00
Karoy Lorentey 79f41229ef Merge pull request #728 from lorentey/container-updates
`Producer.generate(into:)`: Switch to saturating semantics
2026-09-21 13:35:19 -07:00
Karoy Lorentey 9eb1e96d79 Add rudimentary swift-format configuration 2026-09-21 13:34:42 -07:00
Karoy Lorentey 537bf9cbfb Drop support for Swift 6.0 and 6.1
This allows the use of Span types without `#if compiler` guards.
2026-09-21 13:34:39 -07:00
Karoy Lorentey 78bb4bf6b9 Update README 2026-09-21 13:33:58 -07:00
Karoy Lorentey 5d0faff6c7 Update container design document 2026-09-21 13:07:04 -07:00
Karoy Lorentey 8e4f078441 Producer.generate(into:): Switch to saturating semantics
This noticeable simplifies client code, as clients invariably want to fully populate their buffer (when possible). It also is consistent with the semantics of `Iterable.skip(by:)`.
2026-09-21 13:07:01 -07:00
Karoy Lorentey c38a7173fc Merge pull request #720 from Joseph-Cursio/container-conformance-deques
Validate the Container conformance of RigidDeque and UniqueDeque
2026-09-21 12:54:59 -07:00
Karoy Lorentey a70b97e2bf Merge pull request #721 from hxperl/docc-parameter-name-backticks
Unbacktick parameter names so DocC binds the parameter docs
2026-09-21 12:54:44 -07:00
Karoy Lorentey c0c95f05a8 Merge pull request #722 from Joseph-Cursio/deque-allocation-tests
[DequeModule] Add tests for Deque's storage allocation behavior
2026-09-21 12:54:30 -07:00
Karoy Lorentey 45e7f63387 Merge pull request #725 from eliorpom-cmd/fix-typos-20260918
Fix typos in documentation and comments
2026-09-21 12:54:16 -07:00
Karoy Lorentey f959678e28 Merge pull request #719 from Joseph-Cursio/check-set-algebra
Add checkSetAlgebra, a law checker for set-like types
2026-09-21 11:02:44 -07:00
Karoy Lorentey 561d10ed84 Merge pull request #727 from lorentey/container-updates
Container: Reinstate requirement for Comparable indices
2026-09-21 11:01:37 -07:00
Karoy Lorentey b2424210b4 Container: Reinstate requirement for Comparable indices
I have a linked list prototype that can support comparable indices (and an O(1) `count`); accordingly, reinstate the requirement for index comparability. This eliminates a potential performance footgun for custom containers that define their own Index, as an incomparable index would make `func distance` 2x slower.
2026-09-21 10:41:46 -07:00
Karoy Lorentey f5db7175b3 Merge pull request #724 from lorentey/container-updates
MutableContainer: Add some bulk update operations
2026-09-21 10:10:34 -07:00
Karoy Lorentey d392f0cbff MutableContainer: Add tests; resolve issues uncovered 2026-09-21 09:54:29 -07:00
Elior Pommier cabf7390ce Fix typos in documentation and comments
Corrects 25 misspellings across DocC articles, design documentation and doc
comments. Prose only: no identifiers, no public API, no behaviour change.

| Typo | Correction | Count |
|---|---|---|
| `offseting` | `offsetting` | 7 |
| `valud` | `value` | 4 |
| `necessarilly` | `necessarily` | 3 |
| `recommmend` | `recommend` | 2 |
| `Mutablility` | `Mutability` | 1 |
| `childs` | `child's` | 1 |
| `constaints` | `constraints` | 1 |
| `destintion` | `destination` | 1 |
| `explan` | `explain` | 1 |
| `forcuses` | `focuses` | 1 |
| `ot` | `or` | 1 |
| `succcess` | `success` | 1 |
| `unqiue` | `unique` | 1 |

Two of these are worth a second look, since they are not pure spelling:

- `_HTable+Removal.swift:18` reads "without marking it as unoccupied ot
  restoring the hash table's other invariants". Read as `or`, matching the
  sentence, and deliberately not as a prefix of `other` later on the line.
- `_Node.UnsafeHandle+Deletion.swift:369` reads "reuse the left childs node".
  Corrected to the possessive `child's` rather than `children`, which is what
  a plain spellchecker suggests but does not fit the sentence.

`valud` is corrected to `value` to match the wording of the equivalent
parameter documentation on `swapAt(_:_:)`.

One change is outside documentation: `CheckContainer.swift:476` fixes
`succcess` inside a test assertion message. It is a human-readable string, not
an expected value, so no test behaviour changes.

Deliberately left alone:

- `isDisjoint(with:)-54iy6` in `OrderedSet.md` is a DocC disambiguation hash,
  not a misspelling.
- `Peristent` in the 2022 ShareableHashedCollections review document, which is
  an archived record of a past review rather than living documentation.

Found with `typos-cli`, then reviewed by hand; the tool's raw output also
flagged identifiers and symbol hashes, which are not included here.
2026-09-18 14:31:47 +02:00
Karoy Lorentey 4ea0e4443d MutableContainer: Also add copying variants of bulk updates 2026-09-16 20:44:13 -07:00
Karoy Lorentey c031de73d0 MutableContainer: Add some bulk update operations 2026-09-16 19:58:28 -07:00
Karoy Lorentey 3ceaf1ac39 Merge pull request #723 from lorentey/container-updates
Refactor DrainableContainer/RangeReplaceableContainer/DynamicContainer
2026-09-16 13:40:56 -07:00
Karoy Lorentey 5cebba6f29 Refactor DrainableContainer/RangeReplaceableContainer/DynamicContainer
Range replacement operations generally need to invalidate all indices, and that means that we lose our position in the container after each insertion/removal, unless we happen to be using a container with looser index invalidation (such as arrays or deques).

A linked list is an example for a container type where insertions/removals need to invalidate all indices — as we need to track index validation using a single version counter that is stored in the list’s head. However, it would not be acceptable to lose our place whenever we insert a new item to the list; therefore, to mitigate the validation issue, this commit changes all range-replacement operations to return a valid index range to the affected items in the container.

This is a radical break from `RangeReplaceableCollection`. It fixes a long-standing defect with it, but it also makes it tricky to conform the same type to both protocol families, as the two require the “same” methods to return different types (`Void` vs `Range<Index>`).

Given that the LSG has intentionally diverged `UniqueArray.removeAll()` from RangeReplaceableCollection semantics, I expect this isn’t going to be an issue. For example, types with existing collection conformances can expose container views, mitigating such semantic differences.

To allow SubrangeConsumers to work without losing position, add a new protocol, `ContainerDrain` with a consuming `finalize` operation that returns a valid index in the resulting container state.

While we’re here, apply the API tweaks from SE-0527:
- Revert the `replace(removing:…:)` names, rolling back to `replaceSubrange(_:…:)` .
- Similarly, rename `consume(_:)` → `consumeSubrange(_:)`
- Rename `reallocate(capacity:)` → `setCapacity(_:)`.
2026-09-14 20:37:12 -07:00
Joseph D CursioandClaude Opus 5 fe2b083fae [DequeModule] Add tests for Deque's storage allocation behavior
#113 switched `append(contentsOf:)` to exponential capacity reservation
without adding tests. This covers Deque's allocation behavior:

- Implement the empty `test_reserveCapacity` stub: reservations grow
  storage linearly to exactly the requested capacity, never shrink it,
  and leave sufficiently large unique storage in place.
- Initializers with a known element count allocate exactly that much.
- Single-element insertions follow the same capacity sequence as
  `UniqueDeque`.
- Repeated bulk insertions (append/prepend/insert/replaceSubrange, from
  contiguous arrays, collections and sequences) grow storage by a
  constant factor rather than reallocating on each call.
- Reserved capacity is used without reallocating.
- Inserting into shared storage keeps capacity when there is room and
  otherwise grows it by the same factor, leaving the original untouched.

Resolves #129.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016NTKVRe3aXMteHVrhbrTYE
2026-09-13 13:55:10 -05:00
hxperl 80216ab026 Unbacktick parameter names so DocC binds the parameter docs
Six `- Parameter` entries in `Deque` and `BitSet` write the parameter
name inside backticks (``- Parameter `i`:``). DocC binds parameter
documentation by bare identifier, so these never attach: no Parameters
section is rendered at all, and the entry instead falls into the
Discussion as a literal "Parameter `i`: ..." bullet, which also swallows
the `- Complexity:` callout that follows it.

Dropping the backticks around the name restores the Parameters section on
all six pages. Backticks inside the description text are left alone.
2026-09-11 14:07:13 +09:00