25 Commits
Author SHA1 Message Date
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 0ede027242 [HashTreeCollections] Fix invariant violation in some operations
The two-child variant of _HashNode._regularNode did not check bucket ordering before placing children, leading to inaccessible nodes half of the time.
2026-04-30 17:42:27 -07: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 cd309d5a1f Speed up testing by default 2026-01-20 10:54:31 -08:00
AZero13 3534960194 Typo: symmetric difference should be the xor, not intersection
Otherwise it is the same as the intersection.
2025-12-06 12:50:59 -05:00
Karoy Lorentey 5f03d1bc24 Adopt availability macros 2025-08-17 13:23:01 -07:00
Karoy Lorentey 54c65310f4 Adopt #filePath in test assertions 2025-08-17 13:23:00 -07:00
Karoy Lorentey 755c06dd88 Adopt _pointerBitWidth 2024-09-25 14:17:32 -07:00
Karoy Lorentey e9112f40dd [test] TreeDictionary.Keys: Remove stray print that’s flooding test output 2024-04-23 15:53:40 -07:00
Karoy Lorentey 94cf62b3ba Merge pull request #352 from vanvoorden/vanvoorden/tree-dictionary-keys-equality
[TreeDictionary][Keys] Add Equatable and Hashable Conformance to TreeDictionary.Keys
2024-02-06 18:58:46 -08:00
Rick van Voorden c61e5e23c8 tree dictionary keys hashable cleanup 2024-02-06 17:26:21 -08:00
Rick van Voorden a04721360b tree dictionary keys hashable cleanup 2024-02-06 16:25:33 -08:00
Rick van Voorden ff73ed71bb wip tree dictionary keys hashable 2024-02-06 15:57:54 -08:00
Rick van Voorden 3abf60adae wip tree dictionary keys hashable 2024-02-06 14:21:29 -08:00
Karoy Lorentey ffa4a58bc1 Update remaining copyright notices 2024-02-02 16:20:22 -08:00
Rick van Voorden d846bb25b1 edit equal keys check 2024-01-28 14:15:17 -08:00
Rick van Voorden 0e4014c468 tree dictionary keys equality 2024-01-28 13:49:26 -08:00
Karoy Lorentey 09c09f0f73 Fix CustomStringConvertible/CustomDebugStringConvertible conformances
- 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.
2023-07-06 17:25:11 -07:00
Karoy Lorentey 4b1aa5a640 [HashTreeCollections] Resolve issues with running tests on 32 bit systems 2023-05-18 18:41:42 -07:00
Karoy Lorentey a8dad62bc9 Remove obsolete swift(>=5.5)/swift(>=5.6) checks 2023-04-10 18:33:52 -07:00
Karoy Lorentey ea60d293b4 Fix test issues with single-module variant 2023-03-21 18:43:46 -07:00
Karoy Lorentey cbab9e3737 Introduce COLLECTIONS_SINGLE_MODULE condition 2023-03-21 18:42:33 -07:00
Karoy Lorentey a6392bf578 [test] expectEqualDictionaries: Also compare counts, as a fallback in case of missing invariant checks 2022-11-30 14:27:47 -08:00
Karoy Lorentey b8ef14f0c0 ShareableHashedCollections → HashTreeCollections 2022-11-28 21:35:37 -08:00