Skip to content

feat(ts): translate the inherited ne, lt, le, gt, and ge, and byte slice equality - #107

Merged
kixelated merged 4 commits into
mainfrom
quest/m2/ts-cmp-defaults
Oct 27, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m2/ts-cmp-defaults

Conversation

@kixelated

@kixelated kixelated commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

a != b and a < b on a derived type, or on any type whose impl leaves ne, lt, le, gt, or ge to the trait's default, were refused as unsupported calls. #98 made comparisons through references reach the referent's impl, which still refused an inherited method. <[u8] as PartialEq>::eq was also unsupported.

Approach

  • library::Inherited: when a call resolves to the trait's own default body of PartialEq::ne or PartialOrd::lt/le/gt/ge, call_def calls eq or partial_cmp with the same generic arguments and operands, then tests the result as std's default does:
    • ne is !eq.
    • lt is o === -1 and gt is o === 1.
    • le and ge are o !== undefined && o <= 0 (or >= 0), with the partial_cmp spilled to a const unless it is already a path.
    • A partial_cmp returning None makes all four false, whatever eq says.
  • It goes through call_def, so eq/partial_cmp resolve wherever they live: the crate's own or derived impl, std's Option (rt.cmpOption), or a reference's (referent). An impl that overrides ne or lt itself is still called directly.
  • <[u8] as PartialEq>::eq maps to a new rt.byteSliceEq. [T] has no ne of its own, so != on byte slices comes along through the default.

Differential tests, in the lang fixture's new keys::defaults (kind 3 of keys):

  • Rough: a hand-written eq by value and a partial_cmp by quarter that returns None past 200. != holds alongside <= and >=, and no ordering holds past 200.
  • Skew: its existing partial_cmp is reversed against its derived eq and is None between odd values.
  • Also covered: Option<Rough>, including Some(a) <= None; Skewed(&Skew), a derive through a reference; Option<Hop>; derived Horizon and Name, through & and &&; Side's derived != and Way's own eq; and all of it through a generic fn compare<T: PartialOrd>.
  • Byte slices with == and !=, through references and not, at different offsets into one buffer, and empty.

Mutation checks against native Rust. Each was caught:

mutation differences
le as !gt (o !== 1) 170
ge as !lt 170
ne as eq 516
byteSliceEq ignoring start 173

moq-net census

At main b09f8aa, with and without this PR's lowering.

before after
unsupported inherited ne, lt, le, gt, ge 135 (82 ne, 53 orderings) 5
unsupported eq or partial_cmp 20 74
refusals 11503 11428
function instances 4901 4922
  • Of the 130 that changed, 76 now translate, path::Path's ne among them. The other 54 now report the eq or partial_cmp they reach. Most of those are other crates' types: moq_clock::Instant (28 partial_cmp), std::time::Duration (9), and Vec<Range> (8).
  • The 5 left are not inherited defaults. They are std's own impls: tuple orderings ((u64, u64) > , 3) and Vec's ne (2).
  • kio: 344 refusals before and after. One Option<(*const (), ...)>::ne now reports its eq.

Impact

  • Translator output: inherited comparisons and byte slice equality now translate.
  • Runtime: new rt.byteSliceEq(a, b).
  • collections::trait_fn is now pub within the crate. There are no config changes.

Choices made without asking (for review)

  1. Every type, not only the crate's own. The hook keys on the instance being the trait's default body, so Option, String, and other crates' types go the same way. For std types it gives what the old ne mapping in collections gave, and for the rest it reports the real missing piece (eq or partial_cmp). Recommendation: keep.
  2. Spill for le and ge, rather than adding ?? to the printer or a runtime helper. The spill goes through pre, which emit orders with pending temporaries, the same way hasher_call spills. Recommendation: keep.

Alternatives

  • Map ("PartialEq", "ne") and the orderings per type in collections. That would duplicate what eq_fn and cmp_fn reach, and it would miss the crate's own types.
  • Runtime helpers rt.partialLe(o) and similar. Inline tests are cheaper and read as the std default does.

