Commit 0f83cfc1

0f83cfc1d3a8Merged

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

Description

fix(codegen): wire missing Hash dispatch cells (sym_poly_hash.merge kwarg, str_int_hash.dup, str_poly_hash.fetch)

Three sibling cells the prior #510 / #546 dispatch work hadn't covered. Each produced a cannot resolve call to '<m>' on <hash_variant> warning and silently returned 0, driving silent-wrong rendering downstream (Sam's roundhouse blog hit all three via ActionView's link_to / button_to / content_for_get).

sym_poly_hash.merge: add the KeywordHashNode arm so h.merge(c: 3) on a sym_poly_hash receiver builds a fresh sp_SymPolyHash from the kwarg pairs (each value boxed via box_expr_to_poly) and merges. Mirrors the sym_int_hash kwarg path added in #546.

str_int_hash.dup: route to sp_StrIntHash_dup which already exists in the runtime header.

str_poly_hash.fetch: inline as has_key + get with optional default boxed to sp_RbVal so the ternary's two arms agree on type. Also adds the dup arm while in the same block since sp_StrPolyHash_dup is also already in the runtime.

Closes #551

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

Details

Commit
0f83cfc1d3a8
Parent
bc08de1c1b0e

spinel_codegen.rbmodifiedView file

@@ -17147,6 +17147,31 @@
1714717147 args_id = @nd_arguments[nid]
1714817148 if args_id >= 0
1714917149 aargs = get_args(args_id)
17150+ # `h.merge(c: 3)` shorthand: the arg is a KeywordHashNode
17151+ # rather than a regular HashNode. compile_expr on it falls
17152+ # through to 0; build the matching sp_SymPolyHash inline
17153+ # from the kwarg pairs. Boxes each value to sp_RbVal so
17154+ # the poly slot is populated correctly. Mirrors the
17155+ # sym_int_hash kwarg-as-bundle path. Issue #551.
17156+ if aargs.length >= 1 && @nd_type[aargs[0]] == "KeywordHashNode"
17157+ tmp_kw = new_temp
17158+ emit(" sp_SymPolyHash *" + tmp_kw + " = sp_SymPolyHash_new();")
17159+ elems_kw = parse_id_list(@nd_elements[aargs[0]])
17160+ ek_kw = 0
17161+ while ek_kw < elems_kw.length
17162+ if @nd_type[elems_kw[ek_kw]] == "AssocNode"
17163+ key_kw = @nd_key[elems_kw[ek_kw]]
17164+ val_kw = @nd_expression[elems_kw[ek_kw]]
17165+ if key_kw >= 0 && val_kw >= 0 && @nd_type[key_kw] == "SymbolNode"
17166+ emit(" sp_SymPolyHash_set(" + tmp_kw + ", " + compile_expr(key_kw) + ", " + box_expr_to_poly(val_kw) + ");")
17167+ end
17168+ end
17169+ ek_kw = ek_kw + 1
17170+ end
17171+ tmp = new_temp
17172+ emit(" sp_SymPolyHash *" + tmp + " = sp_SymPolyHash_merge(" + rc + ", " + tmp_kw + ");")
17173+ return tmp
17174+ end
1715017175 if aargs.length == 1
1715117176 arg_t = infer_type(aargs[0])
1715217177 if arg_t == "sym_poly_hash"
@@ -17270,6 +17295,26 @@
1727017295 end
1727117296 end
1727217297 end
17298+ # fetch / dup -- sibling of #510. fetch's default is boxed
17299+ # to sp_RbVal so the ternary's two arms agree on type
17300+ # (sp_StrPolyHash_get returns sp_RbVal). Issue #551.
17301+ if mname == "fetch"
17302+ args_id_f = @nd_arguments[nid]
17303+ if args_id_f >= 0
17304+ aargs_f = get_args(args_id_f)
17305+ if aargs_f.length >= 1
17306+ key_f = compile_expr_as_string(aargs_f[0])
17307+ if aargs_f.length >= 2
17308+ defval_f = box_expr_to_poly(aargs_f[1])
17309+ return "(sp_StrPolyHash_has_key(" + rc + ", " + key_f + ") ? sp_StrPolyHash_get(" + rc + ", " + key_f + ") : (" + defval_f + "))"
17310+ end
17311+ return "sp_StrPolyHash_get(" + rc + ", " + key_f + ")"
17312+ end
17313+ end
17314+ end
17315+ if mname == "dup" || mname == "clone"
17316+ return "sp_StrPolyHash_dup(" + rc + ")"
17317+ end
1727317318 end
1727417319 if recv_type == "poly_poly_hash"
1727517320 args_id_ph = @nd_arguments[nid]
@@ -17365,6 +17410,10 @@
1736517410 emit(" sp_StrIntHash *" + tmp + " = sp_StrIntHash_merge(" + rc + ", " + arg + ");")
1736617411 return tmp
1736717412 end
17413+ # dup -- sibling of #510's sym_str_hash.dup. Issue #551.
17414+ if mname == "dup" || mname == "clone"
17415+ return "sp_StrIntHash_dup(" + rc + ")"
17416+ end
1736817417 if mname == "to_a"
1736917418 tt = "tuple:string,int"
1737017419 register_tuple_type(tt)