Commit 275baa19

275baa1939adMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): bigint_arg + lvop + range each peek arith arg side

Three sites still made the cached-int mistake on operator expressions whose recv stayed cached as int but whose arg side was bigint:

  • compile_bigint_arg: wrapping the arg of an outer sp_bigint_* call with another sp_bigint_new_int when the inner emit already produced bigint (total = total + i * j).
  • compile_stmt's LV op-write bigint arm: same at = infer_type staleness, double-wrapping the arith rhs.
  • compile_each_block's range arm: a (lv_lo..lv_hi).each where lo/hi are promoted bigint locals fed unwrapped into the for (mrb_int _t = lv_lo; _t <= lv_hi; ...) int loop — unbox via sp_bigint_to_int.

Add the same operand-side peek shape used elsewhere.

Promote-mode test count: 534 pass / 50 fail / 34 error -> 534 pass / 51 fail / 33 error. Default raise mode 618 / 0 / 0; optcarrot checksum 59662.

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

Details

Commit
275baa1939ad
Parent
d0921ca3cee5

spinel_codegen.rbmodifiedView file

@@ -15025,6 +15025,27 @@
1502515025 arg_ids = get_args(args_id)
1502615026 if arg_ids.length > 0
1502715027 at = infer_type(arg_ids[0])
15028+ # The cache may say "int" even though the arg emits bigint
15029+ # (arith CallNode with bigint operand). Peek operands so we
15030+ # don't wrap an already-bigint expression with sp_bigint_new
15031+ # _int.
15032+ if at != "bigint" && @nd_type[arg_ids[0]] == "CallNode"
15033+ ar_mn_bg = @nd_name[arg_ids[0]]
15034+ if ar_mn_bg == "+" || ar_mn_bg == "-" || ar_mn_bg == "*" || ar_mn_bg == "/" || ar_mn_bg == "%" || ar_mn_bg == "**"
15035+ ar_recv_bg = @nd_receiver[arg_ids[0]]
15036+ if ar_recv_bg >= 0 && base_type(infer_type(ar_recv_bg)) == "bigint"
15037+ at = "bigint"
15038+ else
15039+ ar_args_bg = @nd_arguments[arg_ids[0]]
15040+ if ar_args_bg >= 0
15041+ aa_bg = get_args(ar_args_bg)
15042+ if aa_bg.length > 0 && base_type(infer_type(aa_bg[0])) == "bigint"
15043+ at = "bigint"
15044+ end
15045+ end
15046+ end
15047+ end
15048+ end
1502815049 val = compile_expr(arg_ids[0])
1502915050 if at == "bigint"
1503015051 # Cast away volatile (locals in setjmp-bearing functions are
@@ -25388,6 +25409,27 @@
2538825409 end
2538925410 if vt == "bigint"
2539025411 at = infer_type(@nd_expression[nid])
25412+ # The cache may say "int" even though the rhs emits bigint
25413+ # (arith CallNode with bigint operand, or any of the rhs
25414+ # shapes mirrored by compile_stmt's IVW arm). Peek the
25415+ # operator's operands to upgrade the cached type.
25416+ if at != "bigint" && @nd_expression[nid] >= 0 && @nd_type[@nd_expression[nid]] == "CallNode"
25417+ rhs_mn_lv = @nd_name[@nd_expression[nid]]
25418+ if rhs_mn_lv == "+" || rhs_mn_lv == "-" || rhs_mn_lv == "*" || rhs_mn_lv == "/" || rhs_mn_lv == "%" || rhs_mn_lv == "**"
25419+ rhs_recv_lv = @nd_receiver[@nd_expression[nid]]
25420+ if rhs_recv_lv >= 0 && base_type(infer_type(rhs_recv_lv)) == "bigint"
25421+ at = "bigint"
25422+ else
25423+ rhs_args_lv = @nd_arguments[@nd_expression[nid]]
25424+ if rhs_args_lv >= 0
25425+ ra_lv = get_args(rhs_args_lv)
25426+ if ra_lv.length > 0 && base_type(infer_type(ra_lv[0])) == "bigint"
25427+ at = "bigint"
25428+ end
25429+ end
25430+ end
25431+ end
25432+ end
2539125433 # Cast away volatile from bigint locals (see compile_bigint_arg).
2539225434 barg = at == "bigint" ? "(sp_Bigint *)" + val : "sp_bigint_new_int(" + val + ")"
2539325435 vref_b = "(sp_Bigint *)" + vref
@@ -32131,6 +32173,14 @@
3213132173 cmp = range_excl_end(lit_range) == 1 ? "<" : "<="
3213232174 lo = compile_expr(@nd_left[lit_range])
3213332175 hi = compile_expr(@nd_right[lit_range])
32176+ if infer_type(@nd_left[lit_range]) == "bigint"
32177+ @needs_bigint = 1
32178+ lo = "sp_bigint_to_int((sp_Bigint *)" + lo + ")"
32179+ end
32180+ if infer_type(@nd_right[lit_range]) == "bigint"
32181+ @needs_bigint = 1
32182+ hi = "sp_bigint_to_int((sp_Bigint *)" + hi + ")"
32183+ end
3213432184 if bp_t_re == "bigint"
3213532185 @needs_bigint = 1
3213632186 rtmp_re = new_temp