Repository navigation
Reject negative Bignum digit radices before division - #276
Conversation
284km
left a comment
There was a problem hiding this comment.
Reviewed exact head 2cc2e1b7e36510b6443002b3956a4dc1f44b083f against freshly fetched current main 5276535f and the PR merge base. I read the complete diff, radix conversion and receiver-sign guards, numeric comparison helpers, regression coverage, validation record, reviews and discussion. No tracked AGENTS.md or CLAUDE.md instructions were found. No actionable issue found.
The Bignum sign/lower-bound check is placed before division and preserves the existing negative-receiver error precedence. Covering Float/Rational conversions alongside direct large negative radices is useful. The disclosed pre-existing 0.digits(huge_positive_base) discrepancy remains outside this fix and is not counted as passing coverage.
Independent Darwin arm64 checks: corpus 1114 (24 output lines) and existing corpus 173 (35 lines) match clean Ruby 4.0.10 exactly in stdout, stderr and exit status in evaluator and VM with MERE_RUBY_GC_TIGHT=1 (four matching executions). Duplicate-definition, dead-definition and diff-whitespace checks pass.
Build reuse: verified all 2,457 tracked regular files against this exact head, with zero differences, plus all three imported mgz modules against pin 661a01d8. Reused O2 binary SHA-256 a2ed8bd522b6ce3c0db007dfd557534474bdfe14feb73b4563d1ca50a5b5966e, copied into the isolated review checkout. This is not a fresh build or a tested current-main integration. I did not independently repeat the full corpus, complete upstream files, Linux execution or resource/performance acceptance; the author's results remain separately attributed.
Hosted build-linux has an executed failure, not just runner queueing: run 45553737085, job 139000718724, fails C API verification with capi/vendor/erb_escape.c is not the tree's file; downstream coverage is incomplete. Other macOS/reference jobs remain queued. No merge: this PR is draft and recorded global merge holds remain active. COMMENT is used because the authenticated account owns this PR.
284km
left a comment
There was a problem hiding this comment.
Reviewed 2cc2e1b. No Critical / Major / Minor findings.
Integer#digitsnow refuses a Bignum radix the same way it refuses a fixnum one: a negative Bignum givesArgumentError: negative radix, before any division, and the existing precedence for a negative receiver (Math::DomainError) is kept.- Ran on the author's build at this head (clean tree, binary newer than every
.merefile), on the evaluator andMERE_RUBY_VM=1, against ruby 4.0.10: corpus 1114 is identical, and so is an extra probe:10.digits(-2**70),10.digits(2**70),(-10).digits(-2**70),(2**80).digits(-2**70),10.digits(-(2**64)), radices 1, 0 and -1, and(2**200).digits(2**100). - The description and loop note have the local results our merge policy asks for: corpus
--bothandMERE_RUBY_VM=1 --both, the source gates, record_hygiene, the bracket gate, and the related upstream selections on both engines. git merge-treeagainst current main: clean. No mere-pr-review-watch inline comments; the bot's review found nothing actionable.
Merging.
Integer#digitsaccepted a negative Bignum radix and returned digits instead of raisingArgumentError. For example, withn = 2**1024 - 1,n.digits(-n)returned[0, -1]on both main engines. The Bignum radix guard now applies the same lower bound as the machine-Integer guard before division.This is one cause from the A1 RED inventory (#243). The unchanged
ruby/test_bignum.rb#test_digits_for_invalid_base_numbersfailure was reproduced against clean Ruby 4.0.10 before editing. Corpus 1114 adds negative large radices, Float/Rational conversions, negative-receiver error precedence, positive large radices, and small controls.A1: reject negative Bignum digit bases
Branch base: current origin/main a63e47c. The cause was recorded before
editing in the A1 numeric reproduction table, following merged inventory
PR #243. Unchanged test_bignum.rb#test_digits_for_invalid_base_numbers
fails at line 840 on both main engines against clean Ruby 4.0.10.
That assertion passes an ordinary negative Bignum radix. A standalone
n.digits(-n), n = 2**1024 - 1, reproduces without any C API extension;
main returns [0, -1] instead of raising ArgumentError.
The radix guard checks machine Integers but accepts every Bignum. It now
checks the Bignum sign and the same lower bound before division. Existing
receiver-sign precedence and positive large radices are preserved.
Corpus 1114 covers normal Bignums, converted Float/Rational negative bases,
negative-receiver error precedence, positive huge bases and small controls.
The O2 binary uses Mere 9dec2ff6 and mgz 661a01d8. Corpus 1114 matches
clean Ruby 4.0.10 on evaluator and VM. Each unchanged upstream file runs
separately with --seed=1 and MERE_RUBY_GC_TIGHT=1. The genuine unchanged
-test-/integer extension is built separately for reference and candidate;
no gems are installed into the reference.
Max RSS from /usr/bin/time -l, in bytes, for these fixed-seed tight-GC runs:
sh run_corpus.sh --both and MERE_RUBY_VM=1 sh run_corpus.sh --both each
pass 897/897 programs with hash indexing ON and OFF. Both commands pass
all source gates and full record_hygiene. The generated-C bracket-depth
gate and an explicit record_hygiene check of this note also pass.
No full unit or Rails component suite was run and no workflow is changed.
A positive-base control exposed a separate existing difference:
0.digits(2**1024) is [] on both main and this candidate, versus [0] on
Ruby. That zero-output case is recorded for a separate cause-specific fix;
it is not counted as passing acceptance here. Nonzero positive-base
controls remain in corpus 1114. No upstream assertion or test is edited.
Final O2 binary SHA-256:
a2ed8bd522b6ce3c0db007dfd557534474bdfe14feb73b4563d1ca50a5b5966e. The code, regression and complete validation record are in the initial push; no record-only push is needed.