fix: apply afterCompilation attributes after we have compiled *all* definitions in a mutual block

This commit is contained in:
Leonardo de Moura 2022-01-05 15:56:48 -08:00
parent 030e932db8
commit ff49fd6b7e
2 changed files with 9 additions and 6 deletions

View file

@ -92,7 +92,7 @@ private def compileDecl (decl : Declaration) : TermElabM Bool := do
throw ex
return true
private def addNonRecAux (preDef : PreDefinition) (compile : Bool) : TermElabM Unit :=
private def addNonRecAux (preDef : PreDefinition) (compile : Bool) (applyAttrAfterCompilation := true) : TermElabM Unit :=
withRef preDef.ref do
let preDef ← abstractNestedProofs preDef
let env ← getEnv
@ -118,13 +118,14 @@ private def addNonRecAux (preDef : PreDefinition) (compile : Bool) : TermElabM U
if compile && shouldGenCodeFor preDef then
unless (← compileDecl decl) do
return ()
applyAttributesOf #[preDef] AttributeApplicationTime.afterCompilation
if applyAttrAfterCompilation then
applyAttributesOf #[preDef] AttributeApplicationTime.afterCompilation
def addAndCompileNonRec (preDef : PreDefinition) : TermElabM Unit := do
addNonRecAux preDef true
def addNonRec (preDef : PreDefinition) : TermElabM Unit := do
addNonRecAux preDef false
def addNonRec (preDef : PreDefinition) (applyAttrAfterCompilation := true) : TermElabM Unit := do
addNonRecAux preDef (compile := false) (applyAttrAfterCompilation := applyAttrAfterCompilation)
/--
Eliminate recursive application annotations containing syntax. These annotations are used by the well-founded recursion module

View file

@ -45,7 +45,7 @@ private partial def addNonRecPreDefs (preDefs : Array PreDefinition) (preDefNonR
let arg ← mkSum 0 domain
mkLambdaFVars xs (mkApp (mkConst preDefNonRec.declName us) arg)
trace[Elab.definition.wf] "{preDef.declName} := {value}"
addNonRec { preDef with value }
addNonRec { preDef with value } (applyAttrAfterCompilation := false)
def wfRecursion (preDefs : Array PreDefinition) (wfStx? : Option Syntax) (decrTactic? : Option Syntax) : TermElabM Unit := do
let unaryPreDef ← withoutModifyingEnv do
@ -62,8 +62,10 @@ def wfRecursion (preDefs : Array PreDefinition) (wfStx? : Option Syntax) (decrTa
let preDefs ← preDefs.mapM fun d => eraseRecAppSyntax d
addNonRec preDefNonRec
addNonRecPreDefs preDefs preDefNonRec
addAndCompilePartialRec preDefs
registerEqnsInfo preDefs preDefNonRec.declName
for preDef in preDefs do
applyAttributesOf #[preDef] AttributeApplicationTime.afterCompilation
addAndCompilePartialRec preDefs
builtin_initialize registerTraceClass `Elab.definition.wf