Skip to content

fix: add ConstExpr::evaluate_scalar and expand spec test coverage#310

Closed
guybedford wants to merge 7 commits intomainfrom
fix/get-function-table-entry
Closed

fix: add ConstExpr::evaluate_scalar and expand spec test coverage#310
guybedford wants to merge 7 commits intomainfrom
fix/get-function-table-entry

Conversation

@guybedford
Copy link
Copy Markdown
Contributor

@guybedford guybedford commented Apr 1, 2026

Adds ConstExpr::evaluate_scalar — a method that statically reduces a const expression to a scalar Value given a caller-supplied global resolver:

pub fn evaluate_scalar<F>(&self, resolve_global: &F) -> Option<Value>
where
    F: Fn(GlobalId) -> Option<ConstExpr>

Handles all three const expression forms:

  • ConstExpr::Value — immediate scalar
  • ConstExpr::Global — resolves via the provided resolver
  • ConstExpr::Extended — evaluates the full i32/i64/f32/f64/v128 stack machine (add/sub/mul and global.get)

Returns None for 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.

…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.
@guybedford guybedford changed the title fix: add Module::get_function_table_entry with ConstExpr::Global offset support fix: add ConstExpr::evaluate_scalar and expand spec test coverage Apr 1, 2026
@guybedford guybedford closed this Apr 1, 2026
@guybedford guybedford deleted the fix/get-function-table-entry branch April 1, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant