Skip to content

feat(ts): compare std sequences of unlike items, and VecDeque against any - #313

Merged
kixelated merged 8 commits into
mainfrom
quest/m3/ts-eq-unlike
Oct 30, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m3/ts-eq-unlike

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Completes quest/m3/ts-eq-unlike.md.

Problem

==, !=, and next_if_eq of std sequences were refused (unsupported call) unless both sides held items that compare alike: a Vec<Left> against a &[Right] by Left: PartialEq<Right>, and every VecDeque comparison, against a Vec, slice, array, or another VecDeque. The reject fixture's peeked_deque and unlike_elements showed it.

Approach

  • Audit of std's container PartialEq impls: slices, arrays, Vec, and VecDeque (against Vec, &[U], &mut [U], [U; N], &[U; N], &mut [U; N], and itself) all compare lengths, then each pair in order by the items' !=, and their own ne is !eq. Option, Result, Box, and tuples only compare one type with itself. Cow<[T]> is refused as a type anyway.
  • rt.eqSeq(eq) compares any two sequence forms: JS arrays, bytes in any form, and a deque's ring, read through its head.
  • seq_eq lowers a sequence pair the key mapping doesn't already handle: unlike items, items that are no key, or a VecDeque on either side. item_eq compares each pair by !<T as PartialEq<U>>::ne where the crate overrides ne, and by eq otherwise. A [u8; N] item is lent as the rt.ByteSlice its &[u8; N] is.
  • References: a pair is peeled only where std's forwarding impl resolves. Left against &Right uses Left: PartialEq<&Right>, and a crate's own impl of two references is called as is. alike no longer treats a crate's type and a reference to it as two values of one type.
  • next_if_eq shares impl_eq with the item path, so its lending code is in one place.
  • Tests: a new collections::unlike_eqs differential case. It covers unequal lengths, empty sides, items where eq and ne disagree (logging every call, which shows which one std calls and where it stops), the reverse impl with the default ne, a deque wrapped around its buffer against each sequence form, byte deques, Vec<u8> against a crate type, nested sequences, reference-specific impls, and next_if_eq matching and missing. caller.ts adds every disagreement position over inputs of length 0, 1, 2, 4, and 9. The reject fixture drops both roots, which now translate.
  • Mutation check: forcing eq instead of an overridden ne produced 871 differential differences, and reading a deque without its head produced 387.

Impact

  • Translator output only: these comparisons now translate instead of being refused. New runtime export rt.eqSeq. No breaking change.
  • Consumer: none in moq today. This is m3's all-of-std work.

Alternatives

  • Widening eqSlice itself to read every form. This adds instanceof checks to every key comparison, so it stays as the fast path for arrays.
  • Copying a deque into an array before comparing. This allocates where std doesn't.

Follow-ups

  • quest/m3/ts-eq-own-ne.md: items of one type whose ne the crate overrides are still refused, in slices, VecDeques, and through tuples and Arcs. item_eq's !ne path is the likely fix.

Review

Codex (quest review), gpt-6.1-sol, medium effort. Session 01a18f1d, latest round 4 on head ed76a2cedb67c5d6bdf91524fb06f4a7c84d309c: no findings.

  • Round 1: Vec<Left> == Vec<&Right> peeled both references and resolved the wrong impl. Fixed: references are peeled only in pairs. Two findings in drop.rs and mir/call.rs were refuted: those files came from feat(ts): drop values inside std's iterators and formatting where std's do #307 on origin/main, which this branch has since merged, and git diff origin/main on them is empty.
  • Round 2: a crate's impl PartialEq<&Right> for &Left was peeled past. Fixed: peeling only happens where std's forwarding impl resolves, with differential coverage (Odd).
  • Round 3: no findings. Round 4 reviewed the merge of origin/main, whose one hand-resolved conflict was the lang harness case list: no findings.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 8 commits October 30, 2026 15:53
Quest-Claim: 8377302edac9656b
… any

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…two of one type

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Equality of std containers of unlike elements feat(ts): compare std sequences of unlike items, and VecDeque against any Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 23:52
@kixelated
kixelated merged commit 888fce5 into main Oct 30, 2026
1 of 2 checks passed
@kixelated
kixelated deleted the quest/m3/ts-eq-unlike branch October 30, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant