Commit 1e3e8f15

1e3e8f15f6f1Merged

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

Description

fix(codegen): array literal poly_array push peeks arith arg for bigint

compile_array_literal_as_poly and compile_array_literal_from _ids' poly_array arm called box_value_to_poly(et, val) with et = infer_type(elem). A stale "int" for a CallNode + - * / % ** whose arg side was bigint caused box_value_to_poly to pick the int arm (sp_box_int(val)) — passing the bigint emit through as the int.

Peek operand types before calling box_value_to_poly to upgrade stale "int" to "bigint", so the unbox-then-box path fires.

Promote-mode test count: 548 pass / 48 fail / 22 error -> 548 pass / 49 fail / 21 error. Default raise mode 618 / 0 / 0.

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

Details

Commit
1e3e8f15f6f1
Parent
f45958d5a509

spinel_codegen.rbmodifiedView file

@@ -24669,6 +24669,26 @@
2466924669 emit(" sp_PolyArray_push(" + tmp + ", sp_box_poly_array(" + conv + "));")
2467024670 else
2467124671 val = compile_expr(eid)
24672+ # Stale cache may say "int" for an arith CallNode whose
24673+ # actual emit is bigint. Promote at the box boundary so
24674+ # box_value_to_poly's bigint arm fires (unbox + sp_box_int).
24675+ if et != "bigint" && @nd_type[eid] == "CallNode"
24676+ eml = @nd_name[eid]
24677+ if eml == "+" || eml == "-" || eml == "*" || eml == "/" || eml == "%" || eml == "**"
24678+ er = @nd_receiver[eid]
24679+ if er >= 0 && base_type(infer_type(er)) == "bigint"
24680+ et = "bigint"
24681+ else
24682+ ea = @nd_arguments[eid]
24683+ if ea >= 0
24684+ aa_lit = get_args(ea)
24685+ if aa_lit.length > 0 && base_type(infer_type(aa_lit[0])) == "bigint"
24686+ et = "bigint"
24687+ end
24688+ end
24689+ end
24690+ end
24691+ end
2467224692 emit(" sp_PolyArray_push(" + tmp + ", " + box_value_to_poly(et, val) + ");")
2467324693 end
2467424694 k = k + 1
@@ -24778,6 +24798,26 @@
2477824798 emit(" sp_PolyArray_push(" + tmp + ", sp_box_poly_array(" + conv + "));")
2477924799 else
2478024800 val = compile_expr(elems[k])
24801+ # Stale cache may say "int" for an arith CallNode whose
24802+ # actual emit is bigint. Promote at the box boundary so
24803+ # box_value_to_poly's bigint arm fires.
24804+ if et != "bigint" && @nd_type[elems[k]] == "CallNode"
24805+ ear_mn = @nd_name[elems[k]]
24806+ if ear_mn == "+" || ear_mn == "-" || ear_mn == "*" || ear_mn == "/" || ear_mn == "%" || ear_mn == "**"
24807+ ear_r = @nd_receiver[elems[k]]
24808+ if ear_r >= 0 && base_type(infer_type(ear_r)) == "bigint"
24809+ et = "bigint"
24810+ else
24811+ ear_a = @nd_arguments[elems[k]]
24812+ if ear_a >= 0
24813+ aa_ear = get_args(ear_a)
24814+ if aa_ear.length > 0 && base_type(infer_type(aa_ear[0])) == "bigint"
24815+ et = "bigint"
24816+ end
24817+ end
24818+ end
24819+ end
24820+ end
2478124821 emit(" sp_PolyArray_push(" + tmp + ", " + box_value_to_poly(et, val) + ");")
2478224822 end
2478324823 k = k + 1