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
if lt == "int_array" @needs_int_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_IntArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" return "(sp_IntArray_push(" + rc + ", " + compile_arg0_as_int(nid) + "), " + rc + ")" end if lt == "float_array" @needs_float_array = 1 rc = compile_expr_gc_rooted(recv) return "(sp_FloatArray_push(" + rc + ", " + compile_arg0(nid) + "), " + rc + ")" return "(sp_FloatArray_push(" + rc + ", " + compile_arg0_as_float(nid) + "), " + rc + ")" end if lt == "str_array" @needs_str_array = 1 return "sp_IntArray_empty(" + rc + ")" end if mname == "include?" return "sp_IntArray_include(" + rc + ", " + compile_arg0(nid) + ")" return "sp_IntArray_include(" + rc + ", " + compile_arg0_as_int(nid) + ")" end if mname == "index" || mname == "find_index" if @nd_arguments[nid] >= 0 # not-found; the call result is statically int?, so `.nil?` # tests fold to a sentinel compare and downstream arithmetic # under a nil-guard skips the box/unbox round-trip. return "sp_IntArray_index_opt(" + rc + ", " + compile_arg0(nid) + ")" return "sp_IntArray_index_opt(" + rc + ", " + compile_arg0_as_int(nid) + ")" end end if mname == "rindex" if @nd_arguments[nid] >= 0 return "sp_IntArray_rindex_opt(" + rc + ", " + compile_arg0(nid) + ")" return "sp_IntArray_rindex_opt(" + rc + ", " + compile_arg0_as_int(nid) + ")" end end if mname == "delete_at" if a0id >= 0 if infer_type(a0id) == "lambda" av = "(mrb_int)" + av elsif infer_type(a0id) == "bigint" @needs_bigint = 1 av = "sp_bigint_to_int((sp_Bigint *)" + av + ")" end end emit(" sp_IntArray_push(" + rc + ", " + av + ");") if rt == "int_array" || rt == "sym_array" rc = compile_expr_gc_rooted(recv) av = compile_arg0(nid) # If pushing a lambda value, cast to mrb_int # If pushing a lambda value, cast to mrb_int. With promote # mode, an int_array.push(bigint_lv) sees a sp_Bigint * arg # against an mrb_int param — unbox. a0id = -1 args_id2 = @nd_arguments[nid] if args_id2 >= 0 if a0id >= 0 if infer_type(a0id) == "lambda" av = "(mrb_int)" + av elsif infer_type(a0id) == "bigint" @needs_bigint = 1 av = "sp_bigint_to_int((sp_Bigint *)" + av + ")" end end emit(" sp_IntArray_push(" + rc + ", " + av + ");")