Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This repository contains Lean 4 compiler backends released together as leanfran.
- `maint/`: repository maintenance, version management, differential tests and extern-list generators.
- `.github/`: CI and release automation.
- `lakefile.toml`, `Main.lean`: the Lake package of the compiler. It links the library of every backend into the one executable `leanfran`, and `Main.lean` passes the arguments to the backend that `--lang` names.
- `Leanfran/`: the compiler's shared Lean library. `Leanfran/Embed/` runs `sync`, `check` and `status` for Rust, C, Clojure, Go, Python, TypeScript and PHP, and `Leanfran/Generate.lean` runs `leanfran generate`.
- `Leanfran/`: the compiler's shared Lean library. `Leanfran/Embed/` runs `sync`, `check` and `status` for all seven backends, and `Leanfran/Generate.lean` runs `leanfran generate`.
- `flake.nix`, `flake.lock`, `lean-toolchain`: shared development dependencies, the compiler package and Lean version.
- `LICENSE`: the Apache-2.0 text for the entire repository. Package builds include this file in their artifacts.

Expand All @@ -20,10 +20,10 @@ This repository contains Lean 4 compiler backends released together as leanfran.
- Settings of a project are the tables of `leanfran.toml`, which `Leanfran/Config.lean` reads and passes to the language packages. The first line of a generated file is that of `Leanfran/Header.lean`.
- Add runtime behavior to the backend's native-oracle differential tests; compare the generated program with Lean's C backend.
- Regenerate runtime extern lists with the backend's `make gen-externs` where available.
- Embedded Lean blocks of Rust, C, Clojure, Go, Python, TypeScript and PHP go through `Leanfran.Embed`. A backend supplies a `Leanfran.Embed.Backend` value (`Lean<X>/Embed.lean`, `LeanC/Embed/Backend.lean`), and its language package supplies the runtime and the `scan` and `translate` commands that the compiler runs. Change the shared flow in `Leanfran/Embed/` and check it with `maint/test-embed.sh`; `maint/test-csimp.sh` checks the functions that replace their specs in the generated code.
- Embedded Lean blocks of every backend go through `Leanfran.Embed`. A backend supplies a `Leanfran.Embed.Backend` value (`Lean<X>/Embed.lean`, `LeanC/Embed/Backend.lean`), and its language package supplies the runtime and the `scan` and `translate` commands that the compiler runs. Change the shared flow in `Leanfran/Embed/` and check it with `maint/test-embed.sh`; `maint/test-csimp.sh` checks the functions that replace their specs in the generated code.
- When generated code changes, update both the emitter's generator version and its host-side freshness version together, once between two releases. `leanfran.manifest.json` and `leanfran.lock` record the generator version and the Lean version of each language. The C backend has one `generatorVersion`; raise it when the generated C, the block workspace, the C translation, or the obligations change.
- Keep shared development rules here and backend implementation details in `docs/`.
- The guides, the language READMEs and the development guides have the sections and the words that `docs/add-language.md` lists. `maint/C/test-samples.sh` compares code of `docs/c-guide.md` with the samples, and the version scripts edit the versions in `docs/rust-guide.md` and the READMEs of Rust and Clojure.
- The guides, the language READMEs and the development guides have the sections and the words that `docs/add-language.md` lists. Every `langs/<Language>/samples/Makefile` has `test` and `verify` targets; `maint/test-make-targets.sh` checks them. `maint/C/test-samples.sh` compares code of `docs/c-guide.md` with the samples, and the version scripts edit the versions in `docs/rust-guide.md` and the READMEs of Rust and Clojure.

## Verification and releases

Expand Down
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Follow the [Go quick start](langs/Go/README.md) to add the Go module and tool to

### Embedded Lean blocks

In Python, TypeScript, PHP, Go, and C, Lean blocks live in your source files. The host package reads them, and the compiler builds and generates them with three commands:
In all seven languages, Lean blocks live in your source files. The host package reads them, and the compiler builds and generates them with three commands:

