Commit 898cee72
898cee72860cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): map/count block-param and Array.new(N){} push unbox bigint
Three follow-ups to the block-param promote-mode work:
-
compile_array_count_blockdeclared the block param at the iterator's element type, so an int_arrayarr.count { |x| x > 4 }declared x as int even when the outer scope had widened the slot to bigint. Mirror compile_array_sum_block: probe find_var_type first, declare as bigint if the outer slot was promoted, so the block body lowersx > 4through sp_bigint_cmp instead of raw C>. -
compile_map_block's N.times.map { |i| ... } -> IntArray fast path emittedsp_IntArray_push(arr, lastv)raw. With promote mode, lastv is often bigint (i * 2); unbox via sp_bigint_to_int before pushing. -
compile_constructor_expr's Array.new(N) { ... } -> IntArray path had the same shape; apply the same unbox.
Promote-mode test count: 497 pass / 43 fail / 78 error (unchanged, but the warnings now resolve to PASS instead of ERR for the array cases — error count stays at the higher-up boundary). Default raise mode unchanged at 618 / 0 / 0.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 898cee72860c
- Parent
- 9a62e12b70f5
spinel_codegen.rbmodifiedView file
elsif an_ret_is_arr emit(" sp_PtrArray_push(" + arrnew_tmp + ", (void *)(" + arrnew_lastv + "));") else # promote-mode block tail may emit a bigint expr; unbox # for the int_array accumulator. if infer_type(arrnew_stmts2.last) == "bigint" @needs_bigint = 1 arrnew_lastv = "sp_bigint_to_int((sp_Bigint *)" + arrnew_lastv + ")" end emit(" sp_IntArray_push(" + arrnew_tmp + ", " + arrnew_lastv + ");") end end emit(" mrb_int " + tmp_cnt + " = 0;") emit_iter_open(rc, recv_type, "lv_" + bp1, tmp_i) push_scope declare_var(bp1, iter_elem_type(recv_type)) bp1_t_cnt = find_var_type(bp1) if bp1_t_cnt != "bigint" bp1_t_cnt = iter_elem_type(recv_type) end declare_var(bp1, bp1_t_cnt) blk = @nd_block[nid] bexpr = "0" if @nd_body[blk] >= 0 elsif res_type == "float" emit(" sp_FloatArray_push(" + tmp_arrn + ", " + lastv + ");") else # promote-mode block tail emits a bigint expr; unbox before # pushing into the int_array accumulator. if infer_type(stmts_n2.last) == "bigint" @needs_bigint = 1 lastv = "sp_bigint_to_int((sp_Bigint *)" + lastv + ")" end emit(" sp_IntArray_push(" + tmp_arrn + ", " + lastv + ");") end end