Repository navigation
VM declaration blocks: read without side effects (#289's review) - #291
Merged
Merged
Conversation
vm_def_block_body no longer notes the def's end line or marks its tree
while reading; vm_def_block_mark does, once the parsed form is used. A
block that is neither used so nor run (Foo.new { def x; end } with a new
that ignores it) leaves its tree to be given back. vm_class_def_block drops
pending_srcproc and pending_home as the other declaration paths do; an
unused binding is gone. Corpus 825 gains the ignored block.
284km
commented
Nov 25, 2026
284km
left a comment
Owner
Author
There was a problem hiding this comment.
Reviewed 51022ab. Both Suggestions from #289's review are addressed. No Critical / Major / Minor findings.
- Reading a VM block no longer changes anything:
vm_def_atjust builds the parsed form, and the def'sendline plus the tree's state mark now come fromvm_def_block_mark, called only when the shortcut is actually used (thenewproof passed, orvm_class_def_block's writer defined the method). A block that is neither used nor run (Foo.new { def x; end }where Foo ignores the block) leaves its tree to be released. vm_class_def_blocknow dropspending_srcprocandpending_home, likenative_include_bodyandregister_class_blk0. The unusedigis gone.- Ran on the author's build (built from this PR's code before it was rebased onto main a6f72af; the PR's own diff is unchanged) on the evaluator and
MERE_RUBY_VM=1against ruby 4.0.10: corpus 825 identical; a probe of the TracePoint:returnline for a def inClass.new { },source_location, anewthat ignores its block (no method leaks onto Object),Class.new(&pr), and a laterproc {}is identical too. - The description has corpus
--both949/949 plain and VM, vm_check 245/245 and the 8 gates.git merge-treeagainst current main: clean. No mere-pr-review-watch inline comments.
Merging.
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.
Two suggestions of #289's review, made here.
Reading a block changed nothing only if it was used.
vm_def_block_bodyread a VM block's program as the parsed form and, while reading, did whatvm_definedoes besides defining: noted the line of the def'send, and marked the def's tree as one a method was defined from. At thenewcall it read every block of one def, before the proof. A block the proof refused runs, andvm_definedoes the same again, so nothing differed. But a block that is neither used so nor run,Foo.new { def x; end }with anewthat ignores its block, left its tree marked, and a marked tree is not given back when the run ends. Reading is now only reading;vm_def_block_markdoes the two things for each def of a parsed form that was used: at thenewcall once the proof holds, and inmake_anon_cls_blockonce the writer took the def.The block's source and home.
vm_class_def_blocknow dropspending_srcprocandpending_homebefore the writer, asnative_include_bodyandregister_class_blk0do.And an unused binding in the
refineform is gone.Corpus 825 gains
Foo.new { def never_made; end }with anewthat ignores the block: the method is defined nowhere, as in ruby. Instructions on the VM are #289's (13.01 G for 300,000Class.new { def }, 28.6 G for the leak test's loop).Checked
Against ruby 4.0.10, built with Mere 9dec2ff6, on main 34ba966:
run_corpus.sh --bothandMERE_RUBY_VM=1 run_corpus.sh --both: 949/949 each, with the hash index on and off.tools/iseq/vm_check.sh: 245/245.🤖 Generated with Claude Code