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

@@ -24135,33 +24135,40 @@
2413524135 end
2413624136 end
2413724137
24138- # delete
24138+ # delete on built-in containers. Issue #518: the receiver's
24139+ # compile_expr_gc_rooted was previously called UNCONDITIONALLY
24140+ # before the type check, so a non-container receiver (e.g.
24141+ # `M.adapter.delete` where `M.adapter` is a singleton-accessor
24142+ # reader returning a Module) emitted the receiver expression
24143+ # (with its attendant warn_unresolved_call probe) even when
24144+ # none of the hash / array arms matched. Defer the side-effect
24145+ # into each arm so non-matching shapes fall through cleanly to
24146+ # the general dispatch at the bottom of compile_call_stmt.
2413924147 if mname == "delete"
2414024148 if recv >= 0
2414124149 rt = infer_type(recv)
24142- rc = compile_expr_gc_rooted(recv)
2414324150 if rt == "sym_int_hash"
24144- emit(" sp_SymIntHash_delete(" + rc + ", " + compile_arg0(nid) + ");")
24151+ emit(" sp_SymIntHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");")
2414524152 return 1
2414624153 end
2414724154 if rt == "sym_str_hash"
24148- emit(" sp_SymStrHash_delete(" + rc + ", " + compile_arg0(nid) + ");")
24155+ emit(" sp_SymStrHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");")
2414924156 return 1
2415024157 end
2415124158 if rt == "str_int_hash"
24152- emit(" sp_StrIntHash_delete(" + rc + ", " + compile_str_arg0(nid) + ");")
24159+ emit(" sp_StrIntHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_str_arg0(nid) + ");")
2415324160 return 1
2415424161 end
2415524162 if rt == "str_str_hash"
24156- emit(" sp_StrStrHash_delete(" + rc + ", " + compile_str_arg0(nid) + ");")
24163+ emit(" sp_StrStrHash_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_str_arg0(nid) + ");")
2415724164 return 1
2415824165 end
2415924166 if rt == "int_array"
24160- emit(" sp_IntArray_delete(" + rc + ", " + compile_arg0(nid) + ");")
24167+ emit(" sp_IntArray_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");")
2416124168 return 1
2416224169 end
2416324170 if rt == "str_array"
24164- emit(" sp_StrArray_delete(" + rc + ", " + compile_arg0(nid) + ");")
24171+ emit(" sp_StrArray_delete(" + compile_expr_gc_rooted(recv) + ", " + compile_arg0(nid) + ");")
2416524172 return 1
2416624173 end
2416724174 end