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 return
2819428194 end
28195+ # Symbol index + poly recv: mirror of the string-idx arm above
28196+ # for Sym*Hash variants. Surfaces in `arr[i][:k] = v` where the
28197+ # outer container is a poly_array of boxed sym_int_hash /
28198+ # sym_poly_hash. Without this arm the assignment silently no-ops
28199+ # (falls through to Array arms that never match).
28200+ if idx_t_poly == "symbol"
28201+ @needs_rb_value = 1
28202+ vbox = val
28203+ if val_t_poly != "poly"
28204+ vbox = box_value_to_poly(val_t_poly, val)
28205+ end
28206+ vbox_tmp = new_temp
28207+ emit(" sp_RbVal " + vbox_tmp + " = " + vbox + ";")
28208+ cur_h = new_temp
28209+ 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+ return
28213+ end
2819528214 # Poly index (sp_RbVal): the key's concrete type isn't known
2819628215 # statically, so the dispatch must read the key's tag at
2819728216 # runtime. Surfaces in `merged[k] = v` inside an `each`
@@ -28498,6 +28517,32 @@
2849828517 ", sp_SymIntHash_get(" + tt + ", " + ti + ") " + op + " (" + val + ")); }")
2849928518 return
2850028519 end
28520+ # Poly recv + symbol idx: surfaces in `arr[i][:k] += v` (and the
28521+ # each-block analog `f[:k] += v` where f is destructured from a
28522+ # poly_array of boxed hashes — block param type is widened to
28523+ # poly). Mirrors the `[]=` arm in compile_bracket_assign. Only
28524+ # SymIntHash is dispatched here; SymPolyHash compound-assign needs
28525+ # 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 = 1
28530+ cur_h = new_temp
28531+ k_t = new_temp
28532+ v_t = new_temp
28533+ h_t = new_temp
28534+ 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+ return
28544+ end
28545+ end
2850128546 end
2850228547
2850328548 # `obj.attr <op>= val` family helper -- builds the