Follow-ups

  • Tuple orderings (<(A, B) as PartialOrd>::lt, 3 in moq-net). std implements them through __chaining_*, not as defaults.
  • Equality of Vecs and slices of non-bytes (Vec<Range>, 11 in moq-net).
  • moq_clock::Instant and Duration comparisons (about 50) follow from supporting those types.

Checks: just check, just test (ts fixtures with differential tests, ffi, uniffi), just ts moq, just ts census, and quest check --base origin/main.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

kixelated and others added 2 commits October 26, 2026 20:46
…ice equality

A `PartialEq` or `PartialOrd` impl that leaves `ne` or the orderings to its
trait, as every derive does, now lowers them as std's defaults: `!eq`, and a
test of `partial_cmp` that is false for `None`. `<[u8] as PartialEq>::eq` maps
to `rt.byteSliceEq`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Default comparison methods feat(ts): translate the inherited ne, lt, le, gt, and ge, and byte slice equality Oct 27, 2026
@kixelated
kixelated marked this pull request as ready for review October 27, 2026 04:16
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T05:44:06.610374Z 622c938 New commits
🔒 Security Review ✅ Completed 2026-10-27T05:45:15.502227Z 622c938 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 4a1f1fa

No actionable bugs found in the changed code. The direction is sound: recognizing the resolved trait default preserves explicit overrides, reusing call_def avoids duplicating per-type dispatch, and the le/ge spill evaluates partial_cmp once while keeping None false. The byte-slice comparison respects both lengths and offsets. This is simpler than adding per-type comparison mappings or extra runtime ordering helpers.

Verification: inspected the lowering/dispatch paths, pending-expression emission, runtime helper, and Rust/generated-TypeScript fixtures, including unordered and inconsistent equality/ordering cases. I did not run builds or tests; the PR's reported checks were not independently reproduced.

@kixelated
kixelated merged commit b588838 into main Oct 27, 2026
1 check passed
kixelated added a commit that referenced this pull request Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated added a commit that referenced this pull request Oct 27, 2026
* chore(quest): claim quest/m2/ts-mir-size.md

Quest-Claim: 4f881bb5b70f75e4

* feat(ts): fold single-use temporaries and loop over arrays with for-of

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* feat(ts): share a coroutine field among locals never live at once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* feat(ts): keep a coroutine's argument in its own field

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* feat(ts): give 64- and 128-bit sums their own functions

A bundle with only 64-bit sums, like the async handoff's u64Add, no
longer pulls in the 128-bit limbs. sum64 reads halves without boxing a
number into limbs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): keep stepped loops as while loops

for-of over an array took Firefox 1.19x as long on the async handoff
against the stepped loop (A/A 1.05), and Chrome no less time. Without
it the handoff is 3440 bytes gzipped, under its 3458 target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* Revert "fix(ts): keep stepped loops as while loops"

The Firefox gap was the bench's first translated route, not for-of:
timed the other way round, the stepped loops were the slow ones by the
same margin, and each A/A copy matched the other build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): narrow ts-mir-size to the codec's gzipped gap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): restate ts-mir-size's gap after #87

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* test(ts): order a folded read after a write, and two panics

Each case fails the lang differential when its rule in inline::folds is
removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* test(ts): regenerate strs' snapshot for folded temporaries

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* fix(ts): share an upvar's field only with a copy that runs once

A capture copied into a local on each pass of a loop shared the
capture's field, so changing the copy changed what the next pass
copied. The copy must now run at most once, in the first poll, before
any other use of the local there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* chore(quest): restate ts-mir-size's codec gap after #82

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* test(ts): regenerate shapes' snapshot after merging main

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

* Regenerate snapshots after merging #107

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

---------

Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated deleted the quest/m2/ts-cmp-defaults branch October 27, 2026 20:32
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