`BitSet[members:]` resolved range expressions against
`Int.min ..< Int.max`. A closed range ending at `Int.max`
(`bits[members: ...Int.max]`, `bits[members: 0 ... Int.max]`) needs the
index after `Int.max`, so it trapped with "Index out of bounds", while
`..<Int.max` and `0...` worked.
Resolve against a small internal collection of all `Int` values whose
`index(after:)` saturates at `Int.max`. `Int.max` can never be a bit set
member, so `lower ... Int.max` resolving to `lower ..< Int.max` doesn't
change which members are selected. `BitSet.Counted[members:]` forwards
to `BitSet`, so it's fixed too.
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]`.
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.
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.
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.
`_toUInt()` returns nil whenever a bound is negative, and the guard maps that
straight to `false`. That is right for a nonempty range -- a bit set can never
hold a negative value -- but an empty range equals the empty set regardless of
where its bounds sit, so `BitSet().isEqualSet(to: -5 ..< -5)` answered false.
Five of the six `Range<Int>` predicates already handle this: isSubset and
isDisjoint clamp, isStrictSubset composes those two, and isSuperset and
isStrictSuperset test `other.isEmpty` before converting. isEqualSet was the
one that did not, which let a bit set be both a subset and a superset of a
range while reporting that it was not equal to it.
As of 2026-09-01, conformance checks are now diagnosed as errors:
```
70 | // Fast paths for when we know elements are all unique
71 | if elements is _UniqueCollection {
| `- error: cannot perform a dynamic cast to a type involving protocol '_UniqueCollection' in Embedded Swift
```
Twenty-five doc comments in the shipping modules name an argument that the
declaration below them does not have, so DocC has nothing to bind the
description to and drops it. Nothing warns about this.
Most of them are renames that the comment did not follow, and the file itself
usually holds the proof: RigidDeque.prepend says - maxCount while its own
Complexity line already says newItemCount, and append(copying:) has three
overloads where the oldest still takes newElements and the two newer ones take
items with the older one's wording.
Three entries name an argument that no longer exists at all and are removed
rather than renamed.
This enables faster iteration over subranges of a BitSet than the `Slice` type’s default indexing iterator. (Depending on the fill factor, the speedup can be as high as 4x — not insignificant.)
DocC keeps changing its link syntax. The latest iteration appears to have trouble dealing with `Self`-taking or `Self`-returning methods, so change our API to replace `Self` with a direct mention of the concrete type. ¯\\\_(ツ)\_/¯
That said, the new compiler also found a large number of mismatching parameter names, and that was really helpful.
The indexes passed to span(after:) and friends on UniqueArray
and RigidArray are modified before return. This adds notes
about the updated values to the method documentation, along
with a few other minor formatting changes (dropping smart
quotes, single-sentence abstracts).
Recent development compiler versions have started emitting errors for previously undiagnosed cases where a conformance in another module is referenced by a source file that does not itself explicitly import that module. Add the missing imports.
We are forced to do this due to an Xcode issue (#364) with underscored module names.
This module remains unstable, despite the removal of the underscore. Directly importing it from outside the package remains unsupported. This module and/or its entire contents may go away or change in incompatible ways in any future swift-collections release.
- For CustomStringConvertible, `description` should print elements using `String(reflecting:)` rather than `String(describing:)`, to avoid element output from interfering with syntactically relevant punctuation within structured list displays.
- To make this work without making displays overly verbose, make `debugDescription` mostly the same as `description`, except for escaping raw string displays when and if needed.
- Avoid printing type names in `debugDescription` — it is generally not helpful, as the type is already easily accessible elsewhere. Including it makes for overly verbose displays when the type serves as an Element of a collection.
- Avoid having `debugDescription` return the empty string — it can be confusing when such a description appears in list displays.
Resolves#301.
The `isEqual(to:)` methods are a bit too confusing — they implement
mathematical set comparisons (ignoring element ordering and, in the
case of the Sequence variant, even element multiplicities), so it
seems better to highlight this by putting a `Set` in the name.
These marker-like protocols will allow certain
generic operations to get a performance boost
if the passed-in value happens to be guaranteed
to contain unique elements or to be sorted.
Also, review API checker protocols for Sets and
sorted collections and adjust things as needed.
BitSet gains custom implementations for min()
and max() as part of these improvements.