An Agda backend to generate MetaCoq λ□ (LambdaBox) programs for further verified extraction to WASM or Rust using the Peregrine tool. The backend builds off Agda 2.9.0.
To install the backend, setup GHC (tested with 9.10.1) and cabal.
git clone git@github.com:agda/agda2lambox.git
cd agda2lambox
cabal install
agda2lambox [AGDAFLAGS] [--out-dir DIR] [--typed] [--rocq] [--export-all] FILE
Only the definitions reachable from those marked with {-# COMPILE AGDA2LAMBOX f #-} get compiled; to extract a library instead, --export-all compiles the whole module.
Then, use the following tool to further compile the generated .ast files to WASM, C, LLVM, OCaml, CakeML, Rust, Koka, Lean and F#.
With --rocq, the backend also generates a .v file that checks the well-formedness of the λ□ program and evaluates it in Rocq, and --typed generates typed λ□ instead (which Peregrine needs for Rust and typed Koka).
See HACKING.md for an overview of the implementation.
The test modules live in test/agda2lambox, test/agda2rust and test/agda2hs; each defines an
entry point test, marked with {-# COMPILE AGDA2LAMBOX test #-}, and states its expected value
as _ : test ≡ v.
make testcompiles every module to untyped and typed λ□ undertest/dist/, and validates both withperegrine validate.make gencompiles λ□ to every Peregrine target undertest/gen/.make runevaluates λ□ in Rocq, runs every target's output, and tallies the results intest/gen/stats.log.make htmlrenders the test modules and all of their outputs as a website undertest/html/.
The last three are thin wrappers around test/targets.sh, which lists the tools each target needs.
Evaluating λ□ in Rocq needs the Rocq, MetaRocq and CertiRocq versions that Peregrine is built with
(c.f. the pinned commit in CI), as well as compiling the theories in theories/ with make coq.
- The MetaCoq Project
- The CertiCoq Compilation pipeline
- CertiCoqWASM
- Pierre Letouzey's thesis introducing λ□ (in French)
- Verified Extraction from Coq to OCaml and its accompanying paper
- Certified Erasure for Coq, in Coq
- Extracting functional programs from Coq, in Coq
- Lambdabox syntax and untyped environments
- Lambdabox typed environments
- Coq Extraction Pipeline
- Extraction Example