Commit c4912767

c4912767cd8aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 2 files · +1 added · ~1 modified

Description

Fix nil-initialized ivar type inference, add OBJECT==nil comparison

Type inference:

  • NIL-typed ivars now treated as "unresolved" (like VALUE)
  • Scan all method bodies for @ivar = expr, not just initialize
  • Setter calls (node.left = Node.new) update ivar types

Codegen:

  • OBJECT == nil → ptr == NULL comparison (was unsupported)
  • Also handles nil == OBJECT (reversed)

Enables tree-based benchmarks (gcbench, splay pattern):

  • gcbench: Spinel 0.22s vs CRuby 4.23s (19x)

76/76 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
c4912767cd8a
Parent
9ddfede0ad39

examples/bm_gcbench.rbaddedView file

1+# GCBench (from yjit-bench) - binary tree construction benchmark
2+
3+class Node
4+ attr_accessor :left, :right, :i, :j
5+ def initialize
6+ @left = nil
7+ @right = nil
8+ @i = 0
9+ @j = 0
10+ @tag = "n"
11+ end
12+end
13+
14+STRETCH_DEPTH = 18
15+LONG_LIVED_DEPTH = 16
16+MIN_DEPTH = 4
17+MAX_DEPTH = 16
18+
19+def tree_size(depth)
20+ (1 << (depth + 1)) - 1
21+end
22+
23+def num_iters(depth)
24+ 2 * tree_size(STRETCH_DEPTH) / tree_size(depth)
25+end
26+
27+def populate(depth, node)
28+ if depth > 0
29+ node.left = Node.new
30+ node.right = Node.new
31+ populate(depth - 1, node.left)
32+ populate(depth - 1, node.right)
33+ end
34+end
35+
36+def make_tree(depth)
37+ if depth <= 0
38+ Node.new
39+ else
40+ n = Node.new
41+ n.left = make_tree(depth - 1)
42+ n.right = make_tree(depth - 1)
43+ n
44+ end
45+end
46+
47+def time_construction(depth)
48+ n = num_iters(depth)
49+ i = 0
50+ while i < n
51+ node = Node.new
52+ populate(depth, node)
53+ i = i + 1
54+ end
55+ i = 0
56+ while i < n
57+ make_tree(depth)
58+ i = i + 1
59+ end
60+end
61+
62+make_tree(STRETCH_DEPTH)
63+
64+long_lived = Node.new
65+populate(LONG_LIVED_DEPTH, long_lived)
66+
67+depth = MIN_DEPTH
68+while depth <= MAX_DEPTH
69+ time_construction(depth)
70+ depth = depth + 2
71+end
72+
73+puts "done"