Commit d3da9b47

d3da9b473f6dMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · +1 added

Description

Fix GC root tracking: clear stale var table entries between functions

Root cause: var_declare would reuse stale entries from previous function scopes, placing variables at indices below saved_var_count. The variable declaration loop missed these, leaving IntArray locals (sr, sc) without GC_ROOT registration. GC then freed them.

Fix: clear var table name[0] from saved_var_count to MAX_VARS before each function, and guard var_lookup against empty names.

Also: Array.new(n, val) now correctly inferred as ARRAY type.

Adds nqueens benchmark (N=10, 1000 iterations): Spinel: 0.73s vs CRuby: 24.9s (34x faster)

Sudoku now runs 10000 iterations cleanly (ASAN verified).

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

Details

Commit
d3da9b473f6d
Parent
9d4d4a02bc95

examples/nqueens.rbaddedView file

1+# N-Queens solver benchmark (from yjit-bench)
2+
3+def nq_solve(n)
4+ a = Array.new(n, -1)
5+ l = Array.new(n, 0)
6+ c = Array.new(n, 0)
7+ r = Array.new(n, 0)
8+ y0 = (1 << n) - 1
9+ m = 0
10+ k = 0
11+
12+ while k >= 0
13+ y = (l[k] | c[k] | r[k]) & y0
14+ if (y ^ y0) >> (a[k] + 1) != 0
15+ i = a[k] + 1
16+ while i < n && (y & 1 << i) != 0
17+ i = i + 1
18+ end
19+ if k < n - 1
20+ z = 1 << i
21+ a[k] = i
22+ k = k + 1
23+ l[k] = (l[k - 1] | z) << 1
24+ c[k] = c[k - 1] | z
25+ r[k] = (r[k - 1] | z) >> 1
26+ else
27+ m = m + 1
28+ k = k - 1
29+ end
30+ else
31+ a[k] = -1
32+ k = k - 1
33+ end
34+ end
35+
36+ m
37+end
38+
39+total = 0
40+n = 0
41+while n < 1000
42+ total = total + nq_solve(10)
43+ n = n + 1
44+end
45+puts total
46+puts "done"