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
# N-Queens solver benchmark (from yjit-bench)def nq_solve(n) a = Array.new(n, -1) l = Array.new(n, 0) c = Array.new(n, 0) r = Array.new(n, 0) y0 = (1 << n) - 1 m = 0 k = 0 while k >= 0 y = (l[k] | c[k] | r[k]) & y0 if (y ^ y0) >> (a[k] + 1) != 0 i = a[k] + 1 while i < n && (y & 1 << i) != 0 i = i + 1 end if k < n - 1 z = 1 << i a[k] = i k = k + 1 l[k] = (l[k - 1] | z) << 1 c[k] = c[k - 1] | z r[k] = (r[k - 1] | z) >> 1 else m = m + 1 k = k - 1 end else a[k] = -1 k = k - 1 end end mendtotal = 0n = 0while n < 1000 total = total + nq_solve(10) n = n + 1endputs totalputs "done"