Skip to content

Commit

Permalink
chore: use builtin functions in equation computing (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX authored Dec 15, 2024
1 parent d23a5c9 commit 589875a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions DocGen4/Process/DefinitionInfo.lean
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ namespace DocGen4.Process

open Lean Meta Widget

partial def stripArgs (e : Expr) (k : Expr → MetaM α) : MetaM α :=
match e.consumeMData with
| Expr.forallE name type body bi =>
let name := name.eraseMacroScopes
Meta.withLocalDecl name bi type fun fvar => do
stripArgs (Expr.instantiate1 body fvar) k
| _ => k e

def valueToEq (v : DefinitionVal) : MetaM Expr := withLCtx {} {} do
withOptions (tactic.hygienic.set . false) do
lambdaTelescope v.value fun xs body => do
Expand All @@ -28,9 +20,12 @@ def valueToEq (v : DefinitionVal) : MetaM Expr := withLCtx {} {} do
let type ← mkForallFVars xs type
return type

def prettyPrintEquation (expr : Expr) : MetaM CodeWithInfos :=
Meta.forallTelescope expr.consumeMData (fun _ e => prettyPrintTerm e)

def processEq (eq : Name) : MetaM CodeWithInfos := do
let type ← (mkConstWithFreshMVarLevels eq >>= inferType)
stripArgs type prettyPrintTerm
prettyPrintEquation type

def computeEquations? (v : DefinitionVal) : MetaM (Array CodeWithInfos) := do
let eqs? ← getEqnsFor? v.name
Expand All @@ -39,7 +34,7 @@ def computeEquations? (v : DefinitionVal) : MetaM (Array CodeWithInfos) := do
let eqs ← eqs.mapM processEq
return eqs
| none =>
let equations := #[← stripArgs (← valueToEq v) prettyPrintTerm]
let equations := #[← prettyPrintEquation (← valueToEq v)]
return equations

def DefinitionInfo.ofDefinitionVal (v : DefinitionVal) : MetaM DefinitionInfo := do
Expand Down

0 comments on commit 589875a

Please sign in to comment.