Fuzzing (roadmap S3)
trine fuzz --cases 100000 --seed 1 # differential program fuzzing
trine fuzz --syntax --cases 1000000 --seed 1 # character-level mutation fuzzing
trine fuzz --show 10000861 # print the program for a seed (to reproduce)
Failing cases are saved to fuzz-failures/case-<seed>.tr. Once fixed, they move to tests/fuzz_regressions/ and run in cargo test forever.
What it checks
Program mode generates random, well-typed, terminating programs. They use data types, matches, lambdas with captures, loops (bounded by construction), list indexing (guarded, so the verifier should prove it, and unguarded, which may fail), overflow bait, division by zero, and calls between functions (with a cost budget so programs stay fast). Each program then runs on:
- the tree-walking interpreter (the reference);
- the IR VM under naive, Perceus, Perceus+borrow, Perceus+reuse, and Perceus+reuse with verified bounds checks erased.
All six must agree exactly: the same output, and the same error message if the program fails. The VM also acts as a checker. Use-after-move, double drop, leaks, and an erased bounds check that turns out to be needed are all reported as failures. A metamorphic check also renames every variable and function and requires every content hash to stay the same.
Syntax mode mutates generated programs at the character level (deleting, inserting tokens, swapping, duplicating runs). It runs the lexer, parser and checker, and, if the result still type-checks, every static pass: lowering, Perceus, bounds verification, hashing, IR printing. Errors are expected; panics and hangs (more than 5 s) are failures.
Results (2026-11-26)
| run | cases | result |
|---|---|---|
| program mode, first 4,000 | 4,000 | found a parser bug (14% of programs misparsed; see below) |
| syntax mode | 1,000,000 | clean: no panics, no hangs (slowest case 213 ms) |
| program mode, first 230,000 | 230,000 | found an ownership bug (6 cases; see below) |
| program mode, after fixes | 1,000,000 | clean: no panics, hangs, disagreements, ownership or verifier bugs (4 runs, seeds 20,000,000–21,000,000, ~37 min on 2 cores, slowest case 712 ms) |
Bugs found and fixed
- Silent misparse after block expressions (parser). After a
matchor multi-lineif, a next line starting with(,[or-was glued onto the block as a call, index or subtraction:
match x: A(v) => ... [6, v16, f1()] # parsed as (match ...)[6, v16, f1()]
It hit 14% of generated programs. It was usually rejected by the type checker, but a misparse that happens to type-check would silently change meaning. Fix: an expression that ends with an indented block is complete. After the fix: 0% rejections.
- Leak with the same variable passed twice (Perceus + borrow inference). In
f(x, x)with one borrowed and one owned parameter, the owned use was correctly a copy, but the drop rule skippedxbecause "it has an owned use", so it was never released. Inside loops this showed up as overwriting a live value. In compiled code it would be a memory leak (or worse, depending on how the slot is reused). Fix: any slot that dies at an operation and wasn't moved is dropped right after it, whatever mix of uses it had. All 6 cases are now regression tests. The bet 1 numbers are unchanged.
Both bugs passed every hand-written test, which is exactly why fuzzing comes before the native backend.
Totals
2,000,000 clean cases: 1,000,000 differential program runs (each executed six ways, so 6 million executions compared) plus 1,000,000 syntax mutations. 2 real bugs found and fixed, both now covered by regression tests.