[mono-move] Implement integer cast micro-op#19936
Open
vgao1996 wants to merge 1 commit into
Open
Conversation
Add a universal `IntCast` micro-op covering all 12x12 (from, to) integer type pairs. Semantics match the existing Move VM: the cast preserves the source's mathematical value and aborts iff the value falls outside the target type's range. Self-casts (from == to) are accepted and run as identity, since the bytecode verifier admits them and the production VM executes them. - core: `IntCastOp` + `MicroOp::IntCast`, display, gas, re-exports - runtime: `exec_int_cast` (uniform per-pair `TryFrom` dispatch), `CastOutOfRange` error, verifier frame-access checks - specializer: lower `UnaryOp::Cast*` to `IntCast`, with the target type resolved by `UnaryOp::extract_to_int_ty` - tests: 144-pair property tests with a BigInt oracle in `arithmetic_ops`, plus `.move` / `.masm` differential coverage (including the self-cast identity case) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
9c495ac to
bad140b
Compare
vgao1996
commented
May 29, 2026
Comment on lines
+29
to
+31
| //! | ||
| //! The cast micro-op ([`MicroOp::IntCast`]) is also tested here, in the | ||
| //! cast section at the end, reusing the same single-op harness. |
Contributor
Author
There was a problem hiding this comment.
Note: my plan is to rename this file to int_ops.rs before landing, but keeping the name now so it doesn't screw up the review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the family of integer cast micro-ops for the mono-move VM as a single universal
IntCastmicro-op that covers all 12×12(from, to)integer type pairs.The cast is value-preserving: it reproduces the source's mathematical integer value in the target type and aborts iff that value falls outside the target's
[MIN, MAX]range. This matches the existing Move VM'sValue::cast_*semantics exactly (widening, narrowing, and signed↔unsigned).Self-casts (
from == to) are accepted and run as identity — the bytecode verifier admits them (the operand only has to be an integer) and the production VM executes them, so mono-move must not reject them.Changes
IntCastOpoperand +MicroOp::IntCast, withDisplay, gas cost,is_allocating, and re-exports.exec_int_castdoing a uniform per-pair<dst>::try_from(src)dispatch (native↔native via std, native↔256-bit via theint256crate, identity via the blanket impl); a newCastOutOfRangeerror; verifier frame-access checks.UnaryOp::Cast*toIntCast, with the target type resolved by a newUnaryOp::extract_to_int_tyhelper.Testing
runtime/tests/arithmetic_ops.rs): all 144(from, to)pairs, each checked against an independentnum-bigintrange-check oracle — one generated test per pair.int_cast.movecovers every cast category (widen / narrow / signed↔unsigned, both success and out-of-range) for the wide integer types end-to-end against the legacy VM;self_cast.masmpins the self-cast identity behavior.Note: the narrow widths (
u8..u32,i8..i32) can't yet flow through the.movepipeline (the 8-byte slot-align rule), so they're covered by the property tests rather than the differential.movetests.🤖 Generated with Claude Code
Note
Medium Risk
Touches VM execution semantics for all integer cast combinations; risk is mitigated by extensive property and differential tests, but incorrect range handling could diverge from the legacy VM.
Overview
Adds a universal
MicroOp::IntCastpath so mono-move can execute Move integer casts end-to-end:IntCastOpin core (display, gas, non-allocating),exec_int_castin the runtime via nestedtry_fromover all 12×12 type pairs withCastOutOfRange, verifier frame checks (including identity casts), and specializer lowering ofUnaryOp::Cast*throughUnaryOp::extract_to_int_ty.Semantics are value-preserving in the target range (aligned with the legacy VM); out-of-range values abort. Coverage includes 144 proptest pairs in
arithmetic_ops.rsplus differentialint_cast/self_casttestsuite cases against the production VM.Reviewed by Cursor Bugbot for commit bad140b. Bugbot is set up for automated code reviews on this repo. Configure here.