Commit b4125a5b
b4125a5bffa4Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(codegen): delete stmt handler defers receiver compile into matched arms
Closes #518. M.accessor.delete (where the accessor was a
singleton attr_accessor returning a module, post-#511) emitted
a spurious "cannot resolve call to 'adapter' on class" warning.
Other method names (remove, fetch, keys, each, map, ...) didn't
warn — the asymmetry was the smoking gun.
Root: the statement-level delete arm in compile_call_stmt
called compile_expr_gc_rooted(recv) UNCONDITIONALLY before
the per-type dispatch check. For a non-container receiver (the
poly accessor return), the compile_expr work emitted the
recv's obj-method-dispatch probe, fired the
warn_unresolved_call at the bottom of compile_call_expr, and
THEN the type check fell through none of the hash / array
arms. The outer general-dispatch then emitted the correct call
(via the const-fold path in compile_call_expr at line ~11850)
but the warning had already landed.
Fix: inline compile_expr_gc_rooted(recv) into each matched
arm so a non-matching shape never pays the probe cost.
Receiver types that don't match any of the six container arms
(sym_int_hash / sym_str_hash / str_int_hash / str_str_hash /
int_array / str_array) now fall straight through to the
general dispatch at the bottom of compile_call_stmt, where the
const-fold path handles the chain shape correctly without
warning.
Local: 486 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- b4125a5bffa4
- Parent
- 94e1c1419a69
spinel_codegen.rbmodifiedView file
end end # delete # delete on built-in containers. Issue #518: the receiver's # compile_expr_gc_rooted was previously called UNCONDITIONALLY # before the type check, so a non-container receiver (e.g. # `M.adapter.delete` where `M.adapter` is a singleton-accessor # reader returning a Module) emitted the receiver expression # (with its attendant warn_unresolved_call probe) even when # none of the hash / array arms matched. Defer the side-effect # into each arm so non-matching shapes fall through cleanly to # the general dispatch at the bottom of compile_call_stmt. if mname == "delete" if recv >= 0 rt = infer_type(recv) rc = compile_expr_gc_rooted(recv) if rt == "sym_int_hash" emit(" sp_SymIntHash_delete(" + rc + ", " + compile_arg0(nid) + ");") emit(" sp_SymIntHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");") return 1 end if rt == "sym_str_hash" emit(" sp_SymStrHash_delete(" + rc + ", " + compile_arg0(nid) + ");") emit(" sp_SymStrHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");") return 1 end if rt == "str_int_hash" emit(" sp_StrIntHash_delete(" + rc + ", " + compile_str_arg0(nid) + ");") emit(" sp_StrIntHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_str_arg0(nid) + ");") return 1 end if rt == "str_str_hash" emit(" sp_StrStrHash_delete(" + rc + ", " + compile_str_arg0(nid) + ");") emit(" sp_StrStrHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_str_arg0(nid) + ");") return 1 end if rt == "int_array" emit(" sp_IntArray_delete(" + rc + ", " + compile_arg0(nid) + ");") emit(" sp_IntArray_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");") return 1 end if rt == "str_array" emit(" sp_StrArray_delete(" + rc + ", " + compile_arg0(nid) + ");") emit(" sp_StrArray_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");") return 1 end endtest/module_accessor_delete_chain.rbaddedView file
Loading diff…
test/module_accessor_delete_chain.rb.expectedaddedView file
Loading diff…