Skip to content

feat: per-component handle table allocation and function generation#79

Merged
avrabe merged 1 commit intomainfrom
feat/per-component-handle-tables-v2
Apr 2, 2026
Merged

feat: per-component handle table allocation and function generation#79
avrabe merged 1 commit intomainfrom
feat/per-component-handle-tables-v2

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented Apr 2, 2026

Summary

  • Identify re-exporter components in the resolver by scanning adapter sites for callee_defines_resource=false
  • Allocate handle table space in merger: grow each re-exporter's memory by 1 page, place a 256-entry i32 table at the start of the new page
  • Add a mutable i32 global per re-exporter for the next-allocation pointer (starts at base+4, skipping slot 0)
  • Generate three wasm functions per re-exporter: ht_new (store rep, return aligned handle), ht_rep (load rep), ht_drop (zero out entry)
  • All load/store instructions use the correct multi-memory index
  • Handle addresses are always 4-byte aligned, satisfying wit-bindgen's ResourceTable alignment check

Implements tasks 1-3 of epic #69. Functions are generated but not yet wired — tasks 4-6 (routing, adapter fixes, graph propagation) will follow.

Part of #69, closes #70, closes #71.

Test plan

  • 276 tests pass, 0 failures (166 unit + 110 integration/runtime)
  • No regressions — handle table code only activates for re-exporter components
  • Verified compilation with multi-memory MemArg support

🤖 Generated with Claude Code

, #71)

Implement the first three tasks of epic #69:

1. Identify re-exporter components in the resolver by scanning adapter
   sites for callee_defines_resource=false operations.

2. Allocate handle table space in the merger: for each re-exporter,
   grow its memory by 1 page and place a 256-entry i32 handle table
   at the start of the new page. Add a mutable global for the
   next-allocation pointer (starts at base+4 to avoid handle=0).

3. Generate three wasm functions per re-exporter:
   - ht_new: store rep at next_ptr, return aligned handle, advance by 4
   - ht_rep: i32.load rep from handle address
   - ht_drop: i32.store 0 at handle address (mark as freed)

All functions use the correct multi-memory index for load/store.
Handle addresses are always 4-byte aligned, satisfying wit-bindgen's
ResourceTable alignment check (value & 3 == 0).

Part of #69.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit 478aff9 into main Apr 2, 2026
4 checks passed
@avrabe avrabe deleted the feat/per-component-handle-tables-v2 branch April 2, 2026 00:38
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.

Generate handle table wasm functions in fused module Allocate handle table space in merger

1 participant