Commit d0921ca3
d0921ca3cee5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): map block tail bigint detection peeks arith arg side
compile_map_expr's range arm and poly_array arm checked
infer_type(block_tail) == "bigint" to decide whether to unbox
into an IntArray push. The cache returns stale "int" for an
arith CallNode whose recv is the still-int outer block param but
whose arg is the bigint inner block param (e.g.
[10,20,30,40].map { |a| (0...8).map { |j| a + j } } — outer
a is mrb_int, inner j is bigint, a + j emits sp_bigint_add
but infer_type stays "int"). Peek the operator's arg side too.
Promote-mode test count: 532 pass / 50 fail / 36 error -> 534 pass / 50 fail / 34 error. Default raise mode 618 / 0 / 0; optcarrot checksum 59662.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- d0921ca3cee5
- Parent
- 656878a4c1ed
spinel_codegen.rbmodifiedView file
end else # promote-mode block tail returning bigint into IntArray; # unbox before pushing. if infer_type(stmts_r2.last) == "bigint" # unbox before pushing. The plain infer_type doesn't catch the # arith-callnode-with-bigint-arg shape (cache stale at "int"), so # also peek the operator's arg side. tail_t_rng = infer_type(stmts_r2.last) if tail_t_rng != "bigint" && @nd_type[stmts_r2.last] == "CallNode" tn_mn = @nd_name[stmts_r2.last] if tn_mn == "+" || tn_mn == "-" || tn_mn == "*" || tn_mn == "/" || tn_mn == "%" || tn_mn == "**" tn_recv = @nd_receiver[stmts_r2.last] tn_args_id = @nd_arguments[stmts_r2.last] if tn_recv >= 0 && base_type(infer_type(tn_recv)) == "bigint" tail_t_rng = "bigint" elsif tn_args_id >= 0 tn_aa = get_args(tn_args_id) if tn_aa.length > 0 && base_type(infer_type(tn_aa[0])) == "bigint" tail_t_rng = "bigint" end end end end if tail_t_rng == "bigint" @needs_bigint = 1 lastv_r = "sp_bigint_to_int((sp_Bigint *)" + lastv_r + ")" end elsif block_ret_p == "float" emit(" sp_FloatArray_push(" + tmp_arr + ", " + lastv_p + ");") elsif block_ret_p == "int" || block_ret_p == "bool" if infer_type(stmts_p2.last) == "bigint" @needs_bigint = 1 lastv_p = "sp_bigint_to_int((sp_Bigint *)" + lastv_p + ")" end emit(" sp_IntArray_push(" + tmp_arr + ", " + lastv_p + ");") else emit(" sp_PolyArray_push(" + tmp_arr + ", " + box_value_to_poly(block_ret_p, lastv_p) + ");")