fix: shouldGenerateCode fix for axiom

This commit is contained in:
Leonardo de Moura 2022-09-23 14:25:48 -07:00
parent 1e846ae280
commit e4f0f4b794
3 changed files with 12 additions and 4 deletions

View file

@ -27,7 +27,8 @@ and `[specialize]` since they can be partially applied.
-/
def shouldGenerateCode (declName : Name) : CoreM Bool := do
if (← isCompIrrelevant |>.run') then return false
unless (← getConstInfo declName).hasValue do return false
let some info ← getDeclInfo? declName | return false
unless info.hasValue do return false
let env ← getEnv
if hasMacroInlineAttribute env declName then return false
if (← Meta.isMatcher declName) then return false

View file

@ -74,6 +74,15 @@ private def replaceUnsafeRecNames (value : Expr) : CoreM Expr :=
return .done e
| _ => return .continue
/--
Return the declaration `ConstantInfo` for the code generator.
Remark: the unsafe recursive version is tried first.
-/
def getDeclInfo? (declName : Name) : CoreM (Option ConstantInfo) := do
let env ← getEnv
return env.find? (mkUnsafeRecName declName) <|> env.find? declName
/--
Convert the given declaration from the Lean environment into `Decl`.
The steps for this are roughly:
@ -84,8 +93,7 @@ The steps for this are roughly:
- turn the resulting term into LCNF declaration
-/
def toDecl (declName : Name) : CompilerM Decl := do
let env ← getEnv
let some info := env.find? (mkUnsafeRecName declName) <|> env.find? declName | throwError "declaration `{declName}` not found"
let some info ← getDeclInfo? declName | throwError "declaration `{declName}` not found"
let some value := info.value? | throwError "declaration `{declName}` does not have a value"
let (type, value) ← Meta.MetaM.run' do
let type ← toLCNFType info.type

View file

@ -8,7 +8,6 @@ import Lean.MonadEnv
import Lean.Util.Recognizers
namespace Lean.Compiler.LCNF
/--
Return `true` if `mdata` should be preserved.
Right now, we don't preserve any `MData`, but this may