Skip to content

feat(p3-async): cross-memory ptr-pair return for stackful lift#150

Merged
avrabe merged 1 commit into
mainfrom
feat/stackful-ptr-pair-return
May 14, 2026
Merged

feat(p3-async): cross-memory ptr-pair return for stackful lift#150
avrabe merged 1 commit into
mainfrom
feat/stackful-ptr-pair-return

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented May 14, 2026

Summary

Closes the v0.8.0-deferred follow-up under SR-32: stackful async lifts
returning a `string` or `list` across different linear memories.
The v0.8.0 emitter errored out clearly on this path (the
"deferred to follow-up" error); this PR routes it through the same
realloc + memory.copy + nested-indirection + retptr-write sequence the
callback emitter already used.

Refactor

Extracted `emit_ptr_pair_result_writeback` as a shared method on
`FactStyleGenerator`. Both the callback emitter's `is_ptr_len_pair`
branch and the stackful emitter's `is_ptr_pair` branch now call this
single method. SR-12 / SR-17 cross-memory copy contract has a single
source of truth.

Stackful emitter's locals count bumped from 8 to 12:

  • 1 step-0.5 scratch
  • 4 ptr-pair scratch (src_ptr, src_len, dst_ptr, byte_count)
  • 6 nested-indirection patching scratch
  • 1 headroom

Tests

  • `stackful_ptr_pair_return_emits_realloc_memcopy_retptr_writes` pins
    the wasm shape:
    • `memory.copy` (0xFC 0x0A)
    • =2 `i32.store` (retptr write: new_ptr at offset 0, len at offset 4)

    • =2 `call` (cabi_realloc + lift)

  • 208 lib pass (207 prior + 1 new)
  • 11 P3 async integration unchanged (callback path untouched in behaviour)

Test plan

  • `cargo test -p meld-core --lib` — 208 pass
  • `cargo test -p meld-core --test p3_async_lowering` — 11 pass
  • `cargo clippy --all-targets -- -D warnings` — clean
  • `cargo fmt --check` — clean
  • CI green on smithy runners

Refs

🤖 Generated with Claude Code

Closes the v0.8.0-deferred follow-up: stackful async lifts returning a
string or list<T> across different linear memories. The emitter previously
errored out clearly on this path; this PR routes it through the same
realloc + memory.copy + nested-indirection + retptr-write sequence the
callback emitter already used.

Refactor:
- Extracted emit_ptr_pair_result_writeback as a shared helper. Both the
  callback emitter's is_ptr_len_pair branch and the stackful emitter's
  is_ptr_pair branch now call this single method, so the SR-12 / SR-17
  cross-memory copy contract has a single source of truth.
- Stackful emitter's locals count bumped from 8 to 12 (1 step-0.5
  scratch + 4 ptr-pair scratch + 6 nested-indirection patching + 1
  headroom).

Tests:
- stackful_ptr_pair_return_emits_realloc_memcopy_retptr_writes pins
  the wasm shape: memory.copy (0xFC 0x0A), >=2 i32.store (retptr write),
  >=2 call (cabi_realloc + lift).
- 208 lib pass (207 prior + 1 new); 11 P3 async integration unchanged.

Refs: SR-32, sub-#94, follow-up from #147 / v0.8.0

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@avrabe avrabe merged commit 37f5b97 into main May 14, 2026
9 checks passed
@avrabe avrabe deleted the feat/stackful-ptr-pair-return branch May 14, 2026 12:54
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