Repository navigation
feat(ts): translate drains and B-tree ranges of Bound pairs and the crate's own RangeBounds - #267
Conversation
Quest-Claim: 75591e93be84a4c9
… census needs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rate's own RangeBounds The runtime's Bounds reads a (Bound, Bound) as the pair it is, and any other RangeBounds through rt.boundsOf, which calls its start_bound and then its end_bound where std's does: not at all for an empty B-tree. B-tree ranges panic on equal excluded ends, and slice::range checks an excluded start as std's does, with std's messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…est reads as a message Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…akes one 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>
…td does Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wn by its comparisons Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 36 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: 8f693b143b929878949aeeb4c26e1a887e59e5ad.
No actionable bugs found in the changed areas. Centralizing range lowering while deferring custom bound evaluation preserves the empty-tree and callback-order distinctions without eagerly evaluating every range. Excluded endpoints and custom comparison callbacks—including wrapped keys—are handled coherently, and refusing drop-bearing ranges avoids silently losing their destructors. The differential cases meaningfully exercise endpoint combinations, borrowed bounds and drain/drop behavior. The separately documented whole-B-tree drop-order gap is not introduced by this change.
Verification: independent static review of lowering, runtime range checks, generated output and fixtures. I did not run CI, differential tests or census measurements; reported results were not independently verified.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
rust2-ts refused a range given as a
(Bound<T>, Bound<T>)pair or as a crate's ownRangeBoundswhereverVec::drain,VecDeque::drain, or a B-tree'srangeorrange_muttakes one (#259 added the refusal). moq's model census had 15 of these refusals, and moq-net's whole-crate census had 18. They come from moq-net'sledger.rs,model/track.rs, andmodel/expiry.rs, and from rangemap, which ranges itsBTreeMaps by(Bound<&Wrapper>, Bound<&Wrapper>).Moved from m3 to m2 under ts-model (first commit). The quest sat in m3 as a generic std gap. But the model's census, which ts-model measures its children by, needs it now, so it is ts-model work. This PR finishes the quest, so the second commit deletes it again.
Approach
collections::bounds): every drain and B-tree range goes through one path.Bounds pass as they are, since a pair's JS value already holds its twort.RangeBounds.RangeBounds<T>becomesrt.boundsOf(range, start_bound, end_bound).Tcomes from the callee's ownR: RangeBounds<T>clause, and the two methods resolve throughfn_value, so the crate's own impl, generic or not, translates as its other methods do.rt/collections.ts):boundsreturnsstart_boundand thenend_boundfor every form. A crate's own pair of bounds is computed only when read.rangedoes not.rangenow handles an excluded start. It checks the two ends as std'ssearch_tree_for_bifurcationdoes: equal excluded ends with==, thenstart > endwith>, each panicking with std's message. For a target holding the crate's own type, the translator passes that type'sPartialEq::eqandPartialOrd::gt(its own override, orpartial_cmp). A target of std types alone checks by the map'sOrd, which matches std's==and>with no side effects.sliceRangenow followstry_into_slice_rangestep by step: the end first, then the start, withExcluded(start) >= endpanicking. Panic messages come from std'sslice_index_fail, including its fallback that names the end.R, which drops, to ..." message. The reject fixture'sSpentrange shows it forVec::drain,VecDeque::drain, andBTreeMap::range. It is listed in the drop-order quest.Census
Measured with
just ts censusat the pinned moq revision, on this branch before it merged main's later commits (head 5dc4bac), against main at #259:The brief's "15" for the model counted lines in its census file: 3 table rows and 12 refusals. On head 486f363, which includes main through #265, the totals are 411, 1482, and 144; the rest of that movement comes from #262, #263, and #265. No range refusal is left in any of the three, and this PR adds no other refusal.
Tests
bounds::bounds, run differentially against native wasm32. Named cases cover all 9 pairs of bound kinds, 36 value pairs around and past 4 items, and 0 items, so ranges are empty, backwards, equal, excluded on both ends at one value, and out of bounds. Panics are compared by message.Vecdrains of items that log their drops, of bytes, and of words, by pairs ofBound<usize>andBound<&usize>.RangeBoundsthat logs when it is asked for each bound. The log shows it is asked before the drain yields or drops anything, and not at all for an empty B-tree.VecDequedrains whose items wrap around the buffer.BTreeMap::rangeandrange_mutandBTreeSet::range, including through a genericfn<R: RangeBounds<u8>>.Ord, ranged by(Bound<&Key>, Bound<&Key>)as rangemap ranges, and the same keys held in(u8, Key)tuples.Keylogs each==andpartial_cmp, so the test shows which comparisons std makes of the ends.Impact
Boundpair or a crate's ownRangeBoundsnow translate instead of being refused.rt.boundsOfis new.rt.Boundsalso accepts aBoundpair and a function returning one.rangeCheckis now exported fromrt.ts. Nothing breaks.Alternatives
boundsOftoo would be fully uniform, but it costs a closure and an array on every call on moq's ledger path. A tuple'sstart_boundandend_boundare pure, so passing the pair directly is not observably different.start_bound/end_boundeagerly at the call site would be simpler, but it would ask an empty B-tree for its bounds, which std does not.Choices made without asking
Bounds passes as its own value instead of throughboundsOf(see Alternatives).Follow-ups
BTreeMapnode by node in postorder (drop_tree), but the runtime drops in key order. So a map of 12 or more entries that drop logs a separator key at a different point. This is a silent divergence, not a refusal, and the model may reach it through B-trees of values that drop.Review
Local review with
quest review: Codex, gpt-6.1-sol, medium effort. Reviewed head 5d5f2f7: no findings.VecDequepaths without dropping it. Fixed:boundsrefuses it at every call site, covered by the reject fixture.Ord::cmp, but std usesPartialEq::eqand>. Fixed: the crate's owneqandgtare passed, andKeylogs its comparisons in the differential test.Option<Key>, tuples) skipped those callbacks. Fixed: any owned type in the target passes them, with a(u8, Key)differential case.just cipasses locally on 5d5f2f7.🤖 Generated with Claude Code
(written by Claude Opus 5.5)