Commit 02005f26
02005f26debaMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · +1 added · ~1 modified
Description
fix(codegen): emit stub body for instance_eval(&b) trampolines
PR #124's def m(&b); instance_eval(&b); end trampoline mechanism
detects this exact shape at the call site (recv.m { ... }) and
splices the block inline with self rebound to recv. The body of the
trampoline method itself is dead at runtime — every call site
bypasses it. But emit_instance_method was still compiling the body,
which contains a single instance_eval(&block) call that hits the
warn-and-emit-0 fallback at compile_no_recv_call_expr's tail (added
in b17ec47). Result: every trampoline definition emitted one
"warning: cannot resolve call to 'instance_eval'" line per codegen.
Detect trampolines at emit_instance_method time and skip body
compilation. The fallback return c_return_default(rt); at the end
of the function still emits a syntactically-valid C body for the
linker; the body is unreachable so the return value doesn't matter.
The earlier removal of test/instance_eval_trampoline.rb (40d112e) was prompted by exactly this warning noise; with the body skipped the test runs cleanly. Restored.
Implementation note: the obvious one-liner
is_tramp = midx >= 0 && is_instance_eval_trampoline(...) == 1
binds is_tramp to TrueClass/FalseClass under CRuby semantics,
which makes the subsequent is_tramp == 0 / == 1 int-compares
silently false. Explicit if-block + 1/0 sentinel matches Spinel's
codegen-internal idiom (helpers return integer 1/0, not booleans),
so the same source compiles correctly under both CRuby and the
self-hosted spinel binary.
Bootstrap (gen2 == gen3) clean; 199 tests + 56 benches pass; zero warnings across all test/.rb and benchmark/.rb.
Refs #124
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 02005f26deba
- Parent
- 51d369bb0e1c
spinel_codegen.rbmodifiedView file
j = j + 1 end if bid >= 0 # PR #124 trampoline (`def m(&b); instance_eval(&b); end`): # the body is dead at runtime — every call site `recv.m { ... }` # gets splice-rewritten by try_yield_or_trampoline_dispatch. # Skipping the body compilation avoids the warn-and-emit-0 # fallback that compile_no_recv_call_expr would hit for the dead # `instance_eval(&block)` call inside (which would otherwise fire # one warning per trampoline definition every codegen run). The # fallback `return c_return_default(rt);` below still provides a # syntactically-valid but unreachable C body for the linker. is_tramp = 0 if midx >= 0 if is_instance_eval_trampoline(ci, midx) == 1 is_tramp = 1 end end if bid >= 0 && is_tramp == 0 declare_method_locals(bid, pnames) if @in_gc_scope == 0 if @needs_gc == 1test/instance_eval_trampoline.rbaddedView file
Loading diff…