Commit cdd2dc95

cdd2dc95fac9Merged

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

Description

fix(codegen): array/hash builtin call sites unbox bigint arg

compile_arg0 returned the raw expression without bigint coercion, so call sites that pass an int-typed arg into a mrb_int-accepting C helper (sp_IntArray_push, sp_IntArray_include, sp_IntArray_index_ opt, sp_IntArray_rindex_opt, ...) emitted the bigint pointer verbatim and -Werror=int-conversion killed the compile.

Route through compile_arg0_as_int (which already unwraps via sp_bigint_to_int) at each int_array / sym_array push/<</include?/ index/rindex site. Also add bigint -> int unbox in compile_call_stmt's push and << statement arms.

Promote-mode test count: 452 pass / 43 fail / 123 error -> 457 pass / 43 fail / 118 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
cdd2dc95fac9
Parent
a931fe6d7309

spinel_codegen.rbmodifiedView file

@@ -15420,12 +15420,12 @@
1542015420 if lt == "int_array"
1542115421 @needs_int_array = 1
1542215422 rc = compile_expr_gc_rooted(recv)
15423- return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
15423+ return "(sp_IntArray_push(" + rc + ", " + compile_arg0_as_int(nid) + "), " + rc + ")"
1542415424 end
1542515425 if lt == "float_array"
1542615426 @needs_float_array = 1
1542715427 rc = compile_expr_gc_rooted(recv)
15428- return "(sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")"
15428+ return "(sp_FloatArray_push(" + rc + ", " + compile_arg0_as_float(nid) + "), " + rc + ")"
1542915429 end
1543015430 if lt == "str_array"
1543115431 @needs_str_array = 1
@@ -17508,7 +17508,7 @@
1750817508 return "sp_IntArray_empty(" + rc + ")"
1750917509 end
1751017510 if mname == "include?"
17511- return "sp_IntArray_include(" + rc + ", " + compile_arg0(nid) + ")"
17511+ return "sp_IntArray_include(" + rc + ", " + compile_arg0_as_int(nid) + ")"
1751217512 end
1751317513 if mname == "index" || mname == "find_index"
1751417514 if @nd_arguments[nid] >= 0
@@ -17517,12 +17517,12 @@
1751717517 # not-found; the call result is statically int?, so `.nil?`
1751817518 # tests fold to a sentinel compare and downstream arithmetic
1751917519 # under a nil-guard skips the box/unbox round-trip.
17520- return "sp_IntArray_index_opt(" + rc + ", " + compile_arg0(nid) + ")"
17520+ return "sp_IntArray_index_opt(" + rc + ", " + compile_arg0_as_int(nid) + ")"
1752117521 end
1752217522 end
1752317523 if mname == "rindex"
1752417524 if @nd_arguments[nid] >= 0
17525- return "sp_IntArray_rindex_opt(" + rc + ", " + compile_arg0(nid) + ")"
17525+ return "sp_IntArray_rindex_opt(" + rc + ", " + compile_arg0_as_int(nid) + ")"
1752617526 end
1752717527 end
1752817528 if mname == "delete_at"
@@ -27354,6 +27354,9 @@
2735427354 if a0id >= 0
2735527355 if infer_type(a0id) == "lambda"
2735627356 av = "(mrb_int)" + av
27357+ elsif infer_type(a0id) == "bigint"
27358+ @needs_bigint = 1
27359+ av = "sp_bigint_to_int((sp_Bigint *)" + av + ")"
2735727360 end
2735827361 end
2735927362 emit(" sp_IntArray_push(" + rc + ", " + av + ");")
@@ -27568,7 +27571,9 @@
2756827571 if rt == "int_array" || rt == "sym_array"
2756927572 rc = compile_expr_gc_rooted(recv)
2757027573 av = compile_arg0(nid)
27571- # If pushing a lambda value, cast to mrb_int
27574+ # If pushing a lambda value, cast to mrb_int. With promote
27575+ # mode, an int_array.push(bigint_lv) sees a sp_Bigint * arg
27576+ # against an mrb_int param — unbox.
2757227577 a0id = -1
2757327578 args_id2 = @nd_arguments[nid]
2757427579 if args_id2 >= 0
@@ -27580,6 +27585,9 @@
2758027585 if a0id >= 0
2758127586 if infer_type(a0id) == "lambda"
2758227587 av = "(mrb_int)" + av
27588+ elsif infer_type(a0id) == "bigint"
27589+ @needs_bigint = 1
27590+ av = "sp_bigint_to_int((sp_Bigint *)" + av + ")"
2758327591 end
2758427592 end
2758527593 emit(" sp_IntArray_push(" + rc + ", " + av + ");")