Repository navigation
feat(ts): translate NonZero's unchecked_add and unchecked_mul - #659
Conversation
Quest-Claim: 1be64c6c416f6bf3
Each is its integer's checked form under rs.precondition, which aborts at std's call of its integer's method: the nonzero_integer! call that defines the width's NonZero, as a panic hook reads. 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 10 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. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed head 6fabb93 against base db7b7bd.
No actionable findings. Removing the NonZero-specific refusal routes these calls through the existing width/sign-aware checked integer operations and precondition abort handling. Unsigned nonzero addition and multiplication of two nonzero integers cannot produce zero without overflow, so the existing overflow guard covers the additional NonZero invariant for these methods.
I checked the NonZero-to-integer dispatch, int_method's unchecked mapping, the existing std_site macro-expansion location path, and the new fixture cases/snapshots. The methods fixture adds multiplication across signed and unsigned widths and addition for unsigned widths; the hook snapshots place the u8 add and i16 multiply precondition failures at their respective std nonzero.rs macro sites rather than the caller.
Direction: keep the native differential suite as the regression gate, particularly when changing the pinned Rust toolchain because std locations are version-dependent. The separately noted from_mut/from_mut_unchecked gap is not implemented by this change.
Verification limits: GitHub-only static inspection. I did not execute the differential tests, runtime tests, compiler, or native panic-hook cases; the PR's reported successful just ci run was not independently reproduced.
(Written by review (OpenAI))

Finishes quest/m3/ts-unsafe/nonzero-unchecked-ops.md, and deletes it.
Problem
rust2-ts refused
NonZero::unchecked_addandNonZero::unchecked_mulby name. moq-dev/rust2#622 translated the integers'unchecked_*andNonZero::new_uncheckedbut left these out. These two aren't#[track_caller], so a violated precondition aborts at a location inside std's source, not at the call.Approach
ts/src/lower/library.rs. Each method now goes through theNonZeroarm to its integer'sunchecked_mapping from feat(ts): translate unchecked integer operations and NonZero::new_unchecked #622,rs.precondition(rs.u8CheckedAdd(a, b), "u8::unchecked_add cannot overflow"). Only the integer's precondition can fail: a non-zero value plus or times something, without overflow, is still non-zero, so the innernew_uncheckednever aborts.SITESentry, even though the quest's Plan expected one.std_site(ts/src/lower/mir/mod.rs) already gives a non-tracking std function that a macro defines its outermost macro call. That is thenonzero_integer! {call for that width'sNonZero, the same location native code reports, and the existing site path appends it tors.precondition.lang/methodsadds kind 49,unchecked_mulat every width, and kind 50,unchecked_addon unsigned widths.lang/panicswith thehookfeature adds cases 34 (NonZero<u8>::unchecked_add) and 35 (NonZero<i16>::unchecked_mul). Both abort, and the hook's note is compared with native, location included. The two widths give different sites (nonzero.rs:2662and:2773).ts/README.md's integer-method paragraph.Impact
Choices made without asking
std_site's macro-call location instead of addingSITESentries, which would have needed one per width.#![feature(nonzero_ops)].lang/panicsenables it only underhook, the only place that uses it.Alternatives
SITESkey perNonZerowidth: 12 entries that duplicate whatstd_sitealready works out from the def span.Follow-ups
NonZero::from_mutandfrom_mut_unchecked(unstablenonzero_from_mut) are still unmapped and refused. Plan it: a std gap with no consumer becomes its own m3 quest.NonZerois its integer, so each is the same place plus a non-zero check.Validation
quest gate nix develop --command just ci: passed (89 fixture tests, 10 runtime tests).Models
Size: XS
Implementer: Claude Code, claude-opus-5-5, high effort
(Written by Claude Opus 5.5 with high effort)
🤖 Generated with Claude Code
Review
Rewritten by
quest reviewafter each round.01a1b78a-3cea-77e0-af9e-15afba95c106, round 1The specified diff correctly reuses checked-integer lowering and preserves std-source abort locations, with differential cases covering widths, successful results, overflow, and panic-hook output; no actionable defects were found, though tests were not run in this read-only review.