lua: table.sort insertion-sort → quicksort; 30k sort.lua still timeouts (interpreter-bound)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 21:02:33 +00:00
parent 57516ce18e
commit 12b02d5691
4 changed files with 61 additions and 44 deletions

View File

@@ -1132,23 +1132,39 @@
((= comp nil) (lua-lt a b)) ((= comp nil) (lua-lt a b))
(else (lua-truthy? (lua-call comp a b)))))) (else (lua-truthy? (lua-call comp a b))))))
(define (define
insert-sorted ts-swap
(fn (i) (fn (i j)
(when (> i 1) (let ((vi (get t (str i))) (vj (get t (str j))))
(let ((v (get t (str i))) (prev (get t (str (- i 1)))))
(when (lt? v prev)
(begin
(dict-set! t (str i) prev)
(dict-set! t (str (- i 1)) v)
(insert-sorted (- i 1))))))))
(define
outer
(fn (i)
(when (<= i n)
(begin (begin
(insert-sorted i) (dict-set! t (str i) vj)
(outer (+ i 1)))))) (dict-set! t (str j) vi)))))
(outer 2) (define
ts-partition
(fn (lo hi)
(let ((pivot (get t (str hi))) (i (- lo 1)))
(begin
(define
pt-loop
(fn (j)
(when (< j hi)
(begin
(when (lt? (get t (str j)) pivot)
(begin
(set! i (+ i 1))
(ts-swap i j)))
(pt-loop (+ j 1))))))
(pt-loop lo)
(ts-swap (+ i 1) hi)
(+ i 1)))))
(define
ts-qsort
(fn (lo hi)
(when (< lo hi)
(let ((p (ts-partition lo hi)))
(begin
(ts-qsort lo (- p 1))
(ts-qsort (+ p 1) hi))))))
(ts-qsort 1 n)
nil))))) nil)))))
(define (define

View File

@@ -39,7 +39,7 @@
"name": "attrib.lua", "name": "attrib.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5843 "ms": 5800
}, },
{ {
"name": "big.lua", "name": "big.lua",
@@ -51,7 +51,7 @@
"name": "calls.lua", "name": "calls.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4830 "ms": 4877
}, },
{ {
"name": "checktable.lua", "name": "checktable.lua",
@@ -63,7 +63,7 @@
"name": "closure.lua", "name": "closure.lua",
"status": "timeout", "status": "timeout",
"reason": "per-test timeout", "reason": "per-test timeout",
"ms": 8000 "ms": 8007
}, },
{ {
"name": "code.lua", "name": "code.lua",
@@ -75,7 +75,7 @@
"name": "constructs.lua", "name": "constructs.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 4113 "ms": 4365
}, },
{ {
"name": "db.lua", "name": "db.lua",
@@ -87,13 +87,13 @@
"name": "errors.lua", "name": "errors.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3084 "ms": 3188
}, },
{ {
"name": "events.lua", "name": "events.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6860 "ms": 7039
}, },
{ {
"name": "files.lua", "name": "files.lua",
@@ -111,13 +111,13 @@
"name": "literals.lua", "name": "literals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 1770 "ms": 1873
}, },
{ {
"name": "locals.lua", "name": "locals.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 1646 "ms": 1713
}, },
{ {
"name": "main.lua", "name": "main.lua",
@@ -129,19 +129,19 @@
"name": "math.lua", "name": "math.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3867 "ms": 4010
}, },
{ {
"name": "nextvar.lua", "name": "nextvar.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 6771 "ms": 6632
}, },
{ {
"name": "pm.lua", "name": "pm.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 5769 "ms": 5609
}, },
{ {
"name": "sort.lua", "name": "sort.lua",
@@ -153,19 +153,19 @@
"name": "strings.lua", "name": "strings.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 3909 "ms": 3655
}, },
{ {
"name": "vararg.lua", "name": "vararg.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"assertion failed!\\\\\\\"\\",
"ms": 2074 "ms": 2039
}, },
{ {
"name": "verybig.lua", "name": "verybig.lua",
"status": "fail", "status": "fail",
"reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio", "reason": "other: Unhandled exception: \\\"Unhandled exception: \\\\\\\"lua: attempt to call non-functio",
"ms": 567 "ms": 537
} }
] ]
} }

View File

