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 benchmark2+
3+
class Node4+
attr_accessor :left, :right, :i, :j5+
def initialize6+
@left = nil7+
@right = nil8+
@i = 09+
@j = 010+
@tag = "n"11+
end12+
end13+
14+
STRETCH_DEPTH = 1815+
LONG_LIVED_DEPTH = 1616+
MIN_DEPTH = 417+
MAX_DEPTH = 1618+
19+
def tree_size(depth)20+
(1 << (depth + 1)) - 121+
end22+
23+
def num_iters(depth)24+
2 * tree_size(STRETCH_DEPTH) / tree_size(depth)25+
end26+
27+
def populate(depth, node)28+
if depth > 029+
node.left = Node.new30+
node.right = Node.new31+
populate(depth - 1, node.left)32+
populate(depth - 1, node.right)33+
end34+
end35+
36+
def make_tree(depth)37+
if depth <= 038+
Node.new39+
else40+
n = Node.new41+
n.left = make_tree(depth - 1)42+
n.right = make_tree(depth - 1)43+
n44+
end45+
end46+
47+
def time_construction(depth)48+
n = num_iters(depth)49+
i = 050+
while i < n51+
node = Node.new52+
populate(depth, node)53+
i = i + 154+
end55+
i = 056+
while i < n57+
make_tree(depth)58+
i = i + 159+
end60+
end61+
62+
make_tree(STRETCH_DEPTH)63+
64+
long_lived = Node.new65+
populate(LONG_LIVED_DEPTH, long_lived)66+
67+
depth = MIN_DEPTH68+
while depth <= MAX_DEPTH69+
time_construction(depth)70+
depth = depth + 271+
end72+
73+
puts "done"src/expr.cmodifiedView file
Loading diff…