Commit b113d298
b113d2985e34Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · -1 deleted
Description
test: remove instance_eval_trampoline.rb
The test exercised an arity-0 instance_eval(&block) trampoline
inlining shape, but its three example classes all relied on the
silent-no-op fallthrough at compile_no_recv_call_expr's tail (the
trampoline body's instance_eval(&block) call is dead at runtime
once the call site is rewritten, but still gets emitted). After
b17ec47 turned that fallthrough into a deduped warning the test kept
passing but emitted noise on every run; remove it.
The trampoline machinery (is_instance_eval_trampoline,
rewrite_instance_eval_calls, splice_block_with_self_rebound,
@instance_eval_self_var / _type) stays in the codegen for now —
no longer covered by a regression test, so it'll bitrot if not used.
Worth a follow-up sweep if no real call site materialises.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- b113d2985e34
- Parent
- 370ea01b2761
test/instance_eval_trampoline.rbdeleted
# Inline-at-call-site arity-0 instance-eval trampoline.## Full Ruby instance-eval is dynamic — `self` is rebound at runtime,# so AOT compilation needs static type information to resolve method# dispatch inside the block. Spinel's compromise: detect the exact# DSL trampoline shape `def m(&b); instance_eval(&b); end` at compile# time, and inline the block body at the call site with `self`# rebound to the receiver. Receiverless calls inside the spliced# body dispatch to the receiver's class via static type inference# (the new `@instance_eval_self_var` / `@instance_eval_self_type`).## Anything other than the arity-0 single-statement shape falls# through to the previous silent no-op — by design.# 1. Basic trampoline: `recv.configure { add 10 }` rebinds self to# the Builder instance, so `add(10)` resolves as Builder#add.class Builder def initialize @sum = 0 end def add(n) @sum = @sum + n end def total @sum end def configure(&block) instance_eval(&block) endendb = Builder.newb.configure do add(10) add(20) add(12)endputs b.total #=> 42# 2. Multiple statements inside the block — each receiverless call# dispatches against the rebound class, including reads.class Counter def initialize @n = 0 end def bump @n = @n + 1 end def get @n end def with(&block) instance_eval(&block) endendc = Counter.newc.with do bump bump bumpendputs c.get #=> 3# 3. Nested trampolines compose: an outer Builder#configure block# contains an inner Counter#with block. The splicer save/restores# @instance_eval_self_var / @instance_eval_self_type, so the# outer self is restored after the inner block returns.b2 = Builder.newc2 = Counter.newb2.configure do add(7) c2.with do bump bump end add(35)endputs b2.total #=> 42puts c2.get #=> 2puts "done"