Commit 86d91371
86d91371b008Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
codegen,analyze: Enumerable#each_entry / #reverse_each + each_cons destructure
Three adjacent dispatch fixes:
-
each_entry is just an alias for each — extend the existing each-block dispatch arm.
-
reverse_each on typed arrays walks the receiver backwards with the same shape as the each-block path; reuses sp_get / sp_length so str_array / float_array / sym_array work via the same emitter.
-
each_cons(k) with a multi-param block (|a, b| against k==2) now destructures the pair into per-element scalar locals instead of binding the whole pair to lv_a and leaving lv_b uninitialised. Mirrors the each_cons.map fusion path's multi-param handling.
Fixes #934 Fixes #937 Fixes #938
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 86d91371b008
- Parent
- 57a5b80b06d0
spinel_analyze.rbmodifiedView file
return "int" end if mname == "each_slice" || mname == "each_cons" # Block param is sub-array of recv's element type — keep recv's # array type (slice of int_array is still int_array). # Multi-param block on each_cons(k) / each_slice(k) — when the # req-param count matches the literal k, codegen destructures # the pair into scalar element-type slots. Mirror that here # so the block body's type inference sees the right shape. n_ec_bp = -1 ec_args_bp = @nd_arguments[call_nid] if ec_args_bp >= 0 ec_alist_bp = get_args(ec_args_bp) if ec_alist_bp.length > 0 && @nd_type[ec_alist_bp[0]] == "IntegerNode" n_ec_bp = @nd_value[ec_alist_bp[0]].to_i end end blk_ec_bp = @nd_block[call_nid] if blk_ec_bp >= 0 && n_ec_bp > 0 ec_bp_node = @nd_parameters[blk_ec_bp] if ec_bp_node >= 0 ec_inner_pn = @nd_parameters[ec_bp_node] if ec_inner_pn >= 0 ec_reqs_bp = parse_id_list(@nd_requireds[ec_inner_pn]) if ec_reqs_bp.length == n_ec_bp && ec_reqs_bp.length >= 2 && @nd_type[ec_reqs_bp[0]] != "MultiTargetNode" return elem_type_of_array(recv_t) end end end end # Default: bind the whole pair as a sub-array of recv's element type. return recv_t end if mname == "chunk_while" || mname == "slice_when"spinel_codegen.rbmodifiedView file
Loading diff…
test/each_cons_block_destructure.rbaddedView file
Loading diff…
test/each_entry_reverse_each.rbaddedView file
Loading diff…