import Lean open Lean /- My kernel replay (lean4checker-style, using core Lean.Environment.replay): 1. load the full environment of the endpoint module and collect every constant whose defining module is a Problem455* module; 2. load a fresh environment containing only the external dependencies (Mathlib/Std/Lean imports used by the project); 3. re-add every project constant through the kernel type checker. -/ def main : IO Unit := do initSearchPath (← findSysroot) let full ← importModules #[{module := `MyStatement}] {} (loadExts := false) let mut newC : Std.HashMap Name ConstantInfo := {} let mut nmods := 0 let mut baseMods : Array Name := #[] for i in [0:full.header.moduleNames.size] do let m := full.header.moduleNames[i]! if !(m.toString.startsWith "Init" || m.toString.startsWith "Lean" || m.toString.startsWith "Std" || m.toString.startsWith "Lake" || ["Aesop","Qq","ProofWidgets","Plausible","LeanSearchClient","ImportGraph","Cli"].any (fun p => m.getRoot.toString == p)) then nmods := nmods + 1 for c in full.header.moduleData[i]!.constants do newC := newC.insert c.name c else baseMods := baseMods.push m IO.println s!"modules replayed: {nmods}, constants: {newC.size}" let deps := baseMods let base ← importModules (deps.map fun m => {module := m}) {} (loadExts := false) newC := newC.fold (init := ({} : Std.HashMap Name ConstantInfo)) fun acc n c => if base.contains n then acc else acc.insert n c IO.println s!"constants not already in trusted base (replayed): {newC.size}" let env ← base.replay newC for n in [`P455Undecidability.finite_semigroup_finite_basis_undecidable, `MyCheck.no_algorithm] do IO.println s!"{n} present after replay: {env.contains n}" IO.println "kernel replay OK"