Commit 5d63d829

5d63d8292198Merged

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

Description

fix(codegen): compile_operator_expr peeks recv arith for bigint detect

compile_operator_expr decided whether to (sp_Bigint *) or sp_bigint_new_int(...) the recv based on infer_type(recv) == "bigint". For a left-associative arith chain (a + b + c) where the inner (a + b) emits bigint but the cache stays "int", the outer wrapped the inner with sp_bigint_new_int — passing a pointer to a function that expects int64.

Peek the recv's arith operands (same shape as compile_bigint_arg, compile_stmt's LVOpWrite, and the IVW rhs-type detection) to upgrade the cached type before deciding the cast.

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

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

Details

Commit
5d63d8292198
Parent
275baa1939ad

spinel_codegen.rbmodifiedView file

@@ -15126,7 +15126,30 @@
1512615126 if lt == "bigint"
1512715127 rc_raw = compile_expr(recv)
1512815128 # Cast away volatile from bigint locals (see compile_bigint_arg).
15129- rc = infer_type(recv) == "bigint" ? "(sp_Bigint *)" + rc_raw : "sp_bigint_new_int(" + rc_raw + ")"
15129+ # `infer_type(recv)` may say "int" for an arith CallNode whose
15130+ # actual emit is bigint (operand-side promote — cache stale).
15131+ # Peek the operands so we don't wrap an already-bigint sub-
15132+ # expression with another sp_bigint_new_int (canonical
15133+ # left-associative `a + b + c` chain shape, three bigint locals).
15134+ recv_t_op = infer_type(recv)
15135+ if recv_t_op != "bigint" && @nd_type[recv] == "CallNode"
15136+ rmn_op = @nd_name[recv]
15137+ if rmn_op == "+" || rmn_op == "-" || rmn_op == "*" || rmn_op == "/" || rmn_op == "%" || rmn_op == "**"
15138+ rrcv_op = @nd_receiver[recv]
15139+ if rrcv_op >= 0 && base_type(infer_type(rrcv_op)) == "bigint"
15140+ recv_t_op = "bigint"
15141+ else
15142+ rargs_op = @nd_arguments[recv]
15143+ if rargs_op >= 0
15144+ ra_op = get_args(rargs_op)
15145+ if ra_op.length > 0 && base_type(infer_type(ra_op[0])) == "bigint"
15146+ recv_t_op = "bigint"
15147+ end
15148+ end
15149+ end
15150+ end
15151+ end
15152+ rc = recv_t_op == "bigint" ? "(sp_Bigint *)" + rc_raw : "sp_bigint_new_int(" + rc_raw + ")"
1513015153 arg = compile_bigint_arg(nid)
1513115154 if mname == "+"
1513215155 return "sp_bigint_add(" + rc + ", " + arg + ")"