@@ -15,25 +15,25 @@ fail=13 timeout=3 skip=8 total=24
|---|---|---|---:| |---|---|---|---:|
| all.lua | skip | driver uses dofile to chain other tests | 0 | | all.lua | skip | driver uses dofile to chain other tests | 0 |
| api.lua | skip | requires testC (C debug library) | 0 | | api.lua | skip | requires testC (C debug library) | 0 |
| attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5843 | | attrib.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5800 |
| big.lua | timeout | per-test timeout | 8007 | | big.lua | timeout | per-test timeout | 8007 |
| calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4830 | | calls.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4877 |
| checktable.lua | skip | internal debug helpers | 0 | | checktable.lua | skip | internal debug helpers | 0 |
| closure.lua | timeout | per-test timeout | 8000 | | closure.lua | timeout | per-test timeout | 8007 |
| code.lua | skip | bytecode inspection via debug library | 0 | | code.lua | skip | bytecode inspection via debug library | 0 |
| constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4113 | | constructs.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4365 |
| db.lua | skip | debug library | 0 | | db.lua | skip | debug library | 0 |
| errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3084 | | errors.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3188 |
| events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6860 | | events.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 7039 |
| files.lua | skip | io library | 0 | | files.lua | skip | io library | 0 |
| gc.lua | skip | collectgarbage / finalisers | 0 | | gc.lua | skip | collectgarbage / finalisers | 0 |
| literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1770 | | literals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 1873 |
| locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1646 | | locals.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 1713 |
| main.lua | skip | standalone interpreter driver | 0 | | main.lua | skip | standalone interpreter driver | 0 |
| math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3867 | | math.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 4010 |
| nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6771 | | nextvar.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 6632 |
| pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5769 | | pm.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 5609 |
| sort.lua | timeout | per-test timeout | 8007 | | sort.lua | timeout | per-test timeout | 8007 |
| strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3909 | | strings.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 3655 |
| vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2074 | | vararg.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"assertion failed!\\\"\ | 2039 |
| verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 567 | | verybig.lua | fail | other: Unhandled exception: \"Unhandled exception: \\\"lua: attempt to call non-functio | 537 |

View File

@@ -82,6 +82,7 @@ Each item: implement → tests → tick box → update progress log.
_Newest first. Agent appends on every commit._ _Newest first. Agent appends on every commit._
- 2026-04-24: lua: scoreboard iteration — `table.sort` O(n²) insertion-sort → **quicksort** (Lomuto partition). 1000-element sorts finish in ms; but `sort.lua` uses 30k elements and still times out even at 90s (metamethod-heavy interpreter overhead). Correctness verified on 1000/5000 element random arrays.
- 2026-04-24: lua: scoreboard iteration — `dostring(s)` alias for `loadstring(s)()` (Lua 5.0 compat used by literals.lua). Diagnosed `locals.lua` call-non-fn at call #18`getfenv/setfenv` stub-return pattern fails `assert(getfenv(foo("")) == a)` (need real env tracking, deferred). Tokenizer long-string-leading-NL rule verified correct. - 2026-04-24: lua: scoreboard iteration — `dostring(s)` alias for `loadstring(s)()` (Lua 5.0 compat used by literals.lua). Diagnosed `locals.lua` call-non-fn at call #18`getfenv/setfenv` stub-return pattern fails `assert(getfenv(foo("")) == a)` (need real env tracking, deferred). Tokenizer long-string-leading-NL rule verified correct.
- 2026-04-24: lua: scoreboard iteration — Lua 5.0-style `arg` auto-binding inside vararg functions (some PUC-Rio tests still rely on it). `lua-varargs-arg-table` builds `{1=v1, 2=v2, …, n=count}`; transpile adds `arg` binding alongside `__varargs` when `is-vararg`. Diagnosis done with assert-counter instrumentation — literals.lua fails at #4 (long-string NL rule), vararg.lua was at #2 (arg table — FIXED), attrib.lua at #9, locals.lua now past asserts into call-non-fn. 360 tests. - 2026-04-24: lua: scoreboard iteration — Lua 5.0-style `arg` auto-binding inside vararg functions (some PUC-Rio tests still rely on it). `lua-varargs-arg-table` builds `{1=v1, 2=v2, …, n=count}`; transpile adds `arg` binding alongside `__varargs` when `is-vararg`. Diagnosis done with assert-counter instrumentation — literals.lua fails at #4 (long-string NL rule), vararg.lua was at #2 (arg table — FIXED), attrib.lua at #9, locals.lua now past asserts into call-non-fn. 360 tests.
- 2026-04-24: lua: scoreboard iteration — **`loadstring` scoping**. Temporarily instrumented `lua-assert` with a counter, found `locals.lua` fails at assertion #5: `loadstring('local a = {}')() → assert(type(a) ~= 'table')`. The loadstring'd code's `local a` was leaking to outer scope because `lua-eval-ast` ran at top-level. Fixed by transpiling once and wrapping the AST in `(let () …)` before `eval-expr`. - 2026-04-24: lua: scoreboard iteration — **`loadstring` scoping**. Temporarily instrumented `lua-assert` with a counter, found `locals.lua` fails at assertion #5: `loadstring('local a = {}')() → assert(type(a) ~= 'table')`. The loadstring'd code's `local a` was leaking to outer scope because `lua-eval-ast` ran at top-level. Fixed by transpiling once and wrapping the AST in `(let () …)` before `eval-expr`.