Skip to content

fix: propagate host parameter transitively through direct calls (issu…#22

Merged
arnoox merged 2 commits intomainfrom
fix/issue-19-call-indirect-host-param
Mar 15, 2026
Merged

fix: propagate host parameter transitively through direct calls (issu…#22
arnoox merged 2 commits intomainfrom
fix/issue-19-call-indirect-host-param

Conversation

@arnoox
Copy link
Owner

@arnoox arnoox commented Mar 15, 2026

…e #19 part 2)

Fixes compilation errors when a function A calls function B via IrInstr::Call, and B needs the host parameter. Before the fix:

  1. A's signature didn't have host (no transitive propagation)
  2. emit_call never passed host to the callee

Changes:

  1. assembly.rs: Add fixpoint propagation after enrich_ir_functions. If function A directly calls function B and B.needs_host is true, then A.needs_host = true. This ensures every function in a call chain to an import-calling function gets the host parameter.

  2. backend/mod.rs: Add has_host parameter to emit_call trait method

  3. backend/safe.rs: Update emit_call to insert "host" between Wasm args and resource args (globals, memory, table)

  4. instruction.rs: When handling IrInstr::Call, check if target function needs_host and pass has_host to emit_call (only if caller_has_host AND target_needs_host)

  5. function.rs: Use ir_func.needs_host directly instead of recomputing. The IR builder's fixpoint algorithm is authoritative after the transitive propagation.

Tests:

  • call_import_transitive.wat: regression test with caller → writer → import chain
  • call_import_transitive.rs: integration test verifying the transitive chain works

All existing tests pass, including indirect_call_import tests.

Arnaud Riess and others added 2 commits March 15, 2026 13:09
…#19 part 2)

Fixes compilation errors when a function A calls function B via IrInstr::Call,
and B needs the host parameter. Before the fix:
1. A's signature didn't have host (no transitive propagation)
2. emit_call never passed host to the callee

**Changes:**

1. assembly.rs: Add fixpoint propagation after enrich_ir_functions. If function A
   directly calls function B and B.needs_host is true, then A.needs_host = true.
   This ensures every function in a call chain to an import-calling function gets
   the host parameter.

2. backend/mod.rs: Add has_host parameter to emit_call trait method

3. backend/safe.rs: Update emit_call to insert "host" between Wasm args and
   resource args (globals, memory, table)

4. instruction.rs: When handling IrInstr::Call, check if target function needs_host
   and pass has_host to emit_call (only if caller_has_host AND target_needs_host)

5. function.rs: Use ir_func.needs_host directly instead of recomputing. The IR
   builder's fixpoint algorithm is authoritative after the transitive propagation.

**Tests:**

- call_import_transitive.wat: regression test with caller → writer → import chain
- call_import_transitive.rs: integration test verifying the transitive chain works

All existing tests pass, including indirect_call_import tests.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@arnoox arnoox merged commit 0554022 into main Mar 15, 2026
1 check passed
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