Repository navigation
feat(ts): translate next_if_eq against another type than the item - #297
Conversation
Quest-Claim: 0946d550ddbb4c78
`Peekable::next_if_eq` compares by the item's `PartialEq<T>`: of another type than the item, by that impl's `eq` as a call to it lowers, std's or the crate's, with a `[u8; N]` item lent as the `rt.ByteSlice` its reference is. A pair the call lowering refuses fails at the span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merges origin/main, regenerating the lang and reject snapshots. The collections mapping compared a std `PartialEq<U>` by `eq_fn` of the left type alone, so a `String` against a crate type, or a `Vec<Left>` against a `&[Right]`, compared as two `String`s or two `Vec<Left>`s. It now maps only types that compare alike, and another goes to its impl's own call: the crate's lowers, and std's unmapped one refuses at its span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 24 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 0628bb0
No actionable bugs found. Routing heterogeneous next_if_eq through the resolved PartialEq<T> implementation is a sound direction, and the alike guard avoids silently substituting same-type equality for unsupported element comparisons. Keeping the same-type fast path and refusing unsupported heterogeneous containers is a reasonable scope boundary; the byte-array lending adapter matches the generated fixtures.
The added fixtures cover mismatch retention, empty iterators, comparison side effects, custom implementations, and mutable references. Consider a nested-container heterogeneous comparison regression as the follow-up expands support.
Verification: static review of the lowering changes, runtime signature, fixtures and surrounding equality dispatch only. I did not run tests, builds, or the reported differential/mutation checks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # ts/fixtures/lang/caller.ts # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs # ts/fixtures/reject/census.md
… main Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Completes quest/m3/ts-next-if-eq-other.md.
Problem
Peekable::next_if_eqrefused an expected value of another type than the item, such asnext_if_eq("a")ofStringitems, because it compared byeq_fnof the item's own type. Review also found that the collections mapping for stdPartialEq<U>compared by the left type'seq_fneven whenUdiffered. So a crate'simpl PartialEq<Local> for Stringcompared as two strings, and aVec<Left>against a&[Right]compared as twoVec<Left>s, in==as well.Approach
next_if_eqof another type compares by<Item as PartialEq<T>>::eqthroughfn_value, so the comparison lowers as a call to that impl does: std's mapping or the crate's own impl. A[u8; N]item is lent to it as thert.ByteSlicethat&[u8; N]is.rt.peekableNextIfEqtakesexpectedas its own type parameter.PartialEqmapping applies only to types that comparealike: the same key type, strings, bytes, or element containers of alike elements. Anything else goes to its impl's own call: the crate's impl lowers, and an unmapped std impl refuses at its span.iters::peeked_othersagainst native wasm32 covers:String/&String/&str/Cow<str>againststr,&str,String, andCow.Vec<String>againstVec<&str>.Vec<u16>andVec<u8>against slices, arrays, and&[_].[u8; 2]items against a slice.&mut u8items written through after a match.Quarter: PartialEq<u8>,u8: PartialEq<Quarter>,[u8; 2]: PartialEq<Quarter>,String: PartialEq<Quarter>), including==.next, an empty iterator, and call counts through aCell.eqtwice fails the differential with 167 differences.peeked_str(now translated) is replaced bypeeked_deque(VecDequeagainstVec) andunlike_elements(Vec<Left>against&[Right]), both refused at their spans.Optionhas no cross-typePartialEqin std, so noOptionpair reaches here.Impact
next_if_eqagainst another type translates.==of a std type against a type that doesn't compare alike now runs the impl's owneq: the crate's, or a refusal at the span for an unmapped std impl. No Rust public API change.peekableNextIfEq<T, U>takesexpected: U(widened, not breaking).Alternatives
PartialEq<U>, within this PR. Left out because it needsnehandling for elements whose crate overridesne, and the same lend for byte-array elements on both sides. Recorded as a quest.fn_valuefor the same-type case too. Dropped because it would wrap the runtime'ssameandeqSlicein an arrow for no gain.Follow-ups
==andnext_if_eqof containers of unlike elements, andVecDequeagainstVec.Review
quest review, Codexgpt-6.1-sol, medium effort.eceeb9654799932125d9c41cde0fc4ffc0888829.59b7836b):collections.rs:544Reverse hashing: refuted. That diff came from main's feat(ts): translate accessors of elements whose None is rt.None #292 because the base was ahead of the branch, and merging origin/main in0628bb0bremoved it.alikeints/src/lower/collections.rs. Covered by the reject fixtureunlike_elementsand the langString: PartialEq<Quarter>case.0628bb0b): no findings.eceeb965, after merging origin/maincecbf0d7with a hand-resolved conflict in the lang harness case list): no findings.just cipasses oneceeb965.Merge of main at
f7f0e722(#296, #300) intoeceeb965, asa35bd2ec: ordered main'ssingles::*cases beforeiters::peeked_othersinharness.rsandcaller.ts, and regeneratedharness.tsand the reject census (this PR's refusal changes, shifted lines). Recorded skip, too trivial to review;just cipassed ona35bd2ec.🤖 Generated with Claude Code
(written by Claude Opus 5.5)