| Command | Effect |
| --- | --- |
Expand All @@ -145,7 +145,7 @@ In Python, TypeScript, PHP, Go, and C, Lean blocks live in your source files. Th

`leanfran sync`, `leanfran check` and `leanfran status` without `--lang` run the command for every `[embed.<language>]` table of `leanfran.toml` in their order, and exit with the largest code. The [settings of `sync`, `check` and `status`](docs/generate-guide.md#settings-of-sync-check-and-status) describe the tables and projects with several languages.

`--dir <dir>` selects the project directory and defaults to the working directory. The project root is the nearest directory from there upwards with `leanfran.toml`, or else with the package file of the language (`pyproject.toml`, `package.json`, `composer.json`, or `go.mod`). `leanfran --lang <language> <command> --help` lists the options of a command. Commit `leanfran.manifest.json` and `leanfran.lock`, which are at the project root, and the generated files; C keeps its output directory out of version control because its link settings hold absolute paths. `sync` keeps each language's Lake workspace in `.leanfran/<language>/` and writes `.leanfran/.gitignore`, which excludes that workspace and the lock file `.leanfran/lock`; commit `.leanfran/.gitignore` too.
`--dir <dir>` selects the project directory and defaults to the working directory. The project root is the nearest directory from there upwards with `leanfran.toml`, or else with the package file of the language (`Cargo.toml`, `pyproject.toml`, `package.json`, `deps.edn`, `composer.json`, or `go.mod`). `leanfran --lang <language> <command> --help` lists the options of a command. Commit `leanfran.manifest.json` and `leanfran.lock`, which are at the project root, and the generated files; C keeps its output directory out of version control because its link settings hold absolute paths. `sync` keeps each language's Lake workspace in `.leanfran/<language>/workspace` and writes `.leanfran/.gitignore`, which excludes that workspace and the lock file `.leanfran/lock`; commit `.leanfran/.gitignore` too.

| Exit code | Meaning |
| --- | --- |
Expand Down Expand Up @@ -180,7 +180,7 @@ In each project:
1. Upgrade the compiler and the host package to the same release.
2. Move the settings to `leanfran.toml` as the [settings table](#settings-from-0150) says.
3. Rename the labels, options and theorems of the [source table](#sources-from-0150).
4. Run `leanfran --lang <language> sync`, then `check` for a project with verified functions, and commit the result. Until then, `status` reports every block and function as `stale`. A Rust crate follows the [Rust table](#rust-from-0150).
4. Follow the [Rust](#rust-from-0150) or [Clojure](#clojure-from-0150) migration if applicable. Run `leanfran --lang <language> sync`, then `check` for a project with verified functions, and commit the result. Until then, `status` reports the old entries as stale.

#### Settings from 0.15.0

Expand Down Expand Up @@ -229,26 +229,38 @@ Settings left in an old place of TypeScript, PHP, Go, C or Rust exit with 254 an
| A function or a specification that throws or panics | Different in each language | `failed: <exception>` as the value of the function, or `the spec failed` and `error: <exception>` |
| Few inputs satisfy `requires` | Different in each language | Fails with `<id>: only <n> of <m> inputs satisfied requires (seed <seed>)` after 100 discarded inputs per run |

The random test of Clojure has no label. With PHP, `Verify::checkModel` takes `?int $runs = null, ?int $seed = null`.
With PHP, `Verify::checkModel` takes `?int $runs = null, ?int $seed = null`.

#### Rust from 0.15.0

| | 0.15.0 | Now |
| --- | --- | --- |
| `leanfran.lock` | TOML in the crate | The section `rust` of the JSON `leanfran.lock` in the directory of `leanfran.toml`, or else in the crate. A file that is not JSON exits with 254: delete it and run `cargo leanfran extract` and `cargo leanfran check` |
| `leanfran.lock` | TOML in the crate | The `rust` section of the JSON lock in the project root. Remove the TOML lock and regenerate it with `leanfran --lang rust check`; the compiler rejects a non-JSON lock with exit code 254 |
| Generated code of `lean!` | `.leanfran/cache/` | `.leanfran/rust/cache/`. Change `include` of `Cargo.toml` |
| Row of `cargo leanfran status` | `<function>` and ` <label> <state>` lines | `<function> [<label>]: <state>`, and `<function>: removed` for a function only in the lock |
| Generated Lean package | `lean/lakefile.toml`, `lean/lean-toolchain` and `lean/LeanRustGen/` | Remove those generated files. The disposable workspace is `.leanfran/rust/workspace/`; move additional Lake dependencies into `[[require]]` and a shared package directory into `[lake] packages-dir` |
| Handwritten Lean | `lean/Proofs/`, `lean/External.lean`, `lean/ExternalTypes.lean` | Keep `lean/Proofs/` at the project root, move both external files into it and use the `Proofs.External` and `Proofs.ExternalTypes` imports |
| Function IDs and status rows | `crate::<module>::<function>`; function and obligation on separate lines | `<crate_name>::<module>::<function> [<label>]: <state>`, and `<id>: removed` for a function only in the lock |
| State of an unjudged obligation | `unchecked` | `stale` |
| Function without obligations | `model only` | No row |
| A Lean file in `lean/` changed since `check` | Not detected | `stale`. With `[check] require = "proved"`, `cargo build` fails until `cargo leanfran check` runs again |
| A proof file changed since `check` | Not detected | `status` reports `stale`. Put the proof gate in CI with `leanfran --lang rust check --require proved`; it does not run in `cargo build`, which also no longer shows proof warnings or proof status in rustdoc |
| Rust version | 1.88 | 1.88, and 1.89 for `cargo-leanfran` |
| A spec of other types than its function, a wrong label of `ensures`, a generic function without `instances` | A rustc error that stops the build | The crate builds. `check` and `status` give the state that Lean finds, `unextracted` for a wrong label, and only the test of the function fails ([Functions of other types than their specs](docs/generate-guide.md#functions-of-other-types-than-their-specs)) |

#### Clojure from 0.15.0

| | 0.15.0 | Now |
| --- | --- | --- |
| Workspace and output | `.leanfran/`, with cached Clojure in `.leanfran/cache/` | Remove the old generated Lake files and cache. Keep `.leanfran/clojure/workspace/` out of Git; commit the generated `_lean/` next to each namespace and the manifest and lock at the project root |
| Handwritten Lean | Lean sources alongside the old Lake workspace | Keep proofs in `lean/Proofs/` (module prefix `Proofs`); put reusable Lean modules in a separate Lake package and list it in `[[require]]` |
| Lock and function IDs | No lock-based proof status | The `clojure` section of `leanfran.lock` records function IDs as `<namespace>/<function>`, shown by `leanfran --lang clojure status` |

#### Commands, JSON, environment and exit codes from 0.15.0

| Commands and options | 0.15.0 | Now |
| --- | --- | --- |
| Project directory of `sync`, `check` and `status` in Python, TypeScript and PHP | `--package <dir>`, required in Python and TypeScript | `--dir <dir>`, the working directory by default |
| Rust embedded blocks and proof status | `cargo leanfran init`, `extract`, `check` and `status` | `leanfran --lang rust sync`, `check` and `status`. Install `cargo-leanfran` for the compiler to scan and translate Rust |
| Clojure embedded blocks and proof status | `deflean` generates the block on load | `leanfran --lang clojure sync`, `check` and `status`. `deflean` loads the generated code |
| Build a Lake package and generate its modules in Rust, TypeScript and Clojure | `project generate`, TypeScript `generate` | A `[[generate]]` table of `leanfran.toml` and `leanfran generate` |
| Rust proof check | `crate check --lake-dir <dir>` | `obligations check --lake-dir <dir>` |
| Clojure generation | `module generate-namespace --namespace <ns> --strip-namespace <Name>` | `module generate --clojure-namespace <ns> --namespace <Name>` |
Expand All @@ -259,7 +271,7 @@ The random test of Clojure has no label. With PHP, `Verify::checkModel` takes `?
| Types defined outside the module in Rust | `--type-path <Name>=<path>` | `--type-module <Name>=<path>` |
| Lean version of the compiler | `--lang go --lean-version` | `--version`, which prints `leanfran <version> (Lean <version>)` with and without `--lang` |
| Usage | `help`, `module help` | `--help` or `-h` after `leanfran`, after `--lang <language>` and after each command |
| `cargo leanfran --version` | `cargo-leanfran <version>` | `leanfran <version> (Lean <version>)` |
| Rust CLI version | `cargo leanfran --version` prints `cargo-leanfran <version>` | `leanfran --lang rust --version` prints `leanfran <version> (Lean <version>)` |
| Arguments of a command | Rust, Python, TypeScript and Clojure accept the options of another command, and the last value of a repeated option counts | An option that the command does not list, or a repeated one with a single value, exits with 252 |

| JSON of `module generate` | 0.15.0 | Now |
Expand All @@ -273,8 +285,9 @@ The random test of Clojure has no label. With PHP, `Verify::checkModel` takes `?
| Environment variable | 0.15.0 | Now |
| --- | --- | --- |
| Automatic `sync` of the Python and TypeScript runtimes | `LEANFRAN_PYTHON_AUTO_SYNC`, `LEANFRAN_TS_AUTO_SYNC` | `LEANFRAN_AUTO_SYNC` |
| Clojure workspace | `LEANFRAN_CLJ_WORKSPACE` | None |
| `lake` of Rust `lean!` | `lake` on PATH | `LAKE`, or `lake` on PATH |
| Clojure workspace | `LEANFRAN_CLJ_WORKSPACE` (earlier development builds: `LEANFRAN_CLOJURE_WORKSPACE`) | No workspace override; use `leanfran.toml` for the project and Lake settings |
| Rust build | `LEANFRAN_OFFLINE`, `LEANFRAN_REQUIRE` | No offline flag or build-time proof gate. The build uses the committed code; opt in to generation with `LEANFRAN_AUTO_SYNC=1` |
| Lake executable | `lake` on PATH for Rust `lean!` | `LAKE`, or `lake` on PATH |

| Exit code | 0.15.0 | Now |
| --- | --- | --- |
Expand All @@ -286,9 +299,9 @@ The random test of Clojure has no label. With PHP, `Verify::checkModel` takes `?
| `leanfran generate` with an invalid `leanfran.toml` | 252 | 254 |
| Several failed `--batch` jobs | The first code in Python, TypeScript, PHP and Go | The largest code |
| An error such as an output file that cannot be written, in Clojure | 254 | 255 |
| `cargo leanfran` with invalid arguments | 2 | 252 |
| `cargo leanfran` with an error in the project or the environment | 1 | 254 or 255 |
| `cargo leanfran status` with a `stale`, `failed`, `unextracted` or `removed` function | 0 | 1 |
| Rust CLI with invalid arguments | `cargo leanfran` exits with 2 | `leanfran --lang rust` exits with 252 |
| Rust CLI with a project or environment error | `cargo leanfran` exits with 1 | `leanfran --lang rust` exits with 254 or 255 |
| Rust status with a `stale`, `failed`, `unextracted` or `removed` function | `cargo leanfran status` exits with 0 | `leanfran --lang rust status` exits with 1 |

Messages start with `leanfran: ` in every language, where 0.15.0 writes `leanfran --lang <language>: `, `leanfran-go: `, `cargo leanfran: ` and others. Errors with a position start with `<file>:<line>:<column>: error: `, also for a function that cannot be translated (`error: unextracted <id>: <message>`).

Expand Down
Loading
Loading