tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

68 lignes · 3427 octetsBrut · Historique

fuzz

The differential fuzzer for the compiler (issue #352). src/main.lse is a random-program generator built on packages/gen (ADR 0064): given LOUISE_FUZZ_SEED it prints one small, deterministic, well-typed Louise program. crates/louise_codegen_c/tests/fuzz.rs builds the generator once, then, per seed, runs the program interpreted and natively (one thread, as the interpreter) and compares:

  • stdout, byte for byte;
  • the exit: normal, or a panic with the same message (101 natively);
  • the leak oracle: the native run reports louise: live blocks: 0.

Generated programs are deterministic (every choice is made at generation time; the only std/random use in a program is under random.with_seed) and terminate by construction (recursion decreases an Int argument that call sites clamp; lists are small).

Running it

cargo test -p louise_codegen_c --test fuzz            # 25 programs from seed 1
LOUISE_FUZZ_SEED=41000 LOUISE_FUZZ_RUNS=500 cargo test -p louise_codegen_c --test fuzz

scripts/ci.sh's full mode runs a bounded lane with a random base seed it prints. A failure dumps the program to target/fuzz/case-<seed>.lse, minimizes it (line-chunk deletion while the mismatch still reproduces; LOUISE_FUZZ_MIN_BUDGET bounds the tries) into case-<seed>.min.lse, and fails naming the seed. Reproduce with LOUISE_FUZZ_SEED=<seed> LOUISE_FUZZ_RUNS=1. A minimized crasher belongs in tests/run (add the //> lines the interpreter prints; tests/README.md has the format).

Grammar coverage

  • Expressions: Int/Bool/String literals and operators (+ - * / %, comparisons, ==, <>), string interpolation, show, if, single-line match (on Option, lists, the generated enum, the generated record, Int literals with a guard), closures passed to list.map/filter/fold/any, tuple construction and .0/.1 projection, helper-function calls.
  • Types: Int, Bool, String, lists, options, pairs; a generated enum Choice { A, B(Int), C(String) } and a generated record R with two or three scalar fields (construction, field access, R(..r, f: x) update) in about half of the programs.
  • Statements: annotated let, io.println, if/else blocks, match statements, defer.
  • Effects and handlers (at most two per program): a fn operation (ask), a one-shot ctl operation with resume (collect) and without it (cancellation, with a defer in the cancelled body), a final ctl operation into Result, and handler installation with use <-.
  • use/defer: defer in blocks and cancelled bodies; use x <- result.try in generated Result helpers; use x <- list.each as a final loop; use n <- ref.update in region blocks (references, ref.new/get/set).
  • Std externs: std/list, std/string (length, to_int), std/result.try, std/ref, std/random under with_seed.

Deliberately out (v1): actors and process (nondeterministic scheduling), floats, files and real I/O, multi-shot resumptions, BigInt stress, UInt/bytes. The interpreter and the native backend both run the optimised Core; the unoptimised differential is covered by the existing native.rs lanes.

Nothing in a generated program is random at run time, so a seed reproduces a program exactly: the same seed draws the same bytes, and gen's generators give smaller programs from smaller bytes.