Skip to content

Lean.Replay: mutual block replayed before constants used only in a later type's signature #16133

Closed

Description

@jasisz

Description

Environment.replay (used by leanchecker --from-export) can add a mutual inductive block before constants that only the types of its non-first members depend on. Valid exports are then rejected with unknown constant.

mutual
inductive A : Prop where
  | mk : A
inductive AB : Bool → Prop where
end
$ lean -o MA.olean MA.lean
$ LEAN_PATH=.:$(lean --print-prefix)/lib/lean leanexport MA -- A > mA.ndjson
$ leanchecker --from-export mA.ndjson
... (kernel) unknown constant 'Bool'

The export contains Bool (before the block), and the module compiles. The failure depends on hash order, so it is deterministic for a given name but not for all of them. Renaming A/AB to P/PB, Q/QB, Foo/FooB or Mut/MutB makes it pass, while Even, Good, X and Y fail.

In src/Lean/Replay.lean, the .inductInfo case:

  • replays the used constants of the constant it started from (via replayConstant);
  • replays the used constants of every constructor in the block;
  • never replays those of the other members' types (ci.type for ci ∈ all).

When replay reaches the block through A, nothing has pulled Bool in yet. AB has no constructor mentioning it, and the kernel then sees AB : Bool → Prop.

A fix would be to replay each member's type dependencies before addDecl:

for ci in all do
  replayConstants ci.getUsedConstantsAsSet

lean4lean --import has the same copy (Lean4Lean/Replay.lean) and fails the same way. Running leanchecker MA on the .olean passes, because Init is already loaded.

Similar in kind to #15853: replay order missing a dependency.

Found by differential fuzzing with pestycyd.

Versions

Lean 4.35.0. master's src/Lean/Replay.lean has the same code.

Activity

  1. added a commit that references this issue on Oct 31, 2026
    842c518
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions