feat: add reference implementation for whnf

This commit is contained in:
Leonardo de Moura 2019-11-07 10:18:36 -08:00
parent e020cd2ea0
commit 91e87a0cd4

View file

@ -360,4 +360,26 @@ match e with
deltaDefinition cinfo lvls failK successK
| _ => failK ()
/- Reference implementation for `whnf`. It does not cache any results.
How to use:
- `getConst constName` retrieves `constName` from environment. Caller may make definitions opaque by returning `none`.
- `isAuxDef? constName` returns `true` is `constName` is an auxiliary declaration automatically generated by Lean and
used by equation compiler, and must be eagerly reduced by `whnfCore`. This method is usually implemented using `isAuxRecursor`.
- `synthesizePending` is used to (try to) synthesize synthetic metavariables that may be blocking reduction.
The other parameters should be self explanatory. -/
@[specialize] partial def whnfMain {m : Type → Type} [Monad m]
(getConst : Name → m (Option ConstantInfo))
(isAuxDef? : Name → m Bool)
(inferType : Expr → m Expr)
(isDefEq : Expr → Expr → m Bool)
(synthesizePending : Expr → m Bool)
(getLocalDecl : Name → m LocalDecl)
(getMVarAssignment : Name → m (Option Expr))
: Expr → m Expr
| e => do
e ← whnfCore getConst isAuxDef? whnfMain inferType isDefEq getLocalDecl getMVarAssignment e;
unfoldDefinition getConst isAuxDef? whnfMain inferType isDefEq synthesizePending getLocalDecl getMVarAssignment e (fun _ => pure e) whnfMain
end Lean