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

@@ -33557,8 +33557,26 @@
3355733557 end
3355833558 else
3355933559 # promote-mode block tail returning bigint into IntArray;
33560- # unbox before pushing.
33561- if infer_type(stmts_r2.last) == "bigint"
33560+ # unbox before pushing. The plain infer_type doesn't catch the
33561+ # arith-callnode-with-bigint-arg shape (cache stale at "int"), so
33562+ # also peek the operator's arg side.
33563+ tail_t_rng = infer_type(stmts_r2.last)
33564+ if tail_t_rng != "bigint" && @nd_type[stmts_r2.last] == "CallNode"
33565+ tn_mn = @nd_name[stmts_r2.last]
33566+ if tn_mn == "+" || tn_mn == "-" || tn_mn == "*" || tn_mn == "/" || tn_mn == "%" || tn_mn == "**"
33567+ tn_recv = @nd_receiver[stmts_r2.last]
33568+ tn_args_id = @nd_arguments[stmts_r2.last]
33569+ if tn_recv >= 0 && base_type(infer_type(tn_recv)) == "bigint"
33570+ tail_t_rng = "bigint"
33571+ elsif tn_args_id >= 0
33572+ tn_aa = get_args(tn_args_id)
33573+ if tn_aa.length > 0 && base_type(infer_type(tn_aa[0])) == "bigint"
33574+ tail_t_rng = "bigint"
33575+ end
33576+ end
33577+ end
33578+ end
33579+ if tail_t_rng == "bigint"
3356233580 @needs_bigint = 1
3356333581 lastv_r = "sp_bigint_to_int((sp_Bigint *)" + lastv_r + ")"
3356433582 end
@@ -33917,6 +33935,10 @@
3391733935 elsif block_ret_p == "float"
3391833936 emit(" sp_FloatArray_push(" + tmp_arr + ", " + lastv_p + ");")
3391933937 elsif block_ret_p == "int" || block_ret_p == "bool"
33938+ if infer_type(stmts_p2.last) == "bigint"
33939+ @needs_bigint = 1
33940+ lastv_p = "sp_bigint_to_int((sp_Bigint *)" + lastv_p + ")"
33941+ end
3392033942 emit(" sp_IntArray_push(" + tmp_arr + ", " + lastv_p + ");")
3392133943 else
3392233944 emit(" sp_PolyArray_push(" + tmp_arr + ", " + box_value_to_poly(block_ret_p, lastv_p) + ");")