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:

  1. compile_array_count_block declared the block param at the iterator's element type, so an int_array arr.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 lowers x > 4 through sp_bigint_cmp instead of raw C >.

  2. compile_map_block's N.times.map { |i| ... } -> IntArray fast path emitted sp_IntArray_push(arr, lastv) raw. With promote mode, lastv is often bigint (i * 2); unbox via sp_bigint_to_int before pushing.

  3. 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

@@ -15727,6 +15727,12 @@
1572715727 elsif an_ret_is_arr
1572815728 emit(" sp_PtrArray_push(" + arrnew_tmp + ", (void *)(" + arrnew_lastv + "));")
1572915729 else
15730+ # promote-mode block tail may emit a bigint expr; unbox
15731+ # for the int_array accumulator.
15732+ if infer_type(arrnew_stmts2.last) == "bigint"
15733+ @needs_bigint = 1
15734+ arrnew_lastv = "sp_bigint_to_int((sp_Bigint *)" + arrnew_lastv + ")"
15735+ end
1573015736 emit(" sp_IntArray_push(" + arrnew_tmp + ", " + arrnew_lastv + ");")
1573115737 end
1573215738 end
@@ -32198,7 +32204,11 @@
3219832204 emit(" mrb_int " + tmp_cnt + " = 0;")
3219932205 emit_iter_open(rc, recv_type, "lv_" + bp1, tmp_i)
3220032206 push_scope
32201- declare_var(bp1, iter_elem_type(recv_type))
32207+ bp1_t_cnt = find_var_type(bp1)
32208+ if bp1_t_cnt != "bigint"
32209+ bp1_t_cnt = iter_elem_type(recv_type)
32210+ end
32211+ declare_var(bp1, bp1_t_cnt)
3220232212 blk = @nd_block[nid]
3220332213 bexpr = "0"
3220432214 if @nd_body[blk] >= 0
@@ -35093,6 +35103,12 @@
3509335103 elsif res_type == "float"
3509435104 emit(" sp_FloatArray_push(" + tmp_arrn + ", " + lastv + ");")
3509535105 else
35106+ # promote-mode block tail emits a bigint expr; unbox before
35107+ # pushing into the int_array accumulator.
35108+ if infer_type(stmts_n2.last) == "bigint"
35109+ @needs_bigint = 1
35110+ lastv = "sp_bigint_to_int((sp_Bigint *)" + lastv + ")"
35111+ end
3509635112 emit(" sp_IntArray_push(" + tmp_arrn + ", " + lastv + ");")
3509735113 end
3509835114 end