Commit 0f605284

0f605284523bMerged

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

Description

fix(codegen): poly_poly_hash gains fetch + dup dispatch arms

Sam Ruby's #560. When two writers to a module-level ivar use incompatible key types (int-defaulted param vs symbol literal), spinel widens the storage to poly_poly_hash. The read side previously had only [] / has_key? / length / empty? / any? / keys / values arms; fetch / dup fell through to the unresolved-call warning and emitted 0.

Add fetch (inlined has_key + get with the default boxed to sp_RbVal) and dup (sp_PolyPolyHash_dup, already in the runtime). Sibling of the per-variant arms #551 added for str_poly_hash and sym_poly_hash. Hash#delete on poly_poly_hash is intentionally not wired here -- the runtime needs a corresponding sp_PolyPolyHash_delete helper that handles the occ-array slot bookkeeping, and the reported ActionView shape (content_for_get) uses fetch only.

Closes #560

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

Details

Commit
0f605284523b
Parent
1a76e599863a

spinel_codegen.rbmodifiedView file

@@ -17514,6 +17514,27 @@
1751417514 @needs_rb_value = 1
1751517515 return "sp_PolyPolyHash_values(" + rc + ")"
1751617516 end
17517+ # fetch / dup / delete -- sibling of the per-variant arms
17518+ # for sym/str_poly_hash. Issue #560. fetch inlines as
17519+ # has_key + get with the default boxed to sp_RbVal so the
17520+ # ternary's two arms agree on type.
17521+ if mname == "fetch"
17522+ args_id_f = @nd_arguments[nid]
17523+ if args_id_f >= 0
17524+ aargs_f = get_args(args_id_f)
17525+ if aargs_f.length >= 1
17526+ key_f = box_expr_to_poly(aargs_f[0])
17527+ if aargs_f.length >= 2
17528+ defval_f = box_expr_to_poly(aargs_f[1])
17529+ return "(sp_PolyPolyHash_has_key(" + rc + ", " + key_f + ") ? sp_PolyPolyHash_get(" + rc + ", " + key_f + ") : (" + defval_f + "))"
17530+ end
17531+ return "sp_PolyPolyHash_get(" + rc + ", " + key_f + ")"
17532+ end
17533+ end
17534+ end
17535+ if mname == "dup" || mname == "clone"
17536+ return "sp_PolyPolyHash_dup(" + rc + ")"
17537+ end
1751717538 end
1751817539 if recv_type == "str_int_hash"
1751917540 if mname == "[]"