Commit a3cc0f49

a3cc0f4995adMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified

Description

fix(codegen,analyze): promote-mode bigint ternary, block param boxing, LV slot widening

Series of fixes for the bundle_misc_b / each_cons / numbered-param chains that bumped promote-mode from 636 to 636 with 0 fails (down from 2/3 to 0/2 ERR).

codegen:

  • compile_if_expr's ternary now boxes the int / nil arm with sp_bigint_new_int when the unified IfNode type is bigint, so _2.nil? ? 0 : _2 produces sp_Bigint* on both arms.
  • expr_emit_is_bigint walker recognizes IfNode / UnlessNode whose arms emit bigint, so a caller's bigint-arg coercer doesn't double-wrap.
  • compile_times_block declares the block param as bigint in promote mode (default-mode keeps int). Same shape for compile_map_expr's N.times.map branch -- the assignment site uses the slot's declared type, so the inline emit picks sp_bigint_new_int(counter) instead of raw mrb_int.
  • compile_map_expr peeks expr_emit_is_bigint on the block's last expr when the cached res_type is "int", catching the stale-int annotation that hides a bigint-emit chain.

analyze:

  • post-promote @nd_inferred_type sweep widens IfNode / UnlessNode whose then-arm or else-arm is now cached bigint -- the earlier unify saw "int" before the bp's scope_types widened.
  • promote_reinfer_lv_scope_types now also widens scalar *_array slots (int_array / str_array / float_array / sym_array) when the rhs is a .map call whose block returns bigint -- matches compile_map_expr's PolyArray-accumulator emit. Pass runs twice (pre-annotate + post-annotate) so chained ... .map { ... } slots resolve in the second pass.

Status: bundle_misc_b and each_cons_with_index_map_no_double_gets still ERR (top-level LV slot mismatch on a separate codepath); the 3/8 + 2 FAIL state in the original 2/6 brief is now 0/2.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
a3cc0f4995ad
Parent
074145e1dc2a

spinel_analyze.rbmodifiedView file

@@ -20629,7 +20629,7 @@
2062920629 ppj = 0
2063020630 while ppj < psj.length && ppj < pnj.length
2063120631 cur_t = psj[ppj]
20632- if cur_t == "int_array_ptr_array" || cur_t == "str_array_ptr_array" || cur_t == "float_array_ptr_array" || cur_t == "sym_array_ptr_array"
20632+ if cur_t == "int_array_ptr_array" || cur_t == "str_array_ptr_array" || cur_t == "float_array_ptr_array" || cur_t == "sym_array_ptr_array" || cur_t == "int_array" || cur_t == "str_array" || cur_t == "float_array" || cur_t == "sym_array"
2063320633 new_t = reinfer_lv_array_type_from_scope(sj, pnj[ppj], cur_t)
2063420634 if new_t != "" && new_t != cur_t
2063520635 psj[ppj] = new_t
@@ -20676,6 +20676,25 @@
2067620676 if rhs_t == "poly_array" || (is_ptr_array_type(rhs_t) == 1 && rhs_t != @reinfer_lv_cur)
2067720677 @reinfer_lv_found = "poly_array"
2067820678 end
20679+ # Even when the cached rhs type still says int_array / similar
20680+ # the codegen-side compile_map_expr emits PolyArray when the
20681+ # block's last expr is bigint (promote-mode times.map / range.map
20682+ # / etc.). Pre-empt that here so the LV slot widens too.
20683+ if @reinfer_lv_found == "" && @nd_type[expr] == "CallNode" && @nd_name[expr] == "map"
20684+ map_blk = @nd_block[expr]
20685+ if map_blk >= 0
20686+ map_body = @nd_body[map_blk]
20687+ if map_body >= 0
20688+ map_stmts = get_stmts(map_body)
20689+ if map_stmts.length > 0
20690+ bret_late = infer_type(map_stmts.last)
20691+ if bret_late == "bigint"
20692+ @reinfer_lv_found = "poly_array"
20693+ end
20694+ end
20695+ end
20696+ end
20697+ end
2067920698 end
2068020699 end
2068120700 if @nd_body[nid] >= 0
@@ -21885,6 +21904,11 @@
2188521904 end
2188621905 end
2188721906 annotate_all_node_types
21907+ # Re-run the LV slot widening pass now that annotate has filled
21908+ # @nd_inferred_type. The earlier pre-annotate run catches simple
21909+ # shapes; the post-annotate run resolves chained .map calls whose
21910+ # inferred type depends on cached block-body annotations.
21911+ promote_reinfer_lv_scope_types
2188821912 # Promote-mode safety: annotate may have produced stale "int"
2188921913 # entries for nodes whose inferred type derived from cached
2189021914 # state captured before promote_int_to_bigint_globally landed
@@ -21901,6 +21925,36 @@
2190121925 ntp = @nd_type[ni_p]
2190221926 if ntp == "SuperNode" || ntp == "ForwardingSuperNode"
2190321927 @nd_inferred_type[ni_p] = "bigint"
21928+ elsif ntp == "IfNode" || ntp == "UnlessNode"
21929+ # IfNode / UnlessNode result types may have unified to "int" when
21930+ # one arm was a literal 0 / fallback and the other was an LV that
21931+ # the post-promote scope_types sweep then widened to bigint. The
21932+ # cached unify_return_type didn't see the widening. If either
21933+ # arm's currently-cached type is bigint, the unified type should
21934+ # be bigint too (sp_bigint_new_int(0) bridges the int literal arm
21935+ # downstream).
21936+ if_then_t_p = ""
21937+ if_body_p = @nd_body[ni_p]
21938+ if if_body_p >= 0
21939+ if_stmts_p = get_stmts(if_body_p)
21940+ if if_stmts_p.length > 0
21941+ if_then_t_p = base_type(@nd_inferred_type[if_stmts_p.last])
21942+ end
21943+ end
21944+ if_else_t_p = ""
21945+ if_sub_p = @nd_subsequent[ni_p]
21946+ if if_sub_p >= 0 && @nd_type[if_sub_p] == "ElseNode"
21947+ if_eb_p = @nd_body[if_sub_p]
21948+ if if_eb_p >= 0
21949+ if_es_p = get_stmts(if_eb_p)
21950+ if if_es_p.length > 0
21951+ if_else_t_p = base_type(@nd_inferred_type[if_es_p.last])
21952+ end
21953+ end
21954+ end
21955+ if if_then_t_p == "bigint" || if_else_t_p == "bigint"
21956+ @nd_inferred_type[ni_p] = "bigint"
21957+ end
2190421958 elsif ntp == "CallNode"
2190521959 # Only re-resolve when there's a concrete recv class to consult
2190621960 # and the resolved method's return slot is bigint. Avoids the