# Maintaining Lean and Lynx toolchains

The resolved Lynx Hex package's `lean-toolchain` file specifies the required Lean version.
Updating Elan and installing a Lean toolchain are separate operations.

## Release compatibility

The initial experimental release targets Mix projects. Verification uses the
active Mix project's dependency paths and requires `lake` on `PATH`.

The release check uses Linux x86-64, Elixir 1.20.5, OTP 29.1.2, Lynx 0.2.0 and
Lean 4.36.0. The Mix version constraint admits other Elixir 1.x releases from
1.20 onward. Consult the release checks for the combinations actually tested.
Standalone BEAM releases are outside the supported execution context.

ReductionBounds accepts Lynx 0.2.x. Install the Lean version named in the
resolved Lynx package, since a consuming application resolves dependencies
independently of this repository's lockfile.

## Updating Elan

If Elan was installed with the official installer:

```sh
elan self update
elan --version
```

For a package-manager installation, update through that package manager.
See the [Elan toolchain documentation](https://lean-lang.org/doc/reference/latest/Build-Tools-and-Distribution/Managing-Toolchains-with-Elan/).

## Updating Lynx and its Lean toolchain

When you choose to update Lynx, run the following commands from your
project's root. Re-read `lean-toolchain` after updating the dependency,
because the required Lean version may have changed.

```sh
mix deps.update lynx
export ELAN_TOOLCHAIN="$(cat deps/lynx/lean-toolchain)"
elan toolchain install "$ELAN_TOOLCHAIN"
lean --version
lake --version
mix compile
mix test
```

Review and commit the resulting `mix.lock` changes after checking
compatibility with your project. Installing a newer Lean toolchain alone
does not update Lynx or verify compatibility with ReductionBounds.

The Lynx Hex version recorded in `mix.lock` is integrated through
the translation adapter, which uses Lynx's Core translation and module
assembly interfaces. The runner adapter uses the Lynx Lake executable and
its JSON verification protocol. Public report types reference
[`Lynx.Laws.report/0`](https://hexdocs.pm/lynx/0.2.0/Lynx.Laws.html#t:report/0).
Recheck these interfaces before widening the dependency constraint. This keeps ReductionBounds proof blocks separate
from Lynx's Core translation state. The runner adapter sends source modules
without caller-supplied cache keys, retains the original diagnostic locations,
and audits their axioms before accepting them. Persistent keys are computed by
Lynx. For `cache: :shared`, cached shared modules and uncached consumers run in
separate requests, exchanging compiled artifacts in a temporary directory.
That directory is passed through the child process environment, without
changing the parent VM's `LEAN_PATH`. Lynx verifies independent ready modules in
parallel inside each request; the adapter still uses fresh processes and does
not integrate reusable sessions. See [shared proof modules](shared_proofs.md)
for the current protocol and [the optimization review](runner_optimization_review.md)
for the scope of historical measurements.

## Working in this repository

The tracked `lean-toolchain` file selects the project toolchain when
`ELAN_TOOLCHAIN` is unset. After fetching dependencies, check that it agrees
with Lynx:

```sh
cmp lean-toolchain deps/lynx/lean-toolchain
elan toolchain install "$(cat lean-toolchain)"
```

When intentionally updating Lynx in this repository, synchronize the
tracked toolchain file after checking compatibility, and commit it with
the corresponding lockfile change. The environment-variable commands
above remain useful in consuming projects without a matching project
file, and an explicit `ELAN_TOOLCHAIN` takes precedence over that file.
