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
args_id = @nd_arguments[nid] if args_id >= 0 aargs = get_args(args_id) # `h.merge(c: 3)` shorthand: the arg is a KeywordHashNode # rather than a regular HashNode. compile_expr on it falls # through to 0; build the matching sp_SymPolyHash inline # from the kwarg pairs. Boxes each value to sp_RbVal so # the poly slot is populated correctly. Mirrors the # sym_int_hash kwarg-as-bundle path. Issue #551. if aargs.length >= 1 && @nd_type[aargs[0]] == "KeywordHashNode" tmp_kw = new_temp emit(" sp_SymPolyHash *" + tmp_kw + " = sp_SymPolyHash_new();") elems_kw = parse_id_list(@nd_elements[aargs[0]]) ek_kw = 0 while ek_kw < elems_kw.length if @nd_type[elems_kw[ek_kw]] == "AssocNode" key_kw = @nd_key[elems_kw[ek_kw]] val_kw = @nd_expression[elems_kw[ek_kw]] if key_kw >= 0 && val_kw >= 0 && @nd_type[key_kw] == "SymbolNode" emit(" sp_SymPolyHash_set(" + tmp_kw + ", " + compile_expr(key_kw) + ", " + box_expr_to_poly(val_kw) + ");") end end ek_kw = ek_kw + 1 end tmp = new_temp emit(" sp_SymPolyHash *" + tmp + " = sp_SymPolyHash_merge(" + rc + ", " + tmp_kw + ");") return tmp end if aargs.length == 1 arg_t = infer_type(aargs[0]) if arg_t == "sym_poly_hash" end end end # fetch / dup -- sibling of #510. fetch's default is boxed # to sp_RbVal so the ternary's two arms agree on type # (sp_StrPolyHash_get returns sp_RbVal). Issue #551. if mname == "fetch" args_id_f = @nd_arguments[nid] if args_id_f >= 0 aargs_f = get_args(args_id_f) if aargs_f.length >= 1 key_f = compile_expr_as_string(aargs_f[0]) if aargs_f.length >= 2 defval_f = box_expr_to_poly(aargs_f[1]) return "(sp_StrPolyHash_has_key(" + rc + ", " + key_f + ") ? sp_StrPolyHash_get(" + rc + ", " + key_f + ") : (" + defval_f + "))" end return "sp_StrPolyHash_get(" + rc + ", " + key_f + ")" end end end if mname == "dup" || mname == "clone" return "sp_StrPolyHash_dup(" + rc + ")" end end if recv_type == "poly_poly_hash" args_id_ph = @nd_arguments[nid] emit(" sp_StrIntHash *" + tmp + " = sp_StrIntHash_merge(" + rc + ", " + arg + ");") return tmp end # dup -- sibling of #510's sym_str_hash.dup. Issue #551. if mname == "dup" || mname == "clone" return "sp_StrIntHash_dup(" + rc + ")" end if mname == "to_a" tt = "tuple:string,int" register_tuple_type(tt)test/hash_dispatch_missing_cells.rbaddedView file
Loading diff…
test/hash_dispatch_missing_cells.rb.expectedaddedView file
Loading diff…