aython

Chapter 6 of 1130 min read

Proving it right

Nobody reads the emitted assembly line by line. A differential judge runs every program under the ELF and under CPython and requires the same bytes, backed by leak probes, a fuzzer and CI.

The generated assembly and the runtime run to tens of thousands of lines that no person checks line by line. Something else has to decide that an aython executable is right, and has to be strict enough that "it passed" means something. That something is the differential judge: it runs every program as a native executable and under CPython, and requires the same bytes. This chapter is about the judge, the corpus it runs, and the leak probe, fuzzer and CI pipeline built around it.

Python has no specification on paper that a compiler could be checked against. So aython does not try to write one. Its correctness rule, the second principle in docs/core-design.md, is that CPython is the specification: whatever python3 prints for a program is, by definition, what the aython executable must print. Every corner case nobody thought to write down (how -7 // 2 rounds, how print spells -0.0, which order a set iterates in) is settled by asking CPython, not by reading a document.

The judge is the command that asks. uv run aython check prog.py builds the program into an ELF, runs the ELF and python3 on the same source, and compares what they did. Every file in tests/mvp/ carries a one-line marker that says which comparison applies.

One file, one verdict #

check_file in judge.py is the whole decision. It reads the marker, and then either stops at the frontend (a refusal case), skips (a helper module), or builds the ELF, runs both sides and hands the four results to the check for that kind:

src/aython/judge.py · check_filelines 344–377def check_file(path: Path, runtime_src: Path) -> CheckResult:
    """Check one corpus file against its declared expectation.

    Args:
        path: Corpus ``.py`` file.
        runtime_src: Path to ``runtime.s`` for buildable cases.

    Returns:
        The verdict with one line of evidence.
    """
    kind, payload = parse_expectation(path)
    if kind == EXPECT_REJECT:
        return _check_reject(path, payload)
    if kind == EXPECT_SKIP:
        return CheckResult(path.name, EXPECT_SKIP, True, "helper module: not a standalone program (ok-skip)")
    try:
        elf_path = build_program(path, runtime_src)
    except frontend.FrontendError as exc:
        return CheckResult(path.name, kind, False, f"frontend refused buildable case: {exc}")
    except subprocess.CalledProcessError as exc:
        return CheckResult(path.name, kind, False, f"toolchain failed: {exc}")
    elf_out, elf_err, elf_rc, elf_timed_out = run_elf(elf_path, parse_argv(path))
    if elf_timed_out:
        return CheckResult(path.name, kind, False, "ELF timed out")
    py_out, py_err, py_rc, py_timed_out = run_cpython(path, parse_argv(path))
    if py_timed_out:
        return CheckResult(path.name, kind, False, "CPython timed out")
    if kind == EXPECT_PASS:
        return _check_pass(path, elf_out, elf_rc, py_out, py_rc)
    if kind == EXPECT_ERROR:
        return _check_error(path, payload, elf_out, elf_err, elf_rc, py_err, py_rc)
    if kind == EXPECT_ABORT:
        return _check_abort(path, payload, elf_rc, elf_err)
    return CheckResult(path.name, kind, False, f"unknown expectation {kind!r}")
flowchart TD
  src["tests/mvp/prog.py<br/># mvp: kind[:detail]"] --> marker{"parse_expectation"}
  marker -->|"reject"| fe["frontend.compile_source<br/>must raise FrontendError"]
  marker -->|"skip"| skip["ok-skip<br/>(helper module)"]
  marker -->|"pass / error / abort"| build["build_program<br/>frontend → codegen → as → cc"]
  build --> elf["run the ELF<br/>stdout, stderr, exit status"]
  elf --> cpy["run python3<br/>stdout, stderr, exit status"]
  cpy --> cmp{"_check_pass<br/>_check_error<br/>_check_abort"}
  fe --> verdict["ok / FAIL, one line of evidence"]
  cmp --> verdict
  class build,elf accent
  class cpy py
  class verdict good
What aython check does with one corpus file. Both sides run with the same arguments and a time limit; only the check at the end depends on the marker.

Both sides get the same limit, 5 seconds for the ELF and 5 for CPython (ELF_TIMEOUT_S, CPYTHON_TIMEOUT_S). A timeout on either side fails the check, so an infinite loop in generated code shows up as a failure, not a hung CI job. The result is a CheckResult with one line of evidence, such as 13 stdout bytes match or stdout differs: b'3\n' vs b'4\n', which is what aython check logs.

Five kinds of expectation #

The marker is a comment, so the file is still an ordinary Python program that CPython runs unchanged. The corpus currently holds 290 files: 270 programs plus 20 helper modules.

Marker Files What the judge asserts What a failure means
# mvp: pass 106 Both exit 0, and the ELF’s stdout bytes equal CPython’s exactly The ELF computes or prints something differently
# mvp: error:<Kind> 71 Both exit non-zero, and both stderrs contain <Kind>; stdout is not compared aython fails in a different way, or not at all
# mvp: abort:<Kind> 22 The ELF exits non-zero with <Kind> on stderr; CPython’s result is ignored A recorded divergence stopped behaving as recorded
# mvp: reject:<text> 71 The frontend refuses with a message containing aython: unsupported: and <text>; nothing is built Something outside the subset slipped through
# mvp: skip 20 Nothing: a module other files import (inc_*.py)

The pass check is the strictest and the simplest:

src/aython/judge.py · _check_passlines 403–422def _check_pass(path: Path, elf_out: bytes, elf_rc: int, py_out: bytes, py_rc: int) -> CheckResult:
    """Assert byte-identical stdout and clean exits.

    Args:
        path: Corpus file name for the verdict.
        elf_out: ELF stdout bytes.
        elf_rc: ELF exit status.
        py_out: CPython stdout bytes.
        py_rc: CPython exit status.

    Returns:
        The verdict with the matched byte count as evidence.
    """
    if elf_rc != EXIT_OK:
        return CheckResult(path.name, EXPECT_PASS, False, f"ELF exit {elf_rc}")
    if py_rc != EXIT_OK:
        return CheckResult(path.name, EXPECT_PASS, False, f"CPython exit {py_rc}")
    if elf_out != py_out:
        return CheckResult(path.name, EXPECT_PASS, False, f"stdout differs: {elf_out!r} vs {py_out!r}")
    return CheckResult(path.name, EXPECT_PASS, True, f"{len(elf_out)} stdout bytes match")

Exit status is checked before output, so a program that prints the right text and then crashes still fails. Standard error is never compared for pass, because it is where the two sides are allowed to differ most: CPython prints tracebacks and warnings, aython prints one line. That is also why the error check only asks for the kind name. For err_divzero.py (y = x // 0), CPython’s traceback ends with

ZeroDivisionError: division by zero

while the ELF’s whole stderr is aython: ZeroDivisionError. Both contain ZeroDivisionError, and that is the comparison. The error kinds the corpus pins most often are:

Error kind error files abort files
TypeError 42 9
KeyError 7 1
ValueError 7 2
ZeroDivisionError 5 0
FileNotFoundError 3 0
IndexError 3 0
RuntimeError 2 0
NotImplementedError 1 0
OverflowError 1 6

Turning a divergence into a test #

The abort kind exists for the places where aython knowingly does something else. Integers are 64-bit, so 2**62 * 4 cannot be computed; CPython prints 18446744073709551616, aython aborts OverflowError. Neither pass nor error can describe that, because one side succeeds. An abort file pins the aython side alone:

src/aython/judge.py · _check_abortlines 462–479def _check_abort(path: Path, error_kind: str, elf_rc: int, elf_err: bytes) -> CheckResult:
    """Assert the ELF aborts where CPython legitimately diverges.

    Args:
        path: Corpus file name for the verdict.
        error_kind: Expected kind on the ELF stderr.
        elf_rc: ELF exit status.
        elf_err: ELF stderr bytes.

    Returns:
        The verdict with the matched kind as evidence.
    """
    elf_text = elf_err.decode("utf-8", errors="replace")
    if elf_rc == EXIT_OK:
        return CheckResult(path.name, EXPECT_ABORT, False, "ELF exited 0 on abort case")
    if error_kind not in elf_text:
        return CheckResult(path.name, EXPECT_ABORT, False, f"ELF stderr lacks {error_kind!r}: {elf_text!r}")
    return CheckResult(path.name, EXPECT_ABORT, True, f"ELF aborts {error_kind} (oracle skipped)")

The judge still runs CPython on an abort file (a CPython timeout fails it), but the comparison never looks at the result. That makes every abort file a statement in executable form: “here aython differs, and this is how”. The divergences chapter lists them all with what CPython does instead; of the 22 abort files, 15 run to a clean exit under CPython.

Refusals are tests too #

The first principle of the project is that the frontend never guesses: a program outside the subset is refused, naming the feature, before any assembly exists. A refusal that quietly went missing would be the worst kind of bug, because the frontend would then hand the code generator something it was never written for. So refusals are checked like everything else. _check_reject calls frontend.compile_source and passes only when it raises a FrontendError whose message contains aython: unsupported: and the marker’s text; an accepted program, or a refusal for the wrong reason, fails.

A file with no marker at all is treated as pass by parse_expectation. Every file in the corpus has one (0 rely on the default).

Browse the corpus #

Every corpus file is below, with its marker, what the judge asserts, and the evidence from the other side. For pass and error programs that is what CPython printed when this page was built. For abort programs it is what CPython does instead, which the judge never compares. For reject programs it is the refusal the real frontend gives.

The judge's corpus, 290 files. Filter by kind, search names and source (try read_file, class or while), and use the arrow keys in the list. CPython 3.14.4 produced the outputs at build time; no aython executable was run to make this figure. For a pass program the judge requires the ELF to print exactly the bytes shown.

Making the two sides comparable #

A few things a program can do have no direct equivalent on the CPython side, and the judge bridges them rather than leaving them out of the corpus.

  • Arguments. A # mvp-argv: hello world line gives extra arguments to both sides: to the ELF as its process arguments, to CPython as sys.argv[1:] (parse_argv).
  • The I/O builtins. read_file, write_file, append_file and argv are aython builtins that CPython lacks. When a file calls one, the oracle runs it through SHIM_DRIVER, a one-line python3 -c program that installs the four as builtins with the ELF’s semantics and then executes the source under its own path.
  • Relative imports. from . import m only resolves inside a package, and a script run as __main__ is never one. For those files PKG_DRIVER builds a synthetic package rooted at the corpus directory (and its parent, for ..), so the same rule resolves the same sibling file on both sides.
src/aython/judge.py · run_cpythonlines 302–320def run_cpython(source: Path, argv: list[str] | None = None) -> tuple[bytes, bytes, int, bool]:
    """Execute a corpus file under CPython as the oracle.

    Args:
        source: Program ``.py`` file.
        argv: Extra arguments, exposed as ``sys.argv[1:]``.

    Returns:
        ``(stdout, stderr, returncode, timed_out)`` as byte strings.
    """
    extra = list(argv or [])
    if needs_package_shim(source):
        resolved = source.resolve()
        pkgdir = str(resolved.parent)
        parentdir = str(resolved.parent.parent)
        return run_capture([CPYTHON_CMD, "-c", PKG_DRIVER, pkgdir, parentdir, str(source)] + extra, CPYTHON_TIMEOUT_S)
    if extra or needs_shim(source):
        return run_capture([CPYTHON_CMD, "-c", SHIM_DRIVER, str(source)] + extra, CPYTHON_TIMEOUT_S)
    return run_capture([CPYTHON_CMD, str(source)], CPYTHON_TIMEOUT_S)

One difference cannot be bridged: the ELF’s argv()[0] is the path of the executable, while the shim’s is the path of the source. Corpus programs only ever compare argv()[1:].

How the ELF is built #

build_program is the same pipeline aython run uses. The frontend checks the program and returns its tree; the code generator turns that into one assembly file; GNU as assembles it and the runtime; cc links the two objects against libc and libm:

src/aython/judge.py · build_programlines 141–175def build_program(source: Path, runtime_src: Path) -> Path:
    """Compile a source file all the way to an ELF executable.

    Args:
        source: Program ``.py`` file; artifacts land beside it.
        runtime_src: Path to ``runtime.s`` providing ``main``/``arena_init``.

    Returns:
        Path to the linked ``.elf`` executable.

    Raises:
        frontend.FrontendError: If the program is outside the subset.
        subprocess.CalledProcessError: If assembly or linking fails.
    """
    # Resolve so artifact paths are absolute: the kernel execs the ELF
    # directly, and a bare relative name (no directory component) would
    # make execvp search PATH instead of the current directory.
    source = source.resolve()
    runtime_src = runtime_src.resolve()
    text = source.read_text(encoding="utf-8")
    tree, variables, funcs = frontend.compile_source(text, str(source))
    asm_text = codegen.generate(tree, variables, funcs)
    asm_path = source.with_suffix(ASM_SUFFIX)
    obj_path = source.with_suffix(OBJ_SUFFIX)
    elf_path = source.with_suffix(ELF_SUFFIX)
    runtime_obj = elf_path.parent / RUNTIME_OBJ_NAME
    asm_path.write_text(asm_text, encoding="utf-8")
    log.debug("wrote %s (%d vars)", asm_path, len(variables))
    subprocess.run([ASSEMBLER_CMD, "-o", str(obj_path), str(asm_path)], check=True)
    subprocess.run([ASSEMBLER_CMD, "-o", str(runtime_obj), str(runtime_src)], check=True)
    subprocess.run(
        [LINKER_CMD, "-o", str(elf_path), str(obj_path), str(runtime_obj), LINK_MATH_LIB],
        check=True,
    )
    return elf_path
Artifact, beside the source Made by What it is
prog.s.gen codegen.generate The program as x86-64 assembly: main_main plus one fn_* per function
prog.o as -o prog.o prog.s.gen The program’s object file
runtime.o as -o runtime.o runtime.s The hand-written runtime: allocator, objects, print, main
prog.elf cc -o prog.elf prog.o runtime.o -lm A dynamically linked Linux executable; crt calls the runtime’s main, which calls main_main

The runtime is found by find_runtime: an explicit --runtime path first, then runtime.s beside the program, then runtime.s in the current directory. CI passes --runtime runtime.s from the repository root. Linking with cc means crt provides _start and libc provides the write, mmap, open, read, close and _exit wrappers; the allocator, object model and abort spellings stay hand-written. The machine chapter explains what those pieces are.

The leak probe #

Output comparison cannot see a reference-counting mistake. A forgotten aython_decref leaves an object alive with nobody pointing at it; the program still prints the right answer, and only a program that runs long enough to exhaust the arena would ever notice. The judge closes that gap with a second kind of run, aython check --leak.

The idea rests on how the allocator recycles memory (the objects chapter has the detail). A new object header comes from the free list for its kind (ints, floats, strings, lists and tuples, dicts, sets and ranges each have one) if one is waiting, and otherwise from bumping a pointer forward in the 64 MiB arena. When a count reaches zero, the header goes back on its free list; the bump pointer never moves back. So if a program releases everything it allocated, running it a second time in the same process finds every header it needs on the free lists, and the bump pointer does not move at all. If one release is missing, that header never reaches a free list, the second run has to bump for it, and the pointer moves.

The probe runs exactly that experiment. leak_check links the program’s main_main with the runtime and a small harness whose entry point replaces main (cc -Wl,-e,leak_start):

  1. Entered directly at process start: the linker made this the entry point, so crt’s _start never runs. and rsp, -16 clears the low four bits of the stack pointer, so every call below sees the 16-byte alignment the System V ABI requires.
  2. arena_init receives argc 0 and argv NULL (probe programs never read argv) and maps the arena with one mmap. The bump pointer starts at the base.
  3. The program’s body runs. Every int outside the small-int cache needs a header; the free lists are empty, so each one is bumped. On return the epilogue releases every local, and each header goes onto the int free list.
  4. arena_used returns the bump pointer minus the arena base: the bytes consumed so far. The harness parks it in used1, a .bss word, because no register is guaranteed to survive the next call.
  5. The same body again. Each allocation now pops a header off a free list, so nothing is bumped.
  6. arena_used again, compared with used1. Equal: the arena stayed flat, exit status 0. Had one decref been missing, its header would have been stranded in run 1, run 2 would have bumped for it, and jne leak_grew would print leak: arena grew across reruns and exit 1.

CI runs the probe on tests/mvp/pass_leakflat.py:

tests/mvp/pass_leakflat.pylines 1–8# mvp: pass
x = 1000000
y = x * 1000
z = y - x
w = z // 7
v = w % 999983
print(v)
print(w + z)

Every value it computes is above 256, so every one is a real heap header (the small-int cache would otherwise hide them), and every operation it uses is integer arithmetic and print. That restriction is the probe’s one condition: only header-only programs qualify. List item buffers, string bytes and dict entry runs are exact-sized and never reused, by design, so a program that builds a container grows the bump pointer on every run and fails the probe whether or not it leaks.

The fuzzer #

The corpus is written by hand, and a hand-written test only checks what its author thought of. aython fuzz writes programs nobody thought of. Each one is generated from a seed by Fuzzer.program in fuzz.py, built with the judge’s build_program, and compared with CPython by nearly the same rule as a pass or error file, without needing a marker: the generator only ever writes constructs inside the subset.

A random program generator has two problems a corpus does not: its programs must terminate, and both sides must agree on what they mean. The generator solves both by construction, not by timeouts.

Rule How it is kept Why
Every while terminates Always i = 0 … while i < K with K at most 5 and the increment unconditionally last; no if inside the body A counter that always reaches its bound
Every for terminates Iterates a bounded iterable, usually built inline, never a name the body could rebind or grow A bounded number of passes
Calls terminate Later functions call earlier ones only, at most 2 functions Calls form a DAG; recursion stays in the corpus
Ints stay inside 64 bits Literals from -20 to 20, shift counts 0-5, ** exponents 0-4 Only a tall power tower can overflow
No division by zero by accident /, //, % take nonzero literal divisors A failure must be a real disagreement
Floats stay small A fixed pool of small literals: 0.0, 1.5, -2.5, 3.25, 0.5, -0.0, 2.0, 10.25, -7.5, 0.1, 0.2; set elements may also be 1e400 (infinity), whose spelling both sides share Results stay finite in practice, and inf and nan print the same on both sides anyway
Known divergences are avoided chr only up to 127; enumerate/zip/reversed only as for iterables; no argv()[0]; sets hold only small ints, bools, floats, None and int tuples, never strings These differ by design; see the divergences chapter
Strings are ASCII A fixed pool of literals Non-ASCII is refused

Program i of a run uses seed S + i, so the stream is deterministic and any program can be regenerated from its number. This is the first program CI generates, fuzz_0000.py from seed 7, by the real generator at build time (<out> stands for the run’s output directory, where the generator writes its data files):

class B1:
    K1 = 6
    KC = 1
    def g4(self):
        return self.n
    def h5(self, k=8):
        self.n = self.n + k
        return self.n
class C2:
    K2 = ()
    KC = ()
    def __init__(self, a=0):
        self.n = a
    def i6(self):
        return self.n + 1
    def j7(self, k=3):
        self.n = self.n + k
        return self.n
class D3(B1, C2):
    K1 = (2,)
    K3 = 'abc'
    def k8(self):
        return self.g4() + self.i6()
    def w9(self, k=0):
        return self.h5(k) + self.j7(k)
i10 = D3(9)
print(i10.g4())
print(i10.k8())
print(i10.w9())
print(i10.n)
print(i10.K1)
print(i10.KC)
print(i10.K3)
for x11 in {3: (-17 >> 4), 17: (14 ** 3)}:
    t12 = ((-5 // -15), (-2 | -16), x11, x11)
    f13 = read_file('<out>/fuzz_data_1.txt')
t14 = ((-15 - -3), (-16 ** 0), (16 % 9), (2 & -19))
s15 = 'abc'
t16 = ((5 // 6), (-15 ^ -10))

and what CPython prints for it, which the ELF must match byte for byte:

9
19
18
9
(2,)
1
abc

Nothing in it was chosen by a person: the seed picked every statement, name and literal, and the generator’s bookkeeping (which names hold ints, how long each list is, which keys a dict has) kept every operation inside the subset and every value inside the range both sides agree on.

compare_runs sorts each generated program into one of four buckets:

src/aython/fuzz.py · compare_runslines 3051–3095def compare_runs(
    elf_out: bytes,
    elf_rc: int,
    elf_err: bytes,
    py_out: bytes,
    py_rc: int,
    py_err: bytes,
    elf_timed_out: bool = False,
    py_timed_out: bool = False,
) -> tuple[bool, str, str]:
    """Judge one ELF-vs-CPython pair without a corpus marker.

    Args:
        elf_out: ELF stdout bytes.
        elf_rc: ELF exit status.
        elf_err: ELF stderr bytes.
        py_out: CPython stdout bytes.
        py_rc: CPython exit status.
        py_err: CPython stderr bytes.
        elf_timed_out: True if the ELF hit the timeout.
        py_timed_out: True if CPython hit the timeout.

    Returns:
        ``(ok, bucket, detail)`` where bucket is one of ``pass``,
        ``both-abort``, ``known-divergence`` (documented bigint gap),
        or ``mismatch``.
    """
    if elf_timed_out or py_timed_out:
        return False, "mismatch", "timeout (non-termination?)"
    if elf_rc == EXIT_OK and py_rc == EXIT_OK:
        if elf_out == py_out:
            return True, "pass", f"{len(elf_out)} stdout bytes match"
        return False, "mismatch", f"stdout differs: {elf_out!r} vs {py_out!r}"
    if elf_rc != EXIT_OK and py_rc != EXIT_OK:
        elf_kind = extract_kind("elf", elf_err)
        py_kind = extract_kind("py", py_err)
        if elf_kind and elf_kind == py_kind:
            return True, "both-abort", f"both abort {elf_kind}"
        return False, "mismatch", f"error kinds differ: ELF {elf_kind!r} vs CPython {py_kind!r}"
    if elf_rc != EXIT_OK and py_rc == EXIT_OK:
        elf_kind = extract_kind("elf", elf_err)
        if elf_kind == KNOWN_DIVERGENCE:
            return True, "known-divergence", "i64 overflow aborts where CPython bigints on"
        return False, "mismatch", f"ELF aborts ({elf_kind!r}) where CPython exits 0"
    return False, "mismatch", "ELF exits 0 where CPython fails"
Bucket Condition Counts as
pass Both exit 0, identical stdout ok
both-abort Both exit non-zero, and the ELF’s aython: <Kind> names the kind on the last line of CPython’s traceback ok
known-divergence Only the ELF fails, with OverflowError ok: the 64-bit integer limit
mismatch Anything else, including a timeout, a frontend refusal or a toolchain failure failure: the run stops and prints the seed and a uv run aython check ... line to reproduce it

CI runs the fuzzer 2 times, 250 programs in all: 150 from seed 7 and 100 from seed 4242. Replaying those same programs under CPython while this page was built, 207 ran to exit 0 and 43 ended in an error (17 TypeError, 8 FileNotFoundError, 6 ValueError, 4 MemoryError, 3 ZeroDivisionError, 3 KeyError, 1 RecursionError, 1 RuntimeError). Those are the programs that must land in both-abort: the generator deliberately writes a final uncaught raise of an int, read_file of a missing path, and raise statements in try bodies whose handlers may not match the kind.

CI, end to end #

Every push and pull request runs one job, .github/workflows/ci.yml, on ubuntu-latest: native x86-64 Linux, the only platform the ELFs run on. Its steps, in order:

# Step Commands What it catches
1 Install the locked dependencies uv sync Nothing by itself; every later step runs through uv run
2 Differential judge over every corpus file, by its # mvp: marker uv run aython check tests/mvp/*.py --runtime runtime.s Wrong output, wrong exit status, wrong error kind, a refusal that went missing
3 Arena-flatness probe: run main_main twice in one process uv run aython check --leak tests/mvp/pass_leakflat.py --runtime… A missing decref that strands a header outside the free lists
4 Self-hosted reader: build parser/dump.s, copy files through it as -o /tmp/dump.o parser/dump.s
/tmp/dump.elf parser/dump.s
A reader that drops, reorders or invents bytes, or exits 0 on a missing file
5 Self-hosted tokenizer: parser/tok.s against aython tokdump on every corpus file as -o /tmp/tok.o parser/tok.s
for f in tests/mvp/*.py tests/mvp/inc_dotpkg/*.py
Any token line that differs from the Python reference tokenizer
6 Self-hosted parser: parser/parse.s against aython sexpdump on every corpus file as -o /tmp/parse.o parser/parse.s
set +e
A tree that prints differently, or one side refusing what the other accepts
7 Self-hosted emitter: host codegen against parser/emit.s, both assembled and run bash parser/emitdiff.sh Different stdout or exit status between the two emitters’ executables
8 Seeded differential fuzzer uv run aython fuzz --count 150 --seed 7
uv run aython fuzz --count 100 --seed 4242
Mismatches on programs nobody wrote by hand
9 Stdlib census with a floor uv run aython stdlib-census --min-accepted 31 A change that makes the frontend refuse stdlib files it used to accept
10 Build this site uv run docsite build --out build/site A page quoting a helper, label or file that no longer exists; a broken link
11 Benchmark harness smoke test: two programs, one round uv run aython bench --quick A harness that no longer builds or runs; never a slow result
flowchart LR
  corpus["corpus<br/>aython check"] --> leak["leak probe"]
  leak --> parser["self-hosted reader,<br/>tokenizer, parser,<br/>emitter diffs"]
  parser --> fuzz["fuzzer<br/>250 programs"]
  fuzz --> census["stdlib census<br/>floor 31"]
  census --> site["docsite build"]
  site --> bench["bench --quick"]
  class corpus,leak,fuzz accent
The order of the CI job. Each box is one or more steps; a failing step fails the job.

The steps between the leak probe and the fuzzer compare the self-hosted parser track against its references, the same differential idea applied to the assembly tokenizer and parser: aython tokdump and aython sexpdump print the reference token stream and tree for every corpus file, and the assembly versions must print the same bytes. The census step fails if the frontend accepts fewer than 31 files of CPython’s own standard library, so a change that narrows the subset cannot land unnoticed (the census chapter). Building this site is a test as well: a page that quotes a runtime helper, a generated label or a corpus file that no longer exists stops the build. The last step only checks that the benchmark harness still builds and runs; timing on a shared runner is noise, so CI never reads a number (the speed chapter).

What the judge does not see #

A test that has never been described as incomplete is not trustworthy. These are the things a green CI run does not establish:

  • Stderr beyond the kind. The error message, and CPython’s traceback, are never compared.
  • Exit statuses other than zero and non-zero. A pass case must exit 0 and an error case non-zero, so exit(3) cannot be a corpus case; docs/core-design.md records that it was checked by hand.
  • The CPython side of an abort case. By definition.
  • A divergence where aython succeeds and CPython fails. No marker fits: abort needs the ELF to fail. The one recorded case, a store on a __slots__-only instance (issue #72), is therefore not in the corpus at all.
  • Leaks in programs that use containers. The probe only works on header-only programs, and CI runs it on one file.
  • Which CPython. The oracle is whatever python3 is on the runner’s PATH; the judge does not pin a version.
  • Speed. Correctness only; timing is a separate, manual measurement.

Where this lives #

Concept Where
The verdict for one file src/aython/judge.py check_file, CheckResult
Markers and arguments parse_expectation, parse_argv, MARKER_PREFIX, ARGV_MARKER_PREFIX
The per-kind checks _check_pass, _check_error, _check_abort, _check_reject
The CPython oracle and its shims run_cpython, SHIM_DRIVER, PKG_DRIVER, needs_shim, needs_package_shim
Building the ELF build_program, find_runtime
The leak probe leak_check, LEAK_HARNESS_ASM; runtime.s arena_used, arena_init
The command line src/aython/cli.py check, fuzz
The corpus tests/mvp/
The fuzzer src/aython/fuzz.py Fuzzer, compare_runs, check_source, fuzz
CI .github/workflows/ci.yml
The correctness rule in prose docs/core-design.md Correctness policy, Phase 1
This page’s data docsite/figures/judgecorpus.py, docsite/figures/judgeci.py

Check yourself #

Check yourself

  1. A # mvp: pass program prints exactly CPython’s output, then the ELF exits with status 1. What does aython check report?

    1. ok: the stdout bytes match
    2. FAIL with ELF exit 1
    3. ok, with a warning about the exit status
    AnswerFAIL with ELF exit 1. _check_pass tests the ELF’s exit status before it compares output. A non-zero status fails the case whatever was printed.
  2. print(2**62 * 4) is in the corpus. Why is it marked abort:OverflowError and not error:OverflowError?

    1. Because CPython also raises OverflowError
    2. Because CPython prints 18446744073709551616 and exits 0, so the error check, which needs both sides to fail, could never pass
    3. Because the judge does not run CPython on overflow cases
    AnswerBecause CPython prints 18446744073709551616 and exits 0, so the error check, which needs both sides to fail, could never pass. error requires both sides to exit non-zero naming the kind. Here only aython fails, so the case is an abort: the ELF side is pinned and CPython’s result is ignored.
  3. The leak probe runs main_main twice in one process. What must be true for it to pass?

    1. No object is still allocated when the process exits
    2. arena_used returns the same value after the second run as after the first
    3. The second run prints the same output as the first
    Answerarena_used returns the same value after the second run as after the first. Freed headers go to free lists and their bump bytes stay consumed, so a live count is never zero. If every header was released, the second run reuses them all and the bump pointer does not move.
  4. CI’s second fuzz step is aython fuzz --count 100 --seed 4242. It fails on fuzz_0042.py. Which seed generated that program?

    1. 42
    2. 4242
    3. 4284
    Answer4284. Program i of a run uses seed S + i: 4242 + 42 = 4284. fuzz logs that seed and a uv run aython check line to reproduce it.
  5. Why does the fuzzer only use enumerate(...) as the iterable of a for loop, never as a printed value?

    1. enumerate is refused by the frontend outside for
    2. aython’s enumerate builds a list, so printing it shows the list where CPython shows an iterator object
    3. Printing would make the program too long
    Answeraython’s enumerate builds a list, so printing it shows the list where CPython shows an iterator object. Inside a for both sides iterate the same pairs. Printed, CPython spells <enumerate object at 0x...>; that is a recorded divergence, not a bug to find.