Skip to content

RubyVM.stat (two of #243's VM items) - #279

Merged
284km merged 1 commit into
mainfrom
stage10-rubyvm-stat
Nov 25, 2026
Merged

284km merged 1 commit into
mainfrom
stage10-rubyvm-stat

Conversation

@284km

@284km 284km commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

#243 recorded ten unit-test items of test/ruby as the VM stream's: three of test_iseq, two of test_rubyvm, two of test_stack and three of test_vm_dump. On main 0cd831f, with ruby 4.0.10, unittest/vm_compare.sh over test_rubyvm.rb and test_stack.rb finds the four of those two files RED on both executions, the same on each: none is the VM's alone.

RubyVM.stat

TestRubyVM#test_stat and #test_stat_unknown asked for a method mere-ruby did not have. ruby's vm_stat answers with five counters of its own: its inline constant caches (constant_cache_invalidations, constant_cache_misses), its class variable state (global_cvar_state) and its object shapes (next_shape_id, shape_cache_size).

  • RubyVM.stat is a new Hash of the five; RubyVM.stat(hash) fills the Hash given and returns it, a frozen one raising FrozenError; RubyVM.stat(:name) is one counter.
  • An unknown name is an ArgumentError, "unknown key: name"; any other argument a TypeError, "non-hash or symbol given"; a second argument is the arity's ArgumentError (0..1). The arity is -1, as ruby's.

This interpreter keeps none of the five, and counts 0 for each. The values are each implementation's own, so corpus 824 compares the names, the class of each value, the Hash filled in place and the errors.

Recorded: a Fiber's stack size

TestStack#test_vm_stack_size and #test_relative_stack_sizes ask that a fiber recurse less deep under a smaller RUBY_FIBER_VM_STACK_SIZE and deeper under a larger one, and that RubyVM::DEFAULT_PARAMS report the fiber sizes. Here a fiber's recursion budget is the thread's (15,000 calls at the default), whatever the variable says, and DEFAULT_PARAMS has the two thread sizes only. ruby's default fiber VM stack is 128 KB against the thread's 1 MB, so following it would make every fiber recurse about an eighth as deep as it does here now: a change to what programs can do, left for a round of its own.

Numbers

Corpus 824 matches ruby on both executions, and runs on the VM; on main it fails on both (NoMethodError). test_rubyvm.rb passes on both executions: 3 tests, 0 failures, 0 errors, and the one omission ruby makes too (test_keep_script_lines, under Prism). An uncaught error's backtrace is ruby's, in 'RubyVM.stat' on top.

Checked

Against ruby 4.0.10 (tools/ref_ruby.sh), built with Mere 9dec2ff6, on main 0cd831f:

  • run_corpus.sh --both: 917/917 match ruby, with the hash index on and off.
  • MERE_RUBY_VM=1 run_corpus.sh --both: 917/917 match ruby, with the hash index on and off.
  • The source gates: dead_defs, dup_defs, gc_roots, meth_writes, name_len, ns_names, bracket_depth and record_hygiene each exit 0 (every top-level function called; no name defined twice in one chain; every Val-valued global map accounted for; 111 method writes through the setters; 3,855 name-length guards; ns_names' 16 and 28 names; bracket depth ok; 343 records clean).
  • corpus 824 on the VM (MERE_RUBY_VM=why: on the VM), the same as ruby; main's build raises NoMethodError on both.
  • test/ruby/test_rubyvm.rb on each execution: 3 tests, 0 failures, 0 errors, 1 omission (ruby's own).

🤖 Generated with Claude Code

ruby's vm_stat: five counters (its inline constant caches, class variable
state and object shapes), as a new Hash, into a Hash given, or one by name;
an unknown name is an ArgumentError, any other argument a TypeError. This
interpreter keeps none of them and counts 0 for each.

TestRubyVM#test_stat and #test_stat_unknown (#243's VM items) pass on both
executions. Corpus 824. The two of test_stack (a fiber's stack size) are
recorded.

@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 8b48349. The change reads well. No Critical / Major findings.

  • RubyVM.stat in the prelude matches vm_stat's interface: no argument gives a new Hash of the five counters; a Hash (subclasses too) is filled in place and returned; a frozen Hash raises FrozenError from the write; a Symbol gives one counter; an unknown key is ArgumentError: unknown key: name; anything else is TypeError: non-hash or symbol given; arity -1 with the 0..1 message. Counting 0 for counters this interpreter does not keep is reasonable, and corpus 824 compares only what is comparable (names, value classes, identity of the filled Hash, the errors).
  • Recording the fiber stack size as its own round makes sense: following RUBY_FIBER_VM_STACK_SIZE would cut fiber recursion depth to about an eighth.

Minor (local results): the description lists run_corpus.sh --both 917/917 and corpus 824 on the VM, but not the full MERE_RUBY_VM=1 sh run_corpus.sh --both and not the source gates (dead_defs, dup_defs, gc_roots, meth_writes, name_len, ns_names, bracket_depth, record_hygiene). Our merge policy asks for both. A prelude change cannot break the VM corpus in an obvious way, but please run them and add the numbers. Then this can be merged.

git merge-tree against current main: clean. No mere-pr-review-watch inline comments.

@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.

The Minor from the last review is resolved: the description now has MERE_RUBY_VM=1 run_corpus.sh --both 917/917 and all eight source gates at exit 0. No open findings, the head is unchanged (8b48349), git merge-tree against current main is clean, and there are no mere-pr-review-watch inline comments. Merging.

@284km
284km merged commit d586947 into main Nov 25, 2026
11 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