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 LNode
2+ attr_accessor :val, :nxt
3+ def initialize(val)
4+ @val = val
5+ @nxt = nil
6+ @tag = "ln"
7+ end
8+end
9+
10+def list_push(head, val)
11+ node = LNode.new(val)
12+ node.nxt = head
13+ node
14+end
15+
16+def list_length(head)
17+ n = 0
18+ cur = head
19+ while cur != nil
20+ n = n + 1
21+ cur = cur.nxt
22+ end
23+ n
24+end
25+
26+def list_reverse(head)
27+ prev = nil
28+ cur = head
29+ while cur != nil
30+ nxt = cur.nxt
31+ cur.nxt = prev
32+ prev = cur
33+ cur = nxt
34+ end
35+ prev
36+end
37+
38+def list_sum(head)
39+ s = 0
40+ cur = head
41+ while cur != nil
42+ s = s + cur.val
43+ cur = cur.nxt
44+ end
45+ s
46+end
47+
48+# Build list of 100000 elements
49+head = nil
50+i = 0
51+while i < 100000
52+ head = list_push(head, i)
53+ i = i + 1
54+end
55+puts list_length(head)
56+puts list_sum(head)
57+
58+# Reverse and sum
59+head = list_reverse(head)
60+puts list_sum(head)
61+
62+# Rebuild + reverse 10 times
63+j = 0
64+while j < 10
65+ head = nil
66+ i = 0
67+ while i < 100000
68+ head = list_push(head, i)
69+ i = i + 1
70+ end
71+ head = list_reverse(head)
72+ j = j + 1
73+end
74+puts list_length(head)
75+puts "done"