Skip to content

feat: add lake check to check a project against external checkers - #14990

Open
Kha wants to merge 2 commits into
masterfrom
lake-check-cmd
Open

feat: add lake check to check a project against external checkers#14990
Kha wants to merge 2 commits into
masterfrom
lake-check-cmd

Conversation

@Kha

@Kha Kha commented Sep 1, 2026

Copy link
Copy Markdown
Member

This PR adds lake check, a challenge-less variant of lake challenge, which builds the current project's default targets, exports them, replays the result through the kernel, and fails on any use of non-standard axioms.

Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com

Kha and others added 2 commits September 1, 2026 14:18
This PR adds a `modules` facet to packages, so `lake query :modules` reports the Lean modules of a package's default targets: the modules of each default library, and the root of each default executable together with its local transitive imports. A default target that builds no Lean modules, such as a custom target, contributes nothing.

Libraries have had a `modules` facet for some time. This is its package-level counterpart, and like it the facet is not buildable, so it is reached through `lake query` rather than `lake build`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This PR adds `lake check`, which builds a project's default targets, exports them, replays the result through the kernel, and reports the axioms that code rests on, failing on any beyond `propext`, `Classical.choice` and `Quot.sound`. There is no challenge to compare against.

Nothing about the project is evaluated outside the sandbox. `lake env` resolves its dependencies and `lake query :modules` names the modules to check, both inside it, so the project's configuration is never elaborated in Lake's own address space; the build and the export follow in the same sandbox. As for `lake challenge`, this requires the project to carry a `lake-manifest.json`, since the sandbox cannot write one into the project directory.

The exporter is given no declaration list, so the export covers everything in scope rather than only what the project declares, and a check costs roughly the same whatever the project's size: about a minute for a project holding a single theorem. The axiom report copes with that without a list of roots: an axiom that is merely importable is referred to by nothing, so the axioms that some other constant refers to are exactly the ones the code rests on. Note that the kernel accepts `sorryAx`, so a `sorry` is caught by this report and by nothing else.

All the default targets' modules go through the pipeline together, in one sandboxed `lake build`, one export and one kernel replay. Since each module's export already covers its whole import closure, a pass per module would re-check what they share: on a two-root project the roots' exports agree on 6,437,744 of 6,437,817 lines, so the second pass would double the run for two extra constants.

The sandbox invocations in `Lake.Check` get one definition each. `landrunSpawnArgs` builds the `IO.Process.SpawnArgs` that both `runSandBoxedWithStdout` and `runSandBoxedExitCode` use, and `runSandBoxed` is the latter plus the exit-code check. `runExternalKernel` goes through `runSandBoxedExitCode` rather than spawning `landrun` itself, keeping its own messages. `runExporter` holds the exporter's grants, which `safeExport` and `exportModules` had spelled out identically.

The two commands share the tool resolution and the sandbox context through `mkContext`; the vendored comparison path is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Kha
Kha requested a review from tydeu as a code owner September 1, 2026 14:59
@Kha
Kha requested review from hargoniX and removed request for tydeu September 1, 2026 14:59
@Kha Kha added the changelog-lake Lake label Sep 1, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Sep 1, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-09-01 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-09-01 15:16:03)

builtin_facet transDeps : Package => Array Package

/-- The Lean modules of the package's default targets. -/
builtin_facet modules : Package => Array Module

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tydeu FYI, this is for retrieving the modules for lean4export under the sandbox

def exportModules (modules : Array Lean.Name) : M String := do
let moduleArgs := modules.map (·.toString)
IO.println s!"Exporting the declarations of {" ".intercalate moduleArgs.toList}"
runExporter moduleArgs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hargoniX We might need a leanexport --stdin if we want this to not crash for Mathlib on Windows

@leanprover-bot leanprover-bot added the breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. label Sep 1, 2026
@leanprover-bot

leanprover-bot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. changelog-lake Lake toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants