Commit f92cfe82
f92cfe82e654Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix(analyze,codegen): promote-mode int/bigint compatibility in array element infer
Three layered fixes for (0...3).map { |i| [i, i * 10] } under promote:
analyze:
- post-promote @nd_inferred_type sweep now also widens an arith /
bitop CallNode whose recv is bigint (no obj_X required). The
earlier sweep only re-resolved obj-recv methods, leaving
i * 10cached at the pre-promote "int".
codegen:
- The codegen-side infer_array_elem_type_from_ids mirror gets the same int<>bigint tolerance as the analyzer's: when one element surfaces as bigint (LV with widened scope_type) and a sibling surfaces as int (stale-int cache on arith), don't widen to poly_array. The compile_array_literal_from_ids int_array arm already unboxes per-element bigints via sp_bigint_to_int.
array #take / #drop:
- Inline loop count param goes through compile_arg0_as_int so a promote-mode bigint count operand is unboxed before being used as the mrb_int loop bound.
destructure for .each { |(a, b)| ... } on int_array_ptr_array:
- Numbered-param slots
_1,_2, ... now declare as bigint in promote mode and emit sp_bigint_new_int boxing per element so the block body's arithmetic dispatches via sp_bigint_* consistently with the slot's scope type.
Picks up ptr_array, ptr_array_null_guards, map_range_recv_array_block, each_cons_with_index_map_chain_fusion. Three failures left: gc_root_ptr_array_literal (GC pressure under bigint), bundle_misc_b (_2.nil? ternary), each_cons_with_index_map_no_double_gets (top-level LV slot reinfer).
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- f92cfe82e654
- Parent
- 99731a4b9a34
spinel_analyze.rbmodifiedView file
@@ -2558,7 +2558,16 @@
25582558
while k < elems.length25592559
et2 = infer_type(elems[k])25602560
if et2 != et2561-
return "poly_array"2561+
# Under promote mode, int / bigint are numerically interchangeable2562+
# (the literal codegen unboxes via sp_bigint_to_int for IntArray2563+
# storage). Stale-int cache on an arith CallNode whose actual2564+
# value is bigint causes a spurious mismatch here -- recognize2565+
# int<>bigint as compatible.2566+
if @int_overflow_mode == "promote" && (et == "int" || et == "bigint") && (et2 == "int" || et2 == "bigint")2567+
# compatible; continue2568+
else2569+
return "poly_array"2570+
end25622571
end25632572
k = k + 125642573
end@@ -21909,6 +21918,14 @@
2190921918
@nd_inferred_type[ni_p] = "bigint"2191021919
end2191121920
end21921+
# Arith/bitop on bigint recv produces bigint. The cache was21922+
# filled before promote_int_to_bigint_globally widened the21923+
# recv's scope_type, so the call's cached return is stale "int".21924+
elsif rcv_t_pn == "bigint"21925+
mn_pn = @nd_name[ni_p]21926+
if mn_pn == "+" || mn_pn == "-" || mn_pn == "*" || mn_pn == "/" || mn_pn == "%" || mn_pn == "**" || mn_pn == "&" || mn_pn == "|" || mn_pn == "^" || mn_pn == "<<" || mn_pn == ">>" || mn_pn == "~" || mn_pn == "-@"21927+
@nd_inferred_type[ni_p] = "bigint"21928+
end2191221929
end2191321930
end2191421931
endspinel_codegen.rbmodifiedView file
Loading diff…