Skip to content

feat: per-component resource handle tables for 3-component chains #69

@avrabe

Description

@avrabe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions