Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use builtin functions in equation computing #248

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading