Check swapAt(_:_:), the one requirement PermutableContainer adds to
Container, against an Array model. The checker swaps every pair of
indices, including an index with itself, and then repeats the same swaps
in reverse order, comparing the whole container after each swap. That
leaves the container holding the expected contents in their original
order. It first runs validateContainer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- withEveryDeque/withEveryFullDeque now visit capacity 0.
- checkEquatable reports transitivity violations instead of trapping
when pairs arrive out of order (non-transitive oracles, maxSamples).
- Minimal range-replaceable collections no longer trap in removeLast()
and popLast().
- LifetimeTracked's "Double deinit" precondition can now fire.
- withEvery, withEveryRange and withSomeArrayLayouts include the
failing value in their "Throwing trace".
- CustomCountedProducer drops its unused chunkSize parameter, and the
two loops that reran identical cases over it are removed.
Adds regression tests for the first three.
Fixes#810
- Define a separate `filter` result on Iterable vs BorrowingIteratorProtocol
- Fix handling of delimited iterators in Container.filter
- Add fixmes for throwing
- Inlinability and other small fixes
- Add iterable-based assertions
- Have a single actual implementation; let everything else forward to it
- Delete obsolete assertion variants
- Stop requiring UnstableContainersPreview for Iterable assertions
Check the DrainableContainer requirements and extensions against
Array's removeSubrange(_:), for every subrange: that a subrange drain
hands out the removed items in order, in spans no longer than maxCount,
then only empty spans, with an accurate count; that it removes the
whole subrange whether it is finalized or dropped partway, and
finalize() returns the index following the removed items; that
consumeSubrange(_:consumingWith:) passes the removed items to its
consumer and discards those it leaves; the items and indices returned
by remove(at:), removeFirst() and the index-returning removals,
including the RangeExpression2 and UnboundedRange overloads; and that
no item is leaked or destroyed but the removed items not handed out.
For a BidirectionalContainer, consumeLast(_:), removeLast(),
removeLast(_:) and popLast() are checked too.
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>
Check which of two equal but distinguishable members insert(_:),
update(with:) and remove(_:) keep and return, using Set as the
reference.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Doubling the other model's elements only exposes an implementation that
counts occurrences instead of distinct members when the two sets share
at least half of the receiver's elements, which depended on the models
a test happened to pick. A BitSet.isStrictSubset that counted
duplicates passed every model pair. Repeat the other model
`xm.count + 2` times instead, so a shared element always appears more
often than the receiver has members.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every sequence the checker passed reported its exact count, so an
implementation that trusts underestimatedCount went unnoticed: an empty
TreeSet whose isEqualSet returned `other.underestimatedCount == 0`
passed every test. Also check the predicates and isEqualSet against a
single-pass MinimalSequence, whose underestimatedCount is 0.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No checker exercised isEqualSet(to:), and no test passed it a sequence
with duplicates, so #749's bug, where BitSet.Counted rejected such
sequences, went unnoticed until it was reported. Add a checkSetAlgebra
overload for SetAPIExtras types that also checks isEqualSet against the
models: given another Self, an Array, an Array with duplicates, and a
Set, which takes the _UniqueCollection path in the types that have one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five predicates were only ever given another Self, so a type whose
Sequence-taking overloads first check for Self never ran their
general path under the checker. Check them against an Array of the
other model, with and without duplicates, as the set operations
already are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
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:)`.
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.
SetAPIChecker verifies that a set-like type has the right shape: it is
a protocol with no assertions, so conforming makes the compiler check
that the API surface exists. This adds the other half — that the
operations behave as documented.
Constrained on SetAPIChecker rather than SetAlgebra, because
OrderedSet deliberately does not conform to SetAlgebra (only its
UnorderedView does, for documented reasons about order-sensitive
equality). Constraining on the stdlib protocol would exclude the type
that needs this most.
Follows the house pattern of validating the specification before the
implementation. A Set<Element> model is only as sound as Element's
Hashable conformance, so _checkSetAlgebraModels runs _checkHashable
over the model elements and verifies each model survives a round trip
through Array before any instance is judged; it returns false and the
caller stops rather than reporting defects in the wrong artefact. A
broken model and a broken implementation can agree with each other,
which fails quietly in a way a wrong implementation does not.
Per-instance: contents and count against the model, isEmpty against
count independently of it, the empty set's identity and absorption
cases, the reflexive containment predicates, and filter at both
extremes and in between.
Per-pair: the four operations against the model and again through the
Sequence-taking overloads, which are separate entry points and can
diverge from the Self-taking ones; commutativity, both absorption
laws, and symmetricDifference against its definition in terms of the
other three; and the containment predicates against the model and
against each other. A type can implement each predicate plausibly and
still have them disagree.
Contents and count are asserted separately throughout: a type that
maintains a stored count can return the right elements alongside a
stale one.
Call sites for BitSet, OrderedSet and TreeSet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- Move `InputSpan` into its own module, `SpanPreview`. Add dependencies to it.
- Invert dependencies to `ContainersPreview`, so that no production target imports it, but it now depends on its previous dependents.
- Move all generic APIs and conformances using `Producer`/`Drain`/`Container` to the `ContainersPreview` module.
- Remove `UnstableContainersPreview` conditions around `Iterable` APIs
In summary, importing `BasicContainers` and `DequeModule` continue to get us the basic definitions for `RigidArray`, `UniqueSet`, `RigidDeque` etc., without most of their unstable APIs. (With the exception of core APIs that require `InputSpan`.)
To get any API that uses an unstable protocol like `Container` or `Drain`, we’ll now need to import `ContainersPreview` in addition to the type-defining module.
This will provide a slightly less horrible migration path when (if) the container/producer protocol family gets adopted/adapted into the stdlib.
- Make `nextSpan(after:limitedBy:)` the core iteration interface
- Review default algorithms and update them to use it, speeding them up
- Spin off `Span._nextSpan(after:maxCount)` and `Span._nextSpan(after:limitedBy:)` with copying lifetime semantics. This allows forwarding to these without having to override lifetimes.
- Require Index to be Hashable
- Add strong complexity expectations. Require `isEmpty`, `count` and `endIndex` to have O(1) complexity. Recommend most index navigation methods to be linear in the distance traveled.
- Remove `index(alignedDown:)` and `index(alignedUp:)`; Collection views are far less relevant in this model, so index rounding is mostly unnecessary. (The need can still pop up when indices are shared between several views of layout-compatible Element types — such as a container of UInt64 than can also be interpreted as a container of UInt8; if that becomes a thing, we may need to bring these requirements back.)
- Add `nextSpan(after:limitedBy:)` as an alternative to `nextSpan(after:maximumCount:)`. This makes it possible to provide fast default implementations for `distance(from:to:)` and `formIndex(_:offsetBy:limitedBy:)`.
This is preparing for switching over to the stdlib’s definition of `protocol Iterable`, assuming it will land with macOS 27/iOS 27 etc availability; `Container` is refining `Iterable`, so it needs matching availability.
If `Iterable` won’t ship in Swift 6.4, then we’ll need to bump this again.
This is currently limited to `Container`, `BidirectionalContainer`, `RandomAccessContainer` and `MutableContainer`. `OutputSpan` and `InputSpan` should also be `RangeReplaceableContainer`s, but that is proving tricky to express in current Swift.