Skip to content

feat: implement params-ptr lowering for >16 flat params#65

Merged
avrabe merged 1 commit intomainfrom
feat/params-ptr-lowering
Mar 22, 2026
Merged

feat: implement params-ptr lowering for >16 flat params#65
avrabe merged 1 commit intomainfrom
feat/params-ptr-lowering

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented Mar 22, 2026

Summary

Implement params-ptr lowering for functions with more than 16 flat parameters
(canonical ABI MAX_FLAT_PARAMS). The adapter allocates a buffer in the callee's
memory, bulk-copies params, fixes up pointer pairs and resource handles.

  • New generate_params_ptr_adapter in fact.rs (170 lines)
  • Parser: 7 new methods for params-area layout computation
  • Resolver: 6 new fields on AdapterRequirements
  • resource_aggregates promoted from fuse-only to runtime (43/45 → 44/45)

Test plan

  • All 78 tests pass (73 wit-bindgen + 5 osxcar)
  • resource_aggregates passes at runtime
  • clippy clean, no regressions

🤖 Generated with Claude Code

When a component function has more than MAX_FLAT_PARAMS (16) flat
parameters, the canonical ABI uses the params-ptr calling convention:
both caller and callee use a single i32 pointer to a buffer in linear
memory instead of flat params on the stack.

In multi-memory mode, the adapter must:
1. Allocate a buffer in the callee's memory via cabi_realloc
2. Bulk copy the params buffer from caller to callee memory
3. Fix up (ptr, len) pointer pairs inside the buffer by copying their
   pointed-to data (e.g., list elements) across memories
4. Convert borrow<T> resource handles inside the buffer to
   representations via [resource-rep] calls
5. Convert borrow<T> resource handles inside list element data via
   per-element fixup loops

Changes:
- parser.rs: Add total_flat_params(), params_area_byte_size(),
  params_area_max_align(), pointer_pair_params_byte_offsets(),
  params_area_slots(), resource_params_area_positions(), and
  collect_resource_byte_positions() methods
- resolver.rs: Add params_area_byte_size, params_area_max_align,
  params_area_pointer_pair_offsets, params_area_copy_layouts,
  params_area_slots, and params_area_resource_positions fields to
  AdapterRequirements; populate in both resolution paths
- adapter/mod.rs: Add ParamsAreaResourceFixup struct and
  params_area_borrow_fixups field to AdapterOptions
- adapter/fact.rs: Add generate_params_ptr_adapter() method with full
  buffer copy, pointer pair fixup, borrow handle conversion, and
  inner list resource fixup; detect params-ptr case in
  generate_memory_copy_adapter() dispatch

Promotes resource_aggregates fixture from fuse_only to runtime test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit 57ccf62 into main Mar 22, 2026
@avrabe avrabe deleted the feat/params-ptr-lowering branch March 22, 2026 15:56
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