perf: no need to register axioms outside of the module system (#8121)

This commit is contained in:
Sebastian Ullrich 2025-04-26 18:14:00 +02:00 committed by GitHub
parent 87dccb9d1b
commit f285867137
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -148,8 +148,12 @@ where
let env ← (← getEnv).addDeclAux (← getOptions) decl (← read).cancelTk?
|> ofExceptKernelException
setEnv env
for n in decl.getTopLevelNames do
registerAxiomsForDecl n
if env.header.isModule then
-- Under the module system, must record axioms in environment extension now when we
-- still have access to the declaration's body. We could skip this for non-opaque decls
-- but for them, registering simply acts as a cache.
for n in decl.getTopLevelNames do
registerAxiomsForDecl n
catch ex =>
-- avoid follow-up errors by (trying to) add broken decl as axiom
addAsAxiom

View file

@ -51,6 +51,10 @@ def collectAxioms [Monad m] [MonadEnv m] (constName : Name) : m (Array Name) :=
let (_, s) := ((CollectAxioms.collect constName).run env).run {}
pure s.axioms
/--
Registers axioms used by the declaration in an environment extension so they can be retrieved even
if some parts of the declaration's become inaccessible.
-/
def registerAxiomsForDecl (n : Name) : CoreM Unit := do
let axioms ← collectAxioms n
modifyEnv (exportedAxiomsExt.addEntry · (n, axioms))