52 Commits
Author SHA1 Message Date
Karoy Lorentey 827fef0660 Merge pull request #817 from Joseph-Cursio/drainable-container-check
Add checkDrainableContainer and fix RigidArray's consumeLast recursion
2026-11-10 11:01:51 -08:00
Joseph CursioandClaude Opus 5.5 afa8580b15 Add checkPermutableContainer
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>
2026-11-05 16:48:47 -06:00
Sandeep Vijayarao 2c246541db Fix six small bugs in _CollectionsTestSupport
- 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
2026-11-05 13:52:56 -08:00
Karoy Lorentey 7b578e5bfb Review and fix filter implementations
- 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
2026-11-04 18:28:38 -08:00
Joseph CursioandClaude Opus 5.5 d60ceae062 Add checkDrainableContainer
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>
2026-11-03 19:16:00 -06:00
Joseph CursioandClaude Opus 5.5 bc6be7189f Add checkMutableContainer
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>
2026-10-27 04:51:50 -05:00
Joseph CursioandClaude Opus 5.5 5200f52956 Add checkBidirectionalContainer
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>
2026-10-27 04:51:50 -05:00
Joseph CursioandClaude Opus 5.5 6f570e0ad8 Add checkSetAlgebraMemberIdentity
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>
2026-10-15 14:44:55 -05:00
Joseph CursioandClaude Opus 5.5 2f2c59a39b checkSetAlgebra: Repeat the sequence enough to expose counted duplicates
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>
2026-10-13 20:59:19 -05:00
Joseph CursioandClaude Opus 5.5 edaba634e4 checkSetAlgebra: Also pass a sequence that underestimates its count
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>
2026-10-13 20:17:24 -05:00
Joseph CursioandClaude Opus 5.5 9d4284eb0e checkSetAlgebra: Check isEqualSet(to:) for SetAPIExtras types
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>
2026-10-13 20:10:12 -05:00
Joseph CursioandClaude Opus 5.5 d54c0be657 checkSetAlgebra: Check the predicates against plain sequences too
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>
2026-10-13 20:10:12 -05:00
Karoy Lorentey 9e7949017a Tests: add unsafe keywords where needed 2026-10-01 11:44:47 -07:00
Karoy Lorentey 44b674265c Update import statements 2026-09-29 15:41:05 -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
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 9bf8a9763b Merge pull request #729 from lorentey/release-prep
1.7.0 release preparations
2026-09-22 12:42:05 -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 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
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
Joseph CursioandClaude Opus 5 c99e944570 Add checkSetAlgebra, a law checker for set-like types
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>
2026-09-09 10:45:24 -05:00
Karoy Lorentey 1f94ac8f54 Implement (partial) Container validation 2026-09-01 10:14:42 -07:00
Karoy Lorentey 669eb09cea Use Iterable from the Standard Library, replacing the local definition 2026-07-27 13:32:46 -07:00
Karoy Lorentey ff695132ed Bump availability of Iterable_ and Container protocols to SwiftStdlib 6.4
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.
2026-07-07 14:22:45 -07:00
Karoy Lorentey d0b4c4c215 IterableIterator_ → BorrowingIterator_ 2026-07-07 14:21:53 -07:00
Karoy Lorentey bb0dc189ef maximumCount → maxCount
While we’re here, adjust `RigidSet.insert(maximumCount:initializingWith:)` and similar APIs to be consistent with RangeReplaceableContainer’s methods.
2026-07-07 14:21:53 -07:00
Karoy Lorentey 85cdb77d25 Fix build issues 2026-06-17 16:17:36 -07:00
Nate Cook dca015d7e8 Align Iterable with proposal
Adds throwing and ~Escapable elements
2026-06-17 14:27:29 -07:00
Nate Cook 4bda43f4a9 Renaming BorrowingSequence_ to Iterable_ 2026-06-17 14:27:29 -07:00
Franz Busch 3c373b900c Use the defines from traits directly
Package traits already pass defines with their trait name when building. Instead of adding our own conditional defines based on the traits we can use the trait provided defines directly. I observed that various tooling behaves better with the trait provided defines.
2026-05-06 07:41:02 -07:00
Karoy Lorentey 597b7a7dd2 Revert most of the availability constraints from 419e2f and 4c0482 🎉 2026-03-27 11:25:43 -07:00
Nate Cook a99a015934 Disambiguate ContainersPreview and stdlib
Adds trailing underscores to the BorrowingSequence protocols and
requirements, in order to allow both parallel conformances and
the ability to evolve the requirements in this package.
2026-03-27 07:41:32 -05:00
Karoy Lorentey 4c04822689 [ContainersPreview] Exhibit B in the case against prototyping things in the stdlib 😳 2026-03-26 18:13:22 -07:00
Karoy Lorentey 70a25f1f69 [ContainersPreview] Bump required toolchain to 6.4 for new protocols 2026-03-26 14:51:08 -07:00
Karoy Lorentey 11443c0531 Enforce uniform license headers 2026-03-07 10:26:28 -08:00
Karoy Lorentey 1c69635852 Add SPDX-License-Identifier tags 2026-03-05 19:39:24 -08:00
Karoy Lorentey d9b09ecde8 Update copyright dates 2026-03-05 19:39:20 -08:00
Karoy Lorentey 214d75cb73 BorrowingSequence: estimatedCount ⟹ underestimatedCount
EstimatedCount is largely pointless. Knowing the exact count does enable a fast negative path for `elementsEqual`, but we can otherwise make do with just the (much simpler to understand/deal with) `underestimatedCount` that already exists on `Sequence`.
2026-03-05 15:33:27 -08:00
Karoy Lorentey 7692d9c4b3 RigidArray: Add test coverage; revive some container-based operations 2026-02-04 22:41:33 -08:00
Karoy Lorentey 2318ef4c4e Fix random issues in single-module mode 2026-02-04 17:35:18 -08:00
Karoy Lorentey 70a36c2c47 RigidDeque: Another iterative design pass on deque operations
- Adopt and embrace Drain and Producer to simplify moving data in and out of deques.
- Fully generalized core range replacement primitive using higher-order functions based around InputSpan and OutputSpan
2026-01-25 16:42:40 -08:00
Karoy Lorentey e4aba4c1c9 Iterable → BorrowingSequence, BorrowIterator → BorrowingIterator 2026-01-25 16:42:37 -08:00
Karoy Lorentey 67abaf5182 Replace Container with a far less powerful (but more universal) Iterable construct
I’m hoping Container will return later.
2026-01-08 17:28:23 -08:00
Karoy Lorentey 1dc2b7717f Revert "Don’t allow backdeployment of any Span types below the most recent Darwin OS releases"
This reverts commit 485e69bfb1.

# Conflicts:
#	CMakeLists.txt
2025-09-27 12:15:30 -07:00
Karoy Lorentey 485e69bfb1 Don’t allow backdeployment of any Span types below the most recent Darwin OS releases
References to Span types trigger an issue where SwiftPM isn’t able to run command line executable targets or tests on older OSes.

Set the availability of everything that needs span types to the most recent Apple OS releases.

Hopefully we’ll be able to revert this once we figure out a better workaround.
2025-09-26 22:38:18 -07:00
Karoy Lorentey 2ae7f11ecf Add draft version of borrowable Container protocol 2025-09-26 18:40:00 -07:00
Karoy Lorentey b71cc36f2d [TestSupport] Add Container validator and StaccatoContainer
These are precursors for container protocols, referenced by the new array tests
2025-08-17 13:33:41 -07:00
Karoy Lorentey 0e8dd37073 Box → ClassBox
In preparation of adding the public, noncopyable Box type
2025-08-17 13:33:28 -07:00
Karoy Lorentey 54c65310f4 Adopt #filePath in test assertions 2025-08-17 13:23:00 -07:00