Commit bd3d9caa

bd3d9caa0ac7Merged

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

Description

Promote loop-grown int locals to bigint (legacy pre_detect_bigint port)

bm_bigint_fib and bm_pidigits rely on the legacy analyzer's static bigint promotion: inside a while loop, a local rebuilt by self-referential multiplication (x = a * b or x *= y where an operand flows back from x through local-to-local assignment chains) or by fibonacci-shaped addition (x = a + b where BOTH operands flow back from x; plain i = i + 1 stays int) grows without bound and is typed bigint.

Port that scan to the C analyzer as infer_bigint_loop_locals. It seeds inside infer_write_types' recompute frame (the per-iteration reset would otherwise wipe the promotion), and the existing fixpoint spreads bigint through arithmetic results and assignment chains. ty_unify now resolves int+bigint to bigint — ints flow into bigint slots losslessly via the emitters' sp_bigint_new_int coercion — instead of widening to poly.

The codegen side (sp_bigint_* arithmetic, comparisons, to_s, puts) already existed.

make bench is now fully green: 57 pass, 0 fail, 0 error. make test stays green (845 pass).

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

Details

Commit
bd3d9caa0ac7
Parent
4c5bff524c14

src/analyze_internal.hmodifiedView file

@@ -177,6 +177,7 @@
177177 int infer_string_params(Compiler *c);
178178 int infer_param_types(Compiler *c);
179179 int infer_for_index(Compiler *c);
180+void infer_bigint_loop_locals(Compiler *c);
180181 int first_yield(Compiler *c, int si);
181182 int first_block_call_args(Compiler *c, int si);
182183 int a_proc_params_node(Compiler *c, int create);