Skip to content

VM declaration blocks: read without side effects (#289's review) - #291

Merged
284km merged 1 commit into
mainfrom
stage10-vm-decl-followup
Nov 25, 2026
Merged

284km merged 1 commit into
mainfrom
stage10-vm-decl-followup

Conversation

@284km

@284km 284km commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Two suggestions of #289's review, made here.

Reading a block changed nothing only if it was used. vm_def_block_body read a VM block's program as the parsed form and, while reading, did what vm_define does besides defining: noted the line of the def's end, and marked the def's tree as one a method was defined from. At the new call it read every block of one def, before the proof. A block the proof refused runs, and vm_define does the same again, so nothing differed. But a block that is neither used so nor run, Foo.new { def x; end } with a new that 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_mark does the two things for each def of a parsed form that was used: at the new call once the proof holds, and in make_anon_cls_block once the writer took the def.

The block's source and home. vm_class_def_block now drops pending_srcproc and pending_home before the writer, as native_include_body and register_class_blk0 do.

And an unused binding in the refine form is gone.

Corpus 825 gains Foo.new { def never_made; end } with a new that ignores the block: the method is defined nowhere, as in ruby. Instructions on the VM are #289's (13.01 G for 300,000 Class.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 --both and MERE_RUBY_VM=1 run_corpus.sh --both: 949/949 each, with the hash index on and off.
  • tools/iseq/vm_check.sh: 245/245.
  • Corpus 825 matches ruby on both executions, here and on main.
  • The source gates (dead_defs, dup_defs, gc_roots, meth_writes, name_len, ns_names, bracket_depth, record_hygiene) each exit 0.

🤖 Generated with Claude Code

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 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_at just builds the parsed form, and the def's end line plus the tree's state mark now come from vm_def_block_mark, called only when the shortcut is actually used (the new proof passed, or vm_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_block now drops pending_srcproc and pending_home, like native_include_body and register_class_blk0. The unused ig is 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=1 against ruby 4.0.10: corpus 825 identical; a probe of the TracePoint :return line for a def in Class.new { }, source_location, a new that ignores its block (no method leaks onto Object), Class.new(&pr), and a later proc {} is identical too.
  • The description has corpus --both 949/949 plain and VM, vm_check 245/245 and the 8 gates. git merge-tree against current main: clean. No mere-pr-review-watch inline comments.

Merging.

@284km
284km merged commit ccb6895 into main Nov 25, 2026
5 of 19 checks passed
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