Repository navigation
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, (tested against both
v4.30.0-rc2andnightly-2026-05-01)
Description
When a module X is loaded for IR only (no data), e.g. when the only path to X from the current module is through a meta import of an intermediate module with import X (private+non-meta), the isMeta flag on shake's extraModUse recording for decls in X ends up true incorrectly, because isMarkedMeta reads metaExt, which is persisted only into .olean*, not .ir.
shake --fix then suggests meta import X in downstream modules. Once that import is added, it becomes a direct import from the root file (importAll=true), which loads X's data; on the next shake --fix, the recording has flipped to priv and shake now suggests removing the meta keyword.
Context
Found while running lake shake against mathlib4. Zulip thread.
Steps to Reproduce
Consider the following set of 3 modules (copied from https://github.com/bryangingechen/shake-bug-meta-import-flip):
-- Attr.lean
module
public meta import Lean.Meta.Tactic.Simp.Attr
public import Lean.Meta.Tactic.Simp.RegisterCommand
public meta section
register_simp_attr foo_simps
end-- LibMid.lean
module
import ShakeBug3.Attr
/-! Plain `import ShakeBug3.Attr` (non-public, non-meta). -/
@[expose] public section
def libMidVal : Nat := 17
end-- User.lean
module
public meta import ShakeBug3.LibMid
/-! Uses `@[foo_simps]`. `User`'s meta import of `LibMid` propagates
`needsIRTrans` through `LibMid`'s plain `import ShakeBug3.Attr`, so
`Attr`'s IR is loaded (its `initialize` runs and `foo_simps` is
registered) — but `Attr`'s data, including the `metaExt` entries, is
NOT loaded for this compilation. -/
@[expose] public section
@[foo_simps]
theorem userSimpThm : libMidVal = 17 := rfl
endRunning lake build && lake shake --add-public --keep-implied --keep-prefix --fix on this project once results in a suggestion to add meta import ShakeBug3.Attr to User.lean. Running it again results in a suggestion to replace that line with just import ShakeBug3.Attr.
Alternatively:
git clone https://github.com/bryangingechen/shake-bug-meta-import-flip && cd shake-bug-meta-import-fliplake build && lake shake --add-public --keep-implied --keep-prefix --explain --fix: imports changedlake build && lake shake --add-public --keep-implied --keep-prefix --explain --fix: imports changed again (!)lake build && lake shake --add-public --keep-implied --keep-prefix --explain --fix: no changes
Expected behavior: shake --fix should be idempotent after the first run.
Actual behavior: shake --fix is only idempotent after the second run.
Versions
v4.30.0-rc2
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Activity
fix: reject attribute uses whose home module is reached only as `meta`
fix: reject attribute uses whose module is reachable only via IR (lea…
Kha commentedon May 12, 2026
I'll close this as resolved by #13613. While the shake behavior has not been changed, fixing such instances on the elaborator side should be the correct approach.