-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Problem
The inline optimization pass produces invalid WASM that fails validation.
Reproduction
# Test with simple file
python3 /tmp/test_idempotence.py /tmp/test_inline.wasm --passes inlineResult:
- Input: 83 bytes, ✅ valid
- Output: 108 bytes, ❌ INVALID
- Error:
type mismatch: values remaining on stack at end of block (at offset 0x59)
Test Case
(module
(func $add_two (param $x i32) (result i32)
local.get $x
i32.const 2
i32.add
)
(func $main (param $a i32) (result i32)
local.get $a
call $add_two ;; This gets inlined incorrectly
call $add_two
)
(export "main" (func $main))
)Root Cause
The inline pass (from PR #29) has a bug in stack management:
- ✅ Correctly identifies inlining opportunities
- ✅ Substitutes function body at call site
- ❌ Leaves extra values on stack or corrupts stack discipline
Impact
Severity: HIGH
- Affects loom.wasm self-optimization
- Produces invalid WASM that cannot be executed
- All other 9 optimization passes work correctly
Systematic Test Results
| Pass | Valid Output | Idempotent |
|---|---|---|
| inline | ❌ | ✅ |
| precompute | ✅ | ✅ |
| constant-folding | ✅ | ✅ |
| cse | ✅ | ✅ |
| advanced | ✅ | ✅ |
| branches | ✅ | ✅ |
| dce | ✅ | ✅ |
| merge-blocks | ✅ | ✅ |
| vacuum | ✅ | ✅ |
| simplify-locals | ✅ | ✅ |
See Issue #30 for full test methodology.
Recommendation
Immediate action: Disable inline pass by default until fixed.
// In optimize_module, comment out inline pass:
// loom_core::optimize::inline_functions(&mut module)?;Related
- Issue LOOM cannot optimize itself (self-optimization fails) #30: Component model optimization (where this was discovered)
- PR feat: enable function inlining in optimization pipeline #29: Function inlining implementation
- Commit 99d19b0: feat: enable function inlining in optimization pipeline
Metadata
Metadata
Assignees
Labels
No labels