Repository navigation
RubyVM.stat (two of #243's VM items) - #279
Conversation
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
left a comment
There was a problem hiding this comment.
Reviewed 8b48349. The change reads well. No Critical / Major findings.
RubyVM.statin the prelude matchesvm_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 isArgumentError: unknown key: name; anything else isTypeError: 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_SIZEwould 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
left a comment
There was a problem hiding this comment.
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.
#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.shover 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_statand#test_stat_unknownasked for a method mere-ruby did not have. ruby'svm_statanswers 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.statis 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.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_sizeand#test_relative_stack_sizesask that a fiber recurse less deep under a smallerRUBY_FIBER_VM_STACK_SIZEand deeper under a larger one, and thatRubyVM::DEFAULT_PARAMSreport the fiber sizes. Here a fiber's recursion budget is the thread's (15,000 calls at the default), whatever the variable says, andDEFAULT_PARAMShas 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.rbpasses 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.MERE_RUBY_VM=why: on the VM), the same as ruby; main's build raises NoMethodError on both.🤖 Generated with Claude Code