Skip to content

shake --fix non-idempotency caused when modules are loaded via IR #13599

Closed

Description

@bryangingechen

Prerequisites

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

end

Running 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:

  1. git clone https://github.com/bryangingechen/shake-bug-meta-import-flip && cd shake-bug-meta-import-flip
  2. lake build && lake shake --add-public --keep-implied --keep-prefix --explain --fix: imports changed
  3. lake build && lake shake --add-public --keep-implied --keep-prefix --explain --fix: imports changed again (!)
  4. 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

  1. added
    bug
    on May 1, 2026
  2. Kha commented on May 12, 2026

    @Kha
    Member

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions