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

@@ -30273,8 +30273,32 @@
3027330273 return "int"
3027430274 end
3027530275 if mname == "each_slice" || mname == "each_cons"
30276- # Block param is sub-array of recv's element type — keep recv's
30277- # array type (slice of int_array is still int_array).
30276+ # Multi-param block on each_cons(k) / each_slice(k) — when the
30277+ # req-param count matches the literal k, codegen destructures
30278+ # the pair into scalar element-type slots. Mirror that here
30279+ # so the block body's type inference sees the right shape.
30280+ n_ec_bp = -1
30281+ ec_args_bp = @nd_arguments[call_nid]
30282+ if ec_args_bp >= 0
30283+ ec_alist_bp = get_args(ec_args_bp)
30284+ if ec_alist_bp.length > 0 && @nd_type[ec_alist_bp[0]] == "IntegerNode"
30285+ n_ec_bp = @nd_value[ec_alist_bp[0]].to_i
30286+ end
30287+ end
30288+ blk_ec_bp = @nd_block[call_nid]
30289+ if blk_ec_bp >= 0 && n_ec_bp > 0
30290+ ec_bp_node = @nd_parameters[blk_ec_bp]
30291+ if ec_bp_node >= 0
30292+ ec_inner_pn = @nd_parameters[ec_bp_node]
30293+ if ec_inner_pn >= 0
30294+ ec_reqs_bp = parse_id_list(@nd_requireds[ec_inner_pn])
30295+ if ec_reqs_bp.length == n_ec_bp && ec_reqs_bp.length >= 2 && @nd_type[ec_reqs_bp[0]] != "MultiTargetNode"
30296+ return elem_type_of_array(recv_t)
30297+ end
30298+ end
30299+ end
30300+ end
30301+ # Default: bind the whole pair as a sub-array of recv's element type.
3027830302 return recv_t
3027930303 end
3028030304 if mname == "chunk_while" || mname == "slice_when"