fix: add ConstExpr::evaluate_scalar and expand spec test coverage#310
Closed
guybedford wants to merge 7 commits intomainfrom
Closed
fix: add ConstExpr::evaluate_scalar and expand spec test coverage#310guybedford wants to merge 7 commits intomainfrom
guybedford wants to merge 7 commits intomainfrom
Conversation
…offsets Adds a public Module::get_function_table_entry(idx) method that correctly resolves function table lookups when element segment offsets are expressed as ConstExpr::Global (emitted by lld for large position-independent WASM modules with rustc 1.94+) rather than only ConstExpr::Value(I32). Also guards the local-index arithmetic with checked_sub to avoid u32 underflow when a table has multiple active segments at different offsets, fixing a latent bug that would panic in debug mode. Includes three tests covering global-offset round-trips, extended-const round-trips, and multi-segment underflow prevention. Relates to wasm-bindgen/wasm-bindgen#5076.
- Add ConstExpr::evaluate<F> that reduces any const expression to a Value using a caller-supplied global resolver, handling Value, Global, and Extended (i32/i64/f32/f64/v128 arithmetic) uniformly - Simplify get_function_table_entry to use evaluate instead of ad-hoc pattern matching - Remove stale spec-tests.rs guards for proposals whose tests have graduated into the main testsuite (gc, annotations, function-references, tail-call, exception-handling, relaxed-simd, extended-const) - Skip custom/ annotation tests that wasm-tools cannot yet parse - Un-ignore elem.wast and data.wast from build.rs (both pass) - Update testsuite submodule from Oct 2025 to Mar 2026 (+15 tests, 284 total)
…tead get_function_table_entry was the wrong abstraction for walrus — it operated on raw wasm table indices rather than IDs, and encoded wasm-bindgen-specific logic that doesn't belong in a general-purpose IR library. The right primitive is ConstExpr::evaluate_scalar, which lets callers correctly resolve element segment offsets regardless of whether they are expressed as Value, Global, or Extended const expressions. Coverage is provided by the elem.wast spec tests.
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.
Adds
ConstExpr::evaluate_scalar— a method that statically reduces a const expression to a scalarValuegiven a caller-supplied global resolver:Handles all three const expression forms:
ConstExpr::Value— immediate scalarConstExpr::Global— resolves via the provided resolverConstExpr::Extended— evaluates the full i32/i64/f32/f64/v128 stack machine (add/sub/mul and global.get)Returns
Nonefor non-scalar results (reference types, GC types) and for expressions that cannot be fully determined at compile time (e.g. imported globals).Also removes stale
#[ignore]entries and skip guards in the spec test runner for proposals whose tests have since merged into the main testsuite, and updates the testsuite submodule to Mar 2026. Total spec tests go from 269 to 284.