Repository navigation
feat(ts): translate comparisons through references and &mut slice index writes - #98
Conversation
Quest-Claim: 11a6aeffc6455635
…ex writes std's PartialEq, PartialOrd, Ord, and Hash impls for references call their referents', so a derived impl on a type holding references now reaches the referent's. A bounds check of a `&mut` slice reads its length through a fake raw pointer, which now reads the slice's, so `live[0] = x` translates. A variant MIR reads without a switch, as a derived `==` reads the other operand of an enum whose variants all hold data, is cast to it for tsc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 45f606e
No actionable bugs found in the changed code. Recursive forwarding through the resolved std reference impl preserves the referent's custom comparison/hash behavior without conflating PartialOrd with Ord; restricting raw-pointer support to FakeForPtrMetadata keeps the slice-write change narrow. The mixed-reference, disagreeing PartialOrd, reassigned-reborrow, and bounds-panic fixtures target the important distinctions.
Direction: these are coherent extensions of the existing lowering, with no new runtime abstraction. Always casting enum downcasts would be simpler than the function-wide switched-path heuristic, but I found no concrete regression requiring that change here; the heuristic is not control-flow proof. Documented default-method and slice-equality refusals remain separate gaps, not newly fixed behavior.
Verification: source and generated-snapshot review only; I did not run the translator, native differential tests, or the test suite.
(Written by OpenAI)
Regenerate the lang snapshots for #98's cases over ByteSlice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
* chore(quest): default comparison methods and generic instances Follow-ups from #98 and #94. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): Cow<str> and str slicing from #96 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): share Copy types the crate never changes in place Replaces ts-shared-read's narrow fix, as #99 suggested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn * chore(quest): an A/A control that measures noise From #87's and #97's bench findings. 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>
Problem
Two shapes #83's tests hit were refused with a span:
<&T as PartialEq>::eq, which a derived==on a type holding references reaches, was an unsupported call. std's impls for references were mapped only for std key types, not the crate's own.live[0] = xon a&mut [u8]was refused as a raw pointer. MIR's bounds check of a&mutslice reads its length through&raw const (fake) *live, a fake borrow that onlyPtrMetadatareads.Approach
library::referent: a method that std'sPartialEq,PartialOrd,Ord, orHashimpl for references defines calls the referent's with the operands dereferenced.call_defcalls the referent's impl with the same operands, since a reference is its referent in JS. This is recursive (&&T), covers&mutand mixed&/&mutoperands, and leaves methods the impl inherits from its trait (Ord::max) alone.rt.idx(live, i), the same as a&[u8]read, and the pointer is dropped as unread. Any other raw pointer is still refused.==on an enum whose variants all hold data reads the other operand's fields with no switch on it, because MIR removed the unreachable arms.tscthen rejectedother._0. A downcast of a path no emitted switch tests is now cast to its variant:(other as { tag: "Hop"; _0: Hop.Hop | undefined })._0. The cast is type-only.Differential tests against native Rust, in the lang fixture:
keys::borrows: an enum derivingPartialEq,Eq,PartialOrd,Ord, andHash, holding&Option<Hop>,&&Horizon,&str,&Name, and&mut Hop. Every pair is compared, ordered, and hashed. Also&a == &b,&&g == &&h,&mut x == &mut y, the mixed&/&mutforms, andHashof&mut. A struct deriving onlyPartialOrdover&SkewreachesSkew's ownpartial_cmp, which disagrees with itscmp.shapes::write_atandmoved_at: index writes and compound assignments on&mut [u8]and&mut [Point], an index past the end that panics, and a reassigned reborrow whose bounds checks go the general way rather than throughrt.idx.A mutation check that reversed the forwarded operands gave 951 differences from native Rust.
moq-net census
<&T as PartialEq>::eqor::ne<path::Path as PartialEq>::ne(4, the trait's defaultneon a crate type),<moq_clock::Instant as PartialEq>::eq(2, another crate's type), and<Cow<str> as PartialEq<str>>::eq(1).&mutslice index sites translate. The 2 left are innum_enum's derive inietf/parameters.rs.kio::Producer(2),kio::Pending(1), andmoq_clock::Instant(1).Impact
&mutslices, now translate. A variant read with no switch on it gets a type-only cast.Choices made without asking (for review)
PartialOrd,Ord, andHashthrough references are included withPartialEq. They are the same shape, std's impls for references, and the same code handles them. Recommendation: keep.==on an enum holding references, failstscwhenever every variant holds data. The check does not follow control flow: it casts unless a switch emitted earlier in the function tested that path. An extra cast costs nothing. A missing one failstscloudly. Recommendation: keep.ne,lt,le,gt, andgeon a crate type stay refused.a != banda < bon a derived type are separate gaps. They can land on their own, and moq-net's census has about 60<T as PartialEq>::nerefusals. Recommendation: plan a follow-up quest.Alternatives
collections.rsas a key comparison. That covers only std key types and gets no recursion for free.Follow-ups
ne,lt,le,gt, andgeofPartialEqandPartialOrdon the crate's types as!eqandpartial_cmptests (about 60 moq-net refusals).<[u8] as PartialEq>::eq(slice equality) is unsupported. It came up while writing the tests.Checks:
just check,just ts test(all fixtures, differential tests included),just ts moq,just ts census, andquest check --base origin/main. Not run:just ffi test,just driver test, andjust uniffi test, which this change does not touch. #82 (rt.ByteSlice) is still open. Its byte slices have alengthtoo, sort.idxand the fallback work unchanged after a merge.(written by Opus 5.5)
🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn