-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
When fusing 3+ component chains with re-exported resources (e.g., `resource_floats`), the P2 wrapper's canonical `resource.new` returns sequential indices (1, 2, 3...) that are incompatible with wit-bindgen 0.52.0's internal `ResourceTable` slab, which expects 4-byte-aligned memory pointers as handles.
Root Cause
wit-bindgen re-exporting components manage resources via an internal slab in linear memory:
- Handles are heap pointers (4-byte aligned addresses from `Box::into_raw`)
- The slab validates handles with `value & 3 == 0`
- Sequential canonical indices fail this check
Fix
Implement per-component handle tables as i32 arrays in each re-exporter's linear memory. Handles are byte offsets into the array (always 4-byte aligned). The P2 wrapper routes re-exporter resource operations to these custom functions instead of canonical types.
Implementation Plan
See `docs/superpowers/plans/2026-03-29-per-component-handle-tables.md` on branch `feat/per-component-handle-tables`.
Current Progress (on branch)
- Identify re-exporter components in resolver
- Merger $N suffix stripping for resource_rep/new_by_component
- Caller [resource-rep] synthesis for borrow params
- Adapter callee_defines=false no-conversion path
Remaining Work
- Allocate handle table space in merger #70 Allocate handle table space in merger
- Generate handle table wasm functions in fused module #71 Generate handle table wasm functions
- Route re-exporter resource imports to handle table functions (P2 wrapper) #72 Route re-exporter resource imports to handle table functions (P2 wrapper)
- Fix adapter caller_already_converted for re-exporter chains #73 Fix adapter caller_already_converted for re-exporter chains
- Re-enable resource graph definer propagation (targeted) #74 Re-enable resource graph definer propagation
- Promote resource_floats and resource_with_lists to runtime tests #75 Promote resource_floats to runtime test