Commit 39e260af

39e260af01b3Merged

Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified

Description

analyze,codegen: Hash#delete returns the deleted value

h.delete(k) previously emitted (sp_<Variant>_delete(h, k), 0) (or sp_box_nil() for poly variants), dropping the value and always returning 0 / nil. CRuby returns the value that was mapped to k (or nil / block result when the key was absent).

Rewrite the per-variant delete arms as a GCC compound expression that:

  • pre-evaluates the key once into a temp,
  • looks up via has_key + get (default 0 / NULL / sp_box_nil when absent, matching each variant's missing-default),
  • runs the delete (no return-value change to the runtime helper),
  • yields the captured value.

Sym_int / sym_str / sym_poly variants covered here. Block-form delete (h.delete(k) { default }) and str-keyed / int-keyed variants left for follow-up — they share the compile_body_into plumbing already added for fetch's block form.

Analyzer side: extend the mname == "delete" return-type arm (previously string-only) to cover the 6 sym-keyed and str-keyed hash variants so downstream consumers see the right slot type.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
39e260af01b3
Parent
24ec1cf637a4

spinel_analyze.rbmodifiedView file

@@ -4721,6 +4721,15 @@
47214721 if rt == "string"
47224722 return "string"
47234723 end
4724+ if rt == "sym_int_hash" || rt == "str_int_hash"
4725+ return "int"
4726+ end
4727+ if rt == "sym_str_hash" || rt == "str_str_hash" || rt == "int_str_hash"
4728+ return "string"
4729+ end
4730+ if rt == "sym_poly_hash" || rt == "str_poly_hash" || rt == "poly_poly_hash"
4731+ return "poly"
4732+ end
47244733 end
47254734 end
47264735 if mname == "squeeze"