Use explicit Transfer for tail Resume handlers#357
Open
proboscis wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
do.pybytecode-based tail-Resumerewrite entirelyTransferin tail positionDOEFF032to the linter to flagreturn (yield Resume(k, ...))and suggestyield Transfer(k, ...)Resumesemantics explicit: handlers unwind only after the remainder continuation completesWhy
The new weakref probe looked like finished handler generators were being retained by the VM, but stepping the runtime showed that is not what is happening.
Resumeis non-terminal: the handler does not finish per iteration. It suspends on the remainder continuation and only receives a value back when that continuation completes. Existing public API behavior already depends on this (resume_value = yield Resume(...)post-processing).That means looped tail code such as
return (yield Resume(k, payload))will intentionally stack suspended handler frames until the whole run completes. The safe fix is to use explicitTransferfor true tail-position handlers rather than trying to rewrite VM ownership or add bytecode-dependent magic.Evidence
Acceptance checks for
vm-memory-leakwere re-run on this branch:tests/test_vm_memory_leak.pywith explicitTransfer4 passed in 4.01stests/test_try_finally_in_do.py8 passed in 0.05stests/public_api/test_types_001_handler_protocol.py::TestHP03PostProcess2 passed in 0.04scargo testinpackages/doeff-linter300 passedRuntime probe demonstrating actual
Resumesemantics:This shows the earlier handler frames stay suspended because the continuation has not completed yet, not because finished generators are leaked by stale VM references.
Tests
/home/kento/.orch/worktrees/vm-memory-leak/23039e_codex_20260321-015536/.venv/bin/python -m pytest tests/test_vm_memory_leak.py -q -s/home/kento/.orch/worktrees/vm-memory-leak/23039e_codex_20260321-015536/.venv/bin/python -m pytest tests/test_try_finally_in_do.py -q/home/kento/.orch/worktrees/vm-memory-leak/23039e_codex_20260321-015536/.venv/bin/python -m pytest tests/public_api/test_types_001_handler_protocol.py::TestHP03PostProcess -qcargo testinpackages/doeff-linterRefs:
vm-memory-leak