Commit da62c0e2
da62c0e2c75cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 2 files · +1 added · ~1 modified
Description
fix: prevent double nullable suffix (T??) in type inference
When scan_locals upgrades a nil-typed local with a nullable return type (e.g. obj_Node?), check if the type already has ? suffix before appending another one. Fixes linked list reverse returning sp_LNode??.
Adds linked_list benchmark (7.7x vs Ruby).
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- da62c0e2c75c
- Parent
- 5304881e9b7b
benchmark/linked_list.rbaddedView file
1+
class LNode2+
attr_accessor :val, :nxt3+
def initialize(val)4+
@val = val5+
@nxt = nil6+
@tag = "ln"7+
end8+
end9+
10+
def list_push(head, val)11+
node = LNode.new(val)12+
node.nxt = head13+
node14+
end15+
16+
def list_length(head)17+
n = 018+
cur = head19+
while cur != nil20+
n = n + 121+
cur = cur.nxt22+
end23+
n24+
end25+
26+
def list_reverse(head)27+
prev = nil28+
cur = head29+
while cur != nil30+
nxt = cur.nxt31+
cur.nxt = prev32+
prev = cur33+
cur = nxt34+
end35+
prev36+
end37+
38+
def list_sum(head)39+
s = 040+
cur = head41+
while cur != nil42+
s = s + cur.val43+
cur = cur.nxt44+
end45+
s46+
end47+
48+
# Build list of 100000 elements49+
head = nil50+
i = 051+
while i < 10000052+
head = list_push(head, i)53+
i = i + 154+
end55+
puts list_length(head)56+
puts list_sum(head)57+
58+
# Reverse and sum59+
head = list_reverse(head)60+
puts list_sum(head)61+
62+
# Rebuild + reverse 10 times63+
j = 064+
while j < 1065+
head = nil66+
i = 067+
while i < 10000068+
head = list_push(head, i)69+
i = i + 170+
end71+
head = list_reverse(head)72+
j = j + 173+
end74+
puts list_length(head)75+
puts "done"spinel_codegen.rbmodifiedView file
Loading diff…