Skip to content

VM: a number's % & | ^ << >> ** without a scope - #301

Merged
284km merged 1 commit into
mainfrom
stage10-vm-num-bitops
Nov 25, 2026
Merged

284km merged 1 commit into
mainfrom
stage10-vm-num-bitops

Conversation

@284km

@284km 284km commented Nov 25, 2026

Copy link
Copy Markdown
Owner

On the VM, a Bignum's & or | (and %, ^, <<, >>, **) went through a scope and the parser's EBin instead of being answered where + and < are.

Found while taking apart the benchmarks furthest from the evaluator (note 558). so_meteor_contest was 1,208 G instructions on the VM against the evaluator's 1,134 G. Its search tests and joins boards, which are Bignums: board & cmask == imask, board | mask.

Cause

vm_call answers a send of two numbers and an operator without a scope when vm_num_bin_ok says the evaluator's EBin arm would reach eval_bin_prim with nothing before it taking the call: no TracePoint, refinement, undef or alias of the operator, and no operator of the program's own. It named only + - * / < <= > >=. Two Integers in a Fixnum's range are answered before it (int_fast_op). A Bignum's & went to vm_scoped: a scope from the pool, a fail handler, a region, and the parser's EBin made in it.

For a number on the left, the EBin arm reaches eval_bin_prim the same way for % & | ^ << >> ** as for the operators already named. The arms before it that look at the operator are for Strings, Arrays, Ranges and objects.

Change

vm_num_bin_ok takes % & | ^ << >> ** too. The checks and the call are unchanged.

Numbers

VM instructions, the median of three runs alternating main and this branch:

program main here the evaluator
x = (b & c == 2), a Bignum b, 200,000 turns 9.00 G 8.11 G 8.65 G
x = b | c, the same 9.65 G 8.73 G 9.31 G
so_meteor_contest 1,208.0 G 1,142.0 G 1,134.1 G
so_nsieve_bits, so_pidigits unchanged

Checked

  • Corpus 828 (new): each of the seven operators over Integers, Bignums, Rationals and 0, what each refuses, a program's own Integer#& and a refinement of Integer#|. It matches ruby on both executions.
  • A wider check (Floats too): the VM prints the same as main's VM and as the evaluator.
  • vm_corpus.sh: 956 on the VM, 0 FAIL. run_corpus.sh: 956/956. vm_check.sh: 245/245.

Recorded, not changed: 2.5 ^ 3, 2.5 << 3 and 2.5 >> 3 raise StandardError "mere-ruby: ^ type error" on both executions, as on main. Ruby raises NoMethodError.

Record: loop/2026-11-26-stage10-vm-number-bit-operators.md.

🤖 Generated with Claude Code

vm_num_bin_ok named + - * / < <= > >= only, so a Bignum's & or | went
through vm_scoped and the parser's EBin made in it. For a number on the
left the EBin arm reaches eval_bin_prim the same way for these, so they are
answered in vm_call as the others are. so_meteor_contest on the VM:
1,208.0 -> 1,142.0 G instructions (the evaluator: 1,134.1).

@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 head 69c7c2a7f8981c9ab8fb7ddce96724d79ea0b32e against current main 1a3380b0e5738ee3ed4436c1eb94843e94ac9676. The prospective merge tree equals the reviewed head. No new actionable findings.

The whitelist extension keeps the existing dispatch guards and primitive implementation. Corpus 828 usefully covers Bignum board operations, refusals, an override and a refinement.

Validation on Darwin arm64:

  • Fresh ordinary O2 head build using pinned Mere 9dec2ff687a08433247dbdb7729bc19c8522e538 and mgz 661a01d8bb68f5acd68e3192bd47f081d179c436. For the base comparison, reused the previously built O2 main binary after verifying all tracked files and dependency sources are byte-identical to current main.
  • Full VM corpus: 956/956, no fallback, failure or fallback-list discrepancy. Strict ISeq checks: 245/245.
  • 33 focused corpus files: 264/264 comparisons match Ruby 4.0.10 across base/head, evaluator/VM and hash-index on/off, with GC-tight enabled.
  • 49 additional operator/type and dispatch probes: 392 executions preserve the corresponding base results exactly; eight exception/recovery executions also preserve base results. All 50 added probe programs are accepted by the VM. Existing Ruby discrepancies in the wider probes remain unchanged and are not introduced by this PR.
  • Source checks for duplicate/dead definitions, GC roots, method writes, namespaces and name lengths pass. Emitted C nesting is 155 under the unchanged 1024 limit.

Performance figures were not independently remeasured. Full original upstream-file/resource/platform acceptance is not established by these focused checks. The pre-post check showed the Linux core build and macOS Delegation/URI and Upstream gem tests still running; macOS/reference builds and other macOS jobs were queued, with downstream coverage incomplete. The recorded all-merge hold remains active, so I am not merging or applying the runner-queue exception. Historical failure evidence is preserved.

@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 69c7c2a. No Critical / Major / Minor findings. vm_num_bin_ok now also lets % & | ^ << >> ** take the VM's direct path when both operands are plain numbers and no hook or refinement is active, matching the evaluator's EBin arm. Bignum board & mask no longer goes through a scope and the parser (so_meteor_contest 1,208.0 → 1,142.0 G on the VM). I ran corpus 828 and a probe on the author's build, on the evaluator and MERE_RUBY_VM=1 against ruby 4.0.10: % with negatives and Floats, & / | / ^ with Bignums, shifts by large and negative amounts, ** with negative, Float and huge exponents, ZeroDivisionError, a redefined Integer#& (then restored), and Rationals. All identical. The description has vm_corpus 956 on the VM / 0 FAIL, run_corpus 956/956 and vm_check 245/245. The Float ^ / << / >> exception-class difference is pre-existing on both engines and recorded. git merge-tree against current main (with #300): clean. The bot found nothing actionable. Merging.

@284km
284km merged commit d084304 into main Nov 25, 2026
19 of 20 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