Commit cbc0df9f
cbc0df9f832dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
feat(codegen): support Hash#each_value block on poly_poly_hash
The block dispatcher only knew about each / each_pair;
each_value fell through to the unresolved-call warning and
the block body was silently dropped. Adds a direct iteration
path that walks vals[order[i]] and binds the block param
to the value (poly).
Surfaced via optcarrot's PPU init
entries.each_value {|a| a.uniq! {|entry| entry.object_id } },
where entries is a heterogeneous-key heterogeneous-value
hash. Other hash shapes can join the same arm as they surface.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- cbc0df9f832d
- Parent
- d0429b167fe0
spinel_codegen.rbmodifiedView file
@@ -33649,6 +33649,40 @@
3364933649
end3365033650
end3365133651
33652+
# `hash.each_value { |v| ... }` for poly_poly_hash. Other hash33653+
# shapes can be added here once they surface; the underlying33654+
# representation is the same `vals[order[i]]` walk.33655+
if mname == "each_value" && recv >= 0 && @nd_block[nid] >= 033656+
rt_ev = infer_type(recv)33657+
if rt_ev == "poly_poly_hash"33658+
rc_ev = compile_expr_gc_rooted(recv)33659+
bp_ev = get_block_param(nid, 0)33660+
has_bp_ev = 133661+
if bp_ev == ""33662+
has_bp_ev = 033663+
bp_ev = "_v"33664+
end33665+
tmp_ev = new_temp33666+
emit(" for (mrb_int " + tmp_ev + " = 0; " + tmp_ev + " < " + rc_ev + "->len; " + tmp_ev + "++) {")33667+
if has_bp_ev == 133668+
emit(" sp_RbVal lv_" + bp_ev + " = " + rc_ev + "->vals[" + rc_ev + "->order[" + tmp_ev + "]];")33669+
end33670+
@indent = @indent + 133671+
push_scope33672+
if has_bp_ev == 133673+
declare_var(bp_ev, "poly")33674+
end33675+
redo_label_ev = push_redo_label33676+
emit_redo_label(redo_label_ev)33677+
compile_stmts_body(@nd_body[@nd_block[nid]])33678+
pop_redo_label33679+
pop_scope33680+
@indent = @indent - 133681+
emit(" }")33682+
return 133683+
end33684+
end33685+
3365233686
if mname == "each_slice"3365333687
if @nd_block[nid] >= 03365433688
compile_each_slice_block(nid)test/poly_poly_hash_each_value.rbaddedView file
Loading diff…
test/poly_poly_hash_each_value.rb.expectedaddedView file
Loading diff…