Commit 9089156c

9089156cb709Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 5 files · +2 added · ~3 modified

Description

parse,codegen: keep integer literals wider than int64 as arbitrary-precision bigints

An integer literal that does not fit in signed 64 bits (100000000000000000000) was saturated to LLONG_MAX at parse time, so it printed as 9223372036854775807 instead of its real value. In CRuby such a literal is a Bignum in every overflow mode -- this is exact literal text, not a runtime overflow, so it is independent of --int-overflow.

The parser now keeps the exact decimal text in a bigval field when the value overflows int64 (via Prism's pm_integer_string). An IntegerNode with bigval infers as TY_BIGINT and lowers to sp_bigint_new_str("...", 10) rather than a saturated mrb_int literal; the int-constant folder declines such nodes. Negative and underscored forms work; arithmetic flows through the existing bigint paths (x + 1, x * 3).

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
9089156cb709
Parent
102e2bb52557

src/analyze_infer.cmodifiedView file

@@ -2414,7 +2414,7 @@
24142414 if (!ty) return TY_UNKNOWN;
24152415 NodeKind nk = nt_kind(nt, id);
24162416
2417- if (nk == NK_IntegerNode) return TY_INT;
2417+ if (nk == NK_IntegerNode) return nt_str(nt, id, "bigval") ? TY_BIGINT : TY_INT;
24182418 if (nk == NK_FloatNode) return TY_FLOAT;
24192419 if (nk == NK_ImaginaryNode) return TY_COMPLEX;
24202420 if (nk == NK_RationalNode) return TY_RATIONAL;