Commit 0b2973bd
0b2973bdbeacMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
Merge pull request #570 from taakuuyaa/fix-poly-hash-symidx-dispatch
fix(codegen): symbol-idx arm for chained []= / []op= on poly-recv sym hashes
Details
- Commit
- 0b2973bdbeac
- Parent
- c3adf401f22e
- Merge parent
- 48c65a4089f0
spinel_codegen.rbmodifiedView file
@@ -28192,6 +28192,25 @@
2819228192
emit(" else if (" + cur_h + ".cls_id == SP_BUILTIN_STR_POLY_HASH) sp_StrPolyHash_set((sp_StrPolyHash *)" + cur_h + ".v.p, " + idx + ", " + vbox_tmp + ");")2819328193
return2819428194
end28195+
# Symbol index + poly recv: mirror of the string-idx arm above28196+
# for Sym*Hash variants. Surfaces in `arr[i][:k] = v` where the28197+
# outer container is a poly_array of boxed sym_int_hash /28198+
# sym_poly_hash. Without this arm the assignment silently no-ops28199+
# (falls through to Array arms that never match).28200+
if idx_t_poly == "symbol"28201+
@needs_rb_value = 128202+
vbox = val28203+
if val_t_poly != "poly"28204+
vbox = box_value_to_poly(val_t_poly, val)28205+
end28206+
vbox_tmp = new_temp28207+
emit(" sp_RbVal " + vbox_tmp + " = " + vbox + ";")28208+
cur_h = new_temp28209+
emit(" sp_RbVal " + cur_h + " = " + rc + ";")28210+
emit(" if (" + cur_h + ".cls_id == SP_BUILTIN_SYM_INT_HASH) sp_SymIntHash_set((sp_SymIntHash *)" + cur_h + ".v.p, (sp_sym)(" + idx + "), " + vbox_tmp + ".v.i);")28211+
emit(" else if (" + cur_h + ".cls_id == SP_BUILTIN_SYM_POLY_HASH) sp_SymPolyHash_set((sp_SymPolyHash *)" + cur_h + ".v.p, (sp_sym)(" + idx + "), " + vbox_tmp + ");")28212+
return28213+
end2819528214
# Poly index (sp_RbVal): the key's concrete type isn't known2819628215
# statically, so the dispatch must read the key's tag at2819728216
# runtime. Surfaces in `merged[k] = v` inside an `each`@@ -28498,6 +28517,32 @@
2849828517
", sp_SymIntHash_get(" + tt + ", " + ti + ") " + op + " (" + val + ")); }")2849928518
return2850028519
end28520+
# Poly recv + symbol idx: surfaces in `arr[i][:k] += v` (and the28521+
# each-block analog `f[:k] += v` where f is destructured from a28522+
# poly_array of boxed hashes — block param type is widened to28523+
# poly). Mirrors the `[]=` arm in compile_bracket_assign. Only28524+
# SymIntHash is dispatched here; SymPolyHash compound-assign needs28525+
# poly-op semantics and is deferred.28526+
if rt == "poly"28527+
idx_t = infer_type(arg_ids[0])28528+
if idx_t == "symbol"28529+
@needs_rb_value = 128530+
cur_h = new_temp28531+
k_t = new_temp28532+
v_t = new_temp28533+
h_t = new_temp28534+
emit(" {")28535+
emit(" sp_RbVal " + cur_h + " = " + rc + ";")28536+
emit(" sp_sym " + k_t + " = (sp_sym)(" + idx + ");")28537+
emit(" mrb_int " + v_t + " = (" + val + ");")28538+
emit(" if (" + cur_h + ".cls_id == SP_BUILTIN_SYM_INT_HASH) {")28539+
emit(" sp_SymIntHash *" + h_t + " = (sp_SymIntHash *)" + cur_h + ".v.p;")28540+
emit(" sp_SymIntHash_set(" + h_t + ", " + k_t + ", sp_SymIntHash_get(" + h_t + ", " + k_t + ") " + op + " " + v_t + ");")28541+
emit(" }")28542+
emit(" }")28543+
return28544+
end28545+
end2850128546
end2850228547
2850328548
# `obj.attr <op>= val` family helper -- builds thetest/array_of_hash_aset_sym.rbaddedView file
Loading diff…
test/array_of_hash_aset_sym.rb.expectedaddedView file
Loading diff…