RFC: `lake shake` over the roots of two or more executables in one call

Open
#16,498 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Domain
tooling

Research direction

Read Lake/CLI/Shake.lean for lake shake root handling and Lean/Environment.lean around ImportState.markAllExported; the proposal identifies both as change locations. The linked branch includes a test, so inspect it for the expected behavior and run the relevant Lake shake tests. Done means multiple executable roots are handled together, including grouped imports, with suggestions or --fix applied only after every group succeeds.

Written by the indexing model from the issue text.

Description

P-medium
Proposal

lake shake refuses the roots of two or more executables in one call: each declares main, and loading them into one environment fails in finalizeImport:

error: import B failed, environment already contains 'main' from A

A project with two or more executables runs one lake shake per root, each loading its whole import closure again. Each call sees only the modules under its own roots, and on a project of ours, applying the suggestions of separate calls for two of its modules alone left five others unbuildable.

The proposal is to accept such roots in one call:

  • Before finalizeImport, every main past the first, with the declarations its own module names under it, gets a name of its own, <module>._shake_main, in its module and the modules importing it.
  • When the roots' modules don't load together, each root joins the first group whose modules, with its own, do, the groups checked within one process, each analysing the modules under all of the call's roots, so an edit in one group reaches the modules of a later group.
  • With two groups or more, suggestions are printed, and --fix writes files, only once every group has succeeded; --add-downstream is refused when the roots are split into groups.

User experience: one call checks all of a project's executables together, and when a module's re-export is removed, its dependents in other executables are told to import what they use.

Beneficiaries: projects with two or more executables. On a project of ours (not public) of 120 modules and 45 executables, one patched call over every module took 5.36 s of wall time, against 15.99 s for one unpatched call per module, 25 at a time.

Maintainability: the change adds to Lean/Environment.lean a structure and five functions on ImportState, documented as intended for shake only, beside ImportState.markAllExported, and the grouping to Lake/CLI/Shake.lean. A branch with the change and a test is ready. It was compiled and tested on the Lean nightly nightly-2026-11-16, whose Environment.lean and Shake.lean are those of the commit it is based on, and measured on v4.36.0-rc2.

Community Feedback

An issue search for shake found none about two or more executables in one call.

Dominant language
Lean
Stars
10.3k
Forks
1.1k
Avg merge
19h 8m
Merged PRs (30d)
421

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/lean4

All issues in leanprover/lean4

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.