leanprover / leanprover/lean4

shake can incorrectly demote `public meta import` to `meta import`

Open
#14,427 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

Create a project with following two files:

-- Dep.lean
module

public def helper (n : Nat) : Nat := n + 1
-- Main.lean
module

public meta import Dep

meta section

private def priv (n : Nat) : Nat := helper n  -- private meta helper

public def pub (n : Nat) : Nat := priv n      -- public meta def

end

The body of pub (including priv's body) gets re-exported since it is public, so helper also needs to be accessible to downstream modules, hence the public is required in the import. However:

$ lake build            # succeeds
$ lake shake --fix Main
  remove #[public meta import Dep]
  add #[meta import Dep]
$ lake build            # now FAILS:
error: Main.lean:9:11: Invalid public `meta` definition `pub`, `helper` is not
accessible here; consider adding `public meta import Dep`
Context

Observed in https://github.com/leanprover-community/mathlib4/pull/40343.

Steps to Reproduce

See the Description above.

For a 3-file version that reproduces the issue in mathlib4 (where the --add-public flag that we used suppresses the issue above), as well as Claude Fable's description of the bug see https://github.com/bryangingechen/shake-public-meta-def-demoted.

Expected behavior: shake --fix should not cause breakage.

Actual behavior: the build breaks, see above.

Versions

Present in both v4.32.0 and v4.33.0-rc1.

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

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.

Research direction

Start with the two-file reproduction in Dep.lean and Main.lean, then run lake shake --fix Main followed by lake build to observe the demotion of public meta import. Trace shake's import-fixing logic and ensure the command preserves the public meta import when a public meta definition exposes helper. The build should continue to succeed after --fix.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.