Commit cad6f26b
cad6f26b3bf1Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): IntArray literal unboxes poly element from sibling LV in promote
[x - y, i] where x, y are block-param destructured from a
poly_array source (e.g. .each_cons(2).with_index(N).map { |(x, y), i| ... }) previously emitted sp_IntArray_push(_t9, sp_poly_sub(lv_x, lv_y)) -- sp_RbVal pushed into a mrb_int slot.
Root cause: annotate_all_node_types' walk_and_cache declares only
named block params (RequiredParameterNode), not the inner targets of
a MultiTargetNode destructure. The cached type for x - y falls back
to "int" at analyze time. At codegen emit, find_var_type sees x as
poly (the destructure assigns sp_PolyArray_get into a sp_RbVal slot),
so the - arm picks sp_poly_sub and produces sp_RbVal -- but the
array literal builder still trusts the cached "int" classification
and lowers to IntArray.
Fix: in compile_array_literal_from_ids' IntArray push site, when the
element is an arith CallNode (+ - * / % **) whose LV receiver's
current scope type is poly, treat the element as poly and emit
.v.i unbox before the push. Matches the existing unbox branch
that handles already-poly-typed elements; just refreshes a stale
"int" classification when the receiver-scope evidence contradicts.
Verified: each_cons_with_index_map_no_double_gets passes in promote (was ERR), default 649/0/0 unchanged, optcarrot checksum 59662 unchanged.
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- cad6f26b3bf1
- Parent
- 20cfb9ed546d
spinel_codegen.rbmodifiedView file
end ev = compile_expr(eid) et = infer_type(eid) # Block-param destructure (`|(x, y), i|` from a poly_array source) # leaves x, y uncached by annotate_all_node_types — the cached # type for `x - y` falls back to "int" while the actual emit # picks `sp_poly_sub` (sp_RbVal) because find_var_type at codegen # time sees x as poly. Refresh the cached classification by # checking the receiver's CURRENT scope type. Issue surfaced via # `each_cons_with_index_map_no_double_gets` under promote. if et == "int" && @nd_type[eid] == "CallNode" e_mn = @nd_name[eid] if e_mn == "+" || e_mn == "-" || e_mn == "*" || e_mn == "/" || e_mn == "%" || e_mn == "**" e_rcv = @nd_receiver[eid] if e_rcv >= 0 && @nd_type[e_rcv] == "LocalVariableReadNode" e_rcv_t = find_var_type(@nd_name[e_rcv]) if e_rcv_t == "poly" et = "poly" end end end end # Unbox poly values when pushing into a (concrete) IntArray. # An ArrayNode literal whose elements are poly (e.g. # `[addr]` where addr's recorded type is sp_RbVal) needs the