Validation, Traps and Execution Semantics
13.1 Validation
Before execution, every module is validated: type checking of the value stack, control structure correctness, index bounds, and import/export types. Invalid modules raise CompileError.
This allows engines to compile without runtime type checks inside functions.
13.2 Traps
Out-of-bounds memory/table access i32.load beyond the memory size Integer divide by zero / overflow i32.div_s by 0, or INT_MIN / -1 Invalid float→int conversion
i32.trunc_f64_s of NaN/infinity/out of range (use trunc_sat to avoid it) unreachable executed
Rust panic! → abort, C __builtin_trap Indirect call type mismatch / null
call_indirect with the wrong signature Null reference dereference, failed cast
A trap aborts the current Wasm execution and surfaces as an exception (RuntimeError in JS). The instance's memory stays intact (state may be partially updated).
13.3 Determinism
Wasm is deterministic except for: NaN bit patterns, relaxed SIMD results, resource exhaustion (memory growth failure, stack overflow), and threads (scheduling).
Wasm 3.0 defines a deterministic profile (canonical NaNs, deterministic relaxed SIMD), which is important for blockchains and reproducible builds.