Commit 1a76e599

1a76e599863aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): sym_poly_hash.merge(sym_int_hash) positional-arg dispatch

Sam Ruby's #559. Sibling of #551 (which closed the KeywordHashNode arg path). The positional case h.merge(other) where other is a sym_int_hash variable or literal fell through to the unsupported-call warning and silently emit-0.

Mirror the existing sym_str_hash cross-variant arm (#515): when the merge argument's static type is sym_int_hash, route to a new sp_SymPolyHash_merge_int runtime helper that iterates the arg's pairs and boxes each int value via sp_box_int into the result sp_SymPolyHash slot. Helper is emitted as part of emit_sym_int_hash_runtime so it's gated by @needs_sym_int_hash (both typedefs it references are either always-present sp_SymPolyHash or already-gated sp_SymIntHash).

Closes #559

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
1a76e599863a
Parent
2d7eba6fc3dd

spinel_codegen.rbmodifiedView file

@@ -6807,6 +6807,11 @@
68076807 # so the has_key? guard is redundant — drop it for two lookups per
68086808 # element instead of three.
68096809 emit_raw("static sp_SymIntHash*sp_SymArray_tally(sp_IntArray*a){sp_SymIntHash*h=sp_SymIntHash_new();for(mrb_int i=0;i<a->len;i++){sp_sym k=(sp_sym)a->data[a->start+i];sp_SymIntHash_set(h,k,sp_SymIntHash_get(h,k)+1);}return h;}")
6810+ # Cross-variant merge: sym_poly_hash receiver merging in a
6811+ # sym_int_hash arg boxes each int value into sp_RbVal so the
6812+ # result's poly slots are populated correctly. Sibling of
6813+ # sp_SymPolyHash_merge_str (#515). Issue #559.
6814+ emit_raw("static sp_SymPolyHash*sp_SymPolyHash_merge_int(sp_SymPolyHash*a,sp_SymIntHash*b){sp_SymPolyHash*r=sp_SymPolyHash_new();for(mrb_int i=0;i<a->len;i++)sp_SymPolyHash_set(r,a->order[i],sp_SymPolyHash_get(a,a->order[i]));for(mrb_int i=0;i<b->len;i++)sp_SymPolyHash_set(r,b->order[i],sp_box_int(sp_SymIntHash_get(b,b->order[i])));return r;}")
68106815 emit_raw("")
68116816 end
68126817
@@ -17342,6 +17347,12 @@
1734217347 tmp = new_temp
1734317348 emit(" sp_SymPolyHash *" + tmp + " = sp_SymPolyHash_merge_str(" + rc + ", " + compile_expr(aargs[0]) + ");")
1734417349 return tmp
17350+ # Cross-variant: sym_int_hash arg merged into a
17351+ # sym_poly_hash receiver. Issue #559.
17352+ elsif arg_t == "sym_int_hash"
17353+ tmp = new_temp
17354+ emit(" sp_SymPolyHash *" + tmp + " = sp_SymPolyHash_merge_int(" + rc + ", " + compile_expr(aargs[0]) + ");")
17355+ return tmp
1734517356 elsif arg_t == "poly"
1734617357 # Poly-typed local whose runtime value is a sym_poly_hash
1734717358 # (typical when an `is_a?` branch widened the static