Skip to content

fix: split Phase R own<T> result transfer around post_return#57

Merged
avrabe merged 1 commit intomainfrom
fix/phase-r-ordering
Mar 22, 2026
Merged

fix: split Phase R own<T> result transfer around post_return#57
avrabe merged 1 commit intomainfrom
fix/phase-r-ordering

Conversation

@avrabe
Copy link
Contributor

@avrabe avrabe commented Mar 22, 2026

Summary

Split the own result transfer (Phase R) into two sub-phases with scratch locals,
interleaving post_return correctly:

  1. Phase R-rep: resource.rep(handle) → rep (while callee handles are still alive)
  2. Post_return: drops callee's original handles
  3. Phase R-new: resource.new(rep) → new_handle (mints fresh handles from reps)

Previously Phase R ran as a single block before post_return, overwriting result locals
with converted handles. Post_return then received the caller's new handles instead of
the callee's originals — dropping the wrong ones.

Test plan

  • All 73 wit-bindgen tests pass (no regressions)
  • All 157 unit tests pass
  • cargo +stable clippy --all-targets -- -D warnings clean
  • resources, xcrate, ownership, package_with_version all pass

🤖 Generated with Claude Code

Previously Phase R (resource.rep then resource.new) ran as a single
block before post_return. This overwrote the result locals with
converted handles, so post_return received the caller's new handles
instead of the callee's originals — dropping the wrong handles.

Split into two phases with scratch locals:
  1. Phase R-rep: resource.rep(handle) → rep (before post_return)
  2. Post_return with original handles (drops callee handles)
  3. Phase R-new: resource.new(rep) → new handle (after post_return)

This ensures post_return drops the correct callee handles, and the
caller gets fresh handles minted from the extracted representations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@avrabe avrabe merged commit a5817b0 into main Mar 22, 2026
3 of 4 checks passed
@avrabe avrabe deleted the fix/phase-r-ordering branch March 22, 2026 08:05
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