Skip to content

capi_check runs on the ISeq VM with --vm; a rescue clause clears C's errinfo there - #313

Merged
284km merged 1 commit into
mainfrom
capi-vm-check
Nov 26, 2026
Merged

284km merged 1 commit into
mainfrom
capi-vm-check

Conversation

@284km

@284km 284km commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

Before the VM becomes the default, C extensions need to be shown to work on it. This PR does two things:

  1. Makes capi_check actually able to run on the ISeq VM.
  2. Fixes the one contract that failed there.

Earlier "capi_check under the VM" results were the evaluator's. tools/capi_check.py removes all of the caller's MERE_RUBY_* variables before every run, so MERE_RUBY_VM=1 python3 tools/capi_check.py ... ran the evaluator. Any record that reported capi_check results under MERE_RUBY_VM=1 was reporting the evaluator. That includes the notes in #278, #284, #286 and #292.

Running the six contract scripts on the VM directly, on main 85da98f:

  • ensure, typeddata, loader, numeric and fiber pass.
  • api.rb stops at line 643. Inside a Ruby rescue, a C method's rb_errinfo() must answer nil. On the VM it answered the ArgumentError that an earlier rb_protect had left.

Changes

  • vm_checkmatch (main.mere): when a rescue clause is taken (checkmatch type 3 answers true), it clears C's errinfo with capi_errinfo_clear.
    • This matches the evaluator's run_rescues, and CRuby's clearing of ec->errinfo on entering a rescue.
    • A clause that does not match clears nothing, as on the evaluator.
    • Without a C extension loaded, the extra cost is one mr_capi_booted test.
  • capi_check.py --vm: every mere-ruby run gets MERE_RUBY_VM=report. That covers the contracts, stress and the six negative controls.
    • If the report names the contract script itself, the VM did not take it and the evaluator ran it, so that run fails.
    • A negative control that "fails" in that way does not count as failing.
    • "The native compiler declined" is not treated as a refusal, because the Ruby compiler then compiles the script for the VM.
    • The summary line says mere-ruby (VM).
  • CI: capi_check runs a second time with --vm in both the macOS and Linux steps.
  • capi/README.md describes --vm and why the environment variable does nothing.
  • The record is in loop/2026-11-26-capi-vm-check.md.

Checked

Branch 8008397 (main 85da98f + this change), mere 9dec2ff6, reference ruby 4.0.10.

  • capi_check.py (evaluator): ensure 58, typeddata 115, loader 49 (48 + mere-ruby's own one), numeric 13, fiber 16, api 405.
    • Both sides agree, also under collection stress.
    • All six negative controls fail.
  • capi_check.py --vm: the same counts with mere-ruby's side on the VM, also under stress.
    • The six negative controls fail with the same messages as on the evaluator:

      control where it fails
      no-dmark typeddata.rb:21
      no-dfree "unreachable C cycles are reclaimed"
      no-ensure "normal cleanup once"
      no-switch "the calls in progress are out of step"
      no-fileprobe "one constructor, then Init"
      no-builtin api.rb:35
  • The check notices a script the VM refuses. For one run, BEGIN { } was put at the top of numeric.rb.
    • --vm then failed with "the VM did not take numeric.rb, the evaluator ran it", for the contracts and for stress.
    • The summary said "numeric: a side did not finish its contracts".
  • api.rb on the VM by hand: main's build stops at line 643; this build gives 405 passed.
  • Corpus: run_corpus.sh --both passes the gates, then 961/961 with the hash index on and off. MERE_RUBY_VM=1 run_corpus.sh --both gives 961/961.
  • capi_spec_check: 2420 of 2602, the recorded count.
  • capi_mkmf_check: passes.
  • capi_gem_check: seventeen gems give the same output on both sides.
  • headers_check: passes.

Not done

  • capi_check on the VM was not run on Linux locally, because that needs a reference ruby built for Linux. CI's Linux job runs it.
  • capi_spec_check, capi_mkmf_check and capi_gem_check still run only the evaluator. Whether each of them needs --vm is a separate question.

🤖 Generated with Claude Code

…errinfo there

capi_check started every run with the caller's MERE_RUBY_* removed, so
`MERE_RUBY_VM=1 capi_check.py` ran the evaluator. --vm now gives each
mere-ruby run MERE_RUBY_VM=report and fails a run whose contract script
the VM did not take. CI runs capi_check again with --vm on macOS and Linux.

On the VM, api.rb stopped at the rb_errinfo contract inside a rescue:
vm_checkmatch now clears C's errinfo when a rescue clause is taken, as
the evaluator's run_rescues does.

@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 8008397. No Critical / Major / Minor findings.

  • The VM fix is one place: when vm_checkmatch takes a rescue clause (ty == 3 and a match), it clears what C's rb_errinfo answers, as the evaluator's run_rescues does. That was the only contract the VM stopped at (api.rb around line 643). With it, the rest of api.rb passes on the VM (api 405).
  • tools/capi_check.py --vm makes the VM explicit. Every mere-ruby run (contracts, stress, negative controls) gets MERE_RUBY_VM=report. A contract script the VM did not take itself (so the evaluator ran it) fails the check; "the native compiler declined" is correctly not counted as a refusal. So a pass under --vm is the VM's. A negative control must also fail on the VM, not by being refused.
  • The description says up front that earlier "capi_check on the VM" numbers (#278, #284, #286, #292) were the evaluator's, because the tool clears MERE_RUBY_*. Good to have that on record.
  • CI: one extra capi_check.py ... --vm line in the macOS and the Linux C API steps. This touches .github/workflows/ci.yml, so it goes to the owner before merge.
  • The author's results: capi_check 6/6 on the evaluator and on the VM, the same under stress, the 6 negative controls failing on both; corpus --both 961/961 and MERE_RUBY_VM=1 961/961; spec, mkmf, the 17 gems and headers. Linux --vm will be seen in CI.
  • git merge-tree against main: clean. No mere-pr-review-watch inline comments.

@284km
284km merged commit 555d7c7 into main Nov 26, 2026
18 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