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
if lt == "bigint" rc_raw = compile_expr(recv) # Cast away volatile from bigint locals (see compile_bigint_arg). rc = infer_type(recv) == "bigint" ? "(sp_Bigint *)" + rc_raw : "sp_bigint_new_int(" + rc_raw + ")" # `infer_type(recv)` may say "int" for an arith CallNode whose # actual emit is bigint (operand-side promote — cache stale). # Peek the operands so we don't wrap an already-bigint sub- # expression with another sp_bigint_new_int (canonical # left-associative `a + b + c` chain shape, three bigint locals). recv_t_op = infer_type(recv) if recv_t_op != "bigint" && @nd_type[recv] == "CallNode" rmn_op = @nd_name[recv] if rmn_op == "+" || rmn_op == "-" || rmn_op == "*" || rmn_op == "/" || rmn_op == "%" || rmn_op == "**" rrcv_op = @nd_receiver[recv] if rrcv_op >= 0 && base_type(infer_type(rrcv_op)) == "bigint" recv_t_op = "bigint" else rargs_op = @nd_arguments[recv] if rargs_op >= 0 ra_op = get_args(rargs_op) if ra_op.length > 0 && base_type(infer_type(ra_op[0])) == "bigint" recv_t_op = "bigint" end end end end end rc = recv_t_op == "bigint" ? "(sp_Bigint *)" + rc_raw : "sp_bigint_new_int(" + rc_raw + ")" arg = compile_bigint_arg(nid) if mname == "+" return "sp_bigint_add(" + rc + ", " + arg + ")"