Guide

Contributing

Proving a new kernel

docs/new-kernel.md follows one kernel from its Mojo source to its kernel theorem: compiling it, adding it to the corpus, importing it, writing its specification and running mojo_kernel. docs/kernel.md and docs/tactics.md are the reference for the command and the tactics. AGENTS.md has the same steps and the rules below as a checklist for automated agents.

Building and checking

You need elan (it installs the toolchain that lean-toolchain names, Lean 4 v4.36.0), git and python3. Mojo is needed only to add a kernel to the corpus, and graphviz 2.44.0 (dot) only to regenerate or check the dependency documents: deps.py check compares the rendered SVGs byte for byte, and they record that version.

lake exe cache get        # prebuilt Mathlib files
lake build                # the default targets: GPUProof, MojoProof and MojoProofKernels
lake build MojoProofTest  # every test module
lake test                 # the test runner mojoproof_test
lake env lean --run scripts/Audit.lean
python3 scripts/cited.py
python3 scripts/corpus.py check

What each one checks:

The audit exits with an error only for an axiom or when one of its probes fails: the equivalences probe (it must count the public @[csimp] equality of MojoProofTest.AuditProbe and the iff between its two inductive predicates, and not the equality whose right-hand side is private), the laws probe (with rows that exempt the pair (double, twice), it must count double_and, the law with a further equation, and not double_twice, and a row with another statement's fingerprint or pair must be stale), the duplicates probe (the two statements that differ through an abbrev must pair) and the instances probe (outS_eight must be reported and outS_eight_of_lt not). The counts it prints have limits in scripts/counts.tsv, which are all 0 except laws, at 7, and instances_tests, at 1; if a count drops below its limit, lower the limit. near_dups and width_families in that file are the near-duplicate clusters and width families counts that scripts/near_dups.py prints. python3 scripts/counts.py <audit output> <near_dups output> checks every limit and exits 1 if a count exceeds its limit or is missing; CI saves the two outputs and runs it.

After a change that adds, deletes or moves declarations or imports, regenerate the dependency documents and check them:

lake env lean --run scripts/Audit.lean --deps /tmp/facts.json
python3 scripts/deps.py write /tmp/facts.json
python3 scripts/deps.py check /tmp/facts.json

Adding a kernel to the corpus

  1. Compile the Mojo source to per-kernel LLVM IR. The corpus was compiled with the Mojo version that scripts/corpus.py records (MOJO, 1.3.0.dev2026111705); with another version, pass it to add with --mojo in step 2. In the source's directory:

    mojo build --emit llvm --target-accelerator sm_80 -o <name>.ll <name>.mojo
    

    This writes one *.nvptx.ll file per kernel specialization. Pass any other flags you need, for example --fp-mode contract=off, and record them in step 2.

  2. Add the files and their manifest rows:

    python3 scripts/corpus.py add [--mojo "<version>"] [--lib PATHS] <family> <src.mojo> <source-path> "<flags>" <file.nvptx.ll>...
    

    This copies each file to tests/corpus/<family>/ and writes its MANIFEST.tsv row:

    • path, sha256 and line count;
    • the one ptx_kernel define;
    • the arch and PTX version, from the file's attributes;
    • the Mojo version (--mojo, else MOJO);
    • <flags>, which must be the exact flags passed to mojo build (for example --emit llvm --target-accelerator sm_80);
    • the source and the source's sha256;
    • --lib PATHS: the library files that define the kernel, read from the source's imports (comma-separated .mojo paths; -, the default, when the source defines it).

    <source-path> is the source's path in the modular repository at the commit corpus.py records (MODULAR). For a source kept in this repository, write repo:<path> instead, with <path> relative to the repository root; check then also compares that source's sha256.

    Add the source to tests/corpus/NOTICE, with its commit and its license. Read the license in the source's header: the corpus takes only sources under the Apache License v2.0 with LLVM Exceptions, whose text is tests/corpus/LICENSE-APACHE-LLVM. corpus.py add refuses a source whose header lacks the Apache-LLVM line, before it copies anything. A source kept in this repository that is a modified copy of a Modular file keeps that file's header and says what was changed.

  3. Run python3 scripts/corpus.py check and lake test. A file the importer refuses must be listed in tests/corpus/REFUSALS.tsv with the exact reason the test prints. A refusal that is not listed, or a listed one that does not occur, fails the test. A new row also changes the counts that MojoProofTest/Corpus.lean's #mojo_corpus test expects (rows, imported, refused): update its /-- info: ... -/ line, or lake build MojoProofTest fails there.

  4. To state theorems about the kernel, import it as a Lean term with mojo_corpus in MojoProof/Kernels.lean (the order of the arguments fixes which import names a shared function). Or use mojo_import "<family>/<file>" as <name>. Both check the digest against the manifest at every build.

Rules a change must meet

The website

The website, https://robertboy18.github.io/MojoProof/, is built from the repository's own files by scripts/site.py: the README, the roadmap with every card, this guide and every document of docs/. To build it and check it locally:

pip install -r scripts/site-requirements.txt   # markdown and pygments
python3 scripts/roadmap_status.py              # if a card or a declaration it names changed
python3 scripts/site.py --out _site
python3 scripts/site.py --check _site          # every link, anchor and image resolves

Then open _site/index.html in a browser, as a file. CI builds and checks the site on every pull request, and rebuilds and publishes it from main when the pull request is merged.

Where things live