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

1-# Inline-at-call-site arity-0 instance-eval trampoline.
2-#
3-# Full Ruby instance-eval is dynamic — `self` is rebound at runtime,
4-# so AOT compilation needs static type information to resolve method
5-# dispatch inside the block. Spinel's compromise: detect the exact
6-# DSL trampoline shape `def m(&b); instance_eval(&b); end` at compile
7-# time, and inline the block body at the call site with `self`
8-# rebound to the receiver. Receiverless calls inside the spliced
9-# body dispatch to the receiver's class via static type inference
10-# (the new `@instance_eval_self_var` / `@instance_eval_self_type`).
11-#
12-# Anything other than the arity-0 single-statement shape falls
13-# through to the previous silent no-op — by design.
14-
15-# 1. Basic trampoline: `recv.configure { add 10 }` rebinds self to
16-# the Builder instance, so `add(10)` resolves as Builder#add.
17-class Builder
18- def initialize
19- @sum = 0
20- end
21-
22- def add(n)
23- @sum = @sum + n
24- end
25-
26- def total
27- @sum
28- end
29-
30- def configure(&block)
31- instance_eval(&block)
32- end
33-end
34-
35-b = Builder.new
36-b.configure do
37- add(10)
38- add(20)
39- add(12)
40-end
41-puts b.total #=> 42
42-
43-# 2. Multiple statements inside the block — each receiverless call
44-# dispatches against the rebound class, including reads.
45-class Counter
46- def initialize
47- @n = 0
48- end
49-
50- def bump
51- @n = @n + 1
52- end
53-
54- def get
55- @n
56- end
57-
58- def with(&block)
59- instance_eval(&block)
60- end
61-end
62-
63-c = Counter.new
64-c.with do
65- bump
66- bump
67- bump
68-end
69-puts c.get #=> 3
70-
71-# 3. Nested trampolines compose: an outer Builder#configure block
72-# contains an inner Counter#with block. The splicer save/restores
73-# @instance_eval_self_var / @instance_eval_self_type, so the
74-# outer self is restored after the inner block returns.
75-b2 = Builder.new
76-c2 = Counter.new
77-b2.configure do
78- add(7)
79- c2.with do
80- bump
81- bump
82- end
83- add(35)
84-end
85-puts b2.total #=> 42
86-puts c2.get #=> 2
87-
88-puts "done"