commit
4490b1e674
|
@ -7,11 +7,11 @@ namespace Output
|
||||||
open scoped DocGen4.Jsx
|
open scoped DocGen4.Jsx
|
||||||
open Lean
|
open Lean
|
||||||
|
|
||||||
def instanceToHtml (name : Name) : HtmlM Html := do
|
def classInstanceToHtml (name : Name) : HtmlM Html := do
|
||||||
<li><a href={←declNameToLink name}>{name.toString}</a></li>
|
<li><a href={←declNameToLink name}>{name.toString}</a></li>
|
||||||
|
|
||||||
def instancesToHtml (i : ClassInfo) : HtmlM Html := do
|
def classInstancesToHtml (i : ClassInfo) : HtmlM Html := do
|
||||||
let instancesHtml ← i.instances.mapM instanceToHtml
|
let instancesHtml ← i.instances.mapM classInstanceToHtml
|
||||||
return <details «class»="instances">
|
return <details «class»="instances">
|
||||||
<summary>Instances</summary>
|
<summary>Instances</summary>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -20,7 +20,7 @@ def instancesToHtml (i : ClassInfo) : HtmlM Html := do
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
def classToHtml (i : ClassInfo) : HtmlM (Array Html) := do
|
def classToHtml (i : ClassInfo) : HtmlM (Array Html) := do
|
||||||
(←structureToHtml i.toStructureInfo).push (←instancesToHtml i)
|
(←structureToHtml i.toStructureInfo).push (←classInstancesToHtml i)
|
||||||
|
|
||||||
end Output
|
end Output
|
||||||
end DocGen4
|
end DocGen4
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import DocGen4.Output.Template
|
||||||
|
|
||||||
|
namespace DocGen4
|
||||||
|
namespace Output
|
||||||
|
|
||||||
|
open scoped DocGen4.Jsx
|
||||||
|
open Lean Widget
|
||||||
|
|
||||||
|
def equationToHtml (c : CodeWithInfos) : HtmlM Html := do
|
||||||
|
<li «class»="equation">[←infoFormatToHtml c]</li>
|
||||||
|
|
||||||
|
def equationsToHtml (i : DefinitionInfo) : HtmlM (Option Html) := do
|
||||||
|
if let some eqs ← i.equations then
|
||||||
|
let equationsHtml ← eqs.mapM equationToHtml
|
||||||
|
return <details>
|
||||||
|
<summary>Equations</summary>
|
||||||
|
<ul «class»="equations">
|
||||||
|
[equationsHtml]
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
|
else
|
||||||
|
return none
|
||||||
|
|
||||||
|
def definitionToHtml (i : DefinitionInfo) : HtmlM (Array Html) := do
|
||||||
|
let equationsHtml ← equationsToHtml i
|
||||||
|
if let some equationsHtml ← equationsHtml then
|
||||||
|
#[equationsHtml]
|
||||||
|
else
|
||||||
|
#[]
|
||||||
|
|
||||||
|
end Output
|
||||||
|
end DocGen4
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import DocGen4.Output.Template
|
||||||
|
import DocGen4.Output.Definition
|
||||||
|
|
||||||
|
namespace DocGen4
|
||||||
|
namespace Output
|
||||||
|
|
||||||
|
def instanceToHtml (i : InstanceInfo) : HtmlM (Array Html) := definitionToHtml i
|
||||||
|
|
||||||
|
end Output
|
||||||
|
end DocGen4
|
|
@ -7,6 +7,8 @@ import DocGen4.Output.Template
|
||||||
import DocGen4.Output.Inductive
|
import DocGen4.Output.Inductive
|
||||||
import DocGen4.Output.Structure
|
import DocGen4.Output.Structure
|
||||||
import DocGen4.Output.Class
|
import DocGen4.Output.Class
|
||||||
|
import DocGen4.Output.Definition
|
||||||
|
import DocGen4.Output.Instance
|
||||||
|
|
||||||
namespace DocGen4
|
namespace DocGen4
|
||||||
namespace Output
|
namespace Output
|
||||||
|
@ -75,6 +77,8 @@ def docInfoToHtml (module : Name) (doc : DocInfo) : HtmlM Html := do
|
||||||
| DocInfo.inductiveInfo i => inductiveToHtml i
|
| DocInfo.inductiveInfo i => inductiveToHtml i
|
||||||
| DocInfo.structureInfo i => structureToHtml i
|
| DocInfo.structureInfo i => structureToHtml i
|
||||||
| DocInfo.classInfo i => classToHtml i
|
| DocInfo.classInfo i => classToHtml i
|
||||||
|
| DocInfo.definitionInfo i => definitionToHtml i
|
||||||
|
| DocInfo.instanceInfo i => instanceToHtml i
|
||||||
| _ => #[]
|
| _ => #[]
|
||||||
|
|
||||||
return <div «class»="decl" id={doc.getName.toString}>
|
return <div «class»="decl" id={doc.getName.toString}>
|
||||||
|
|
|
@ -47,6 +47,7 @@ structure DefinitionInfo extends Info where
|
||||||
--value : CodeWithInfos
|
--value : CodeWithInfos
|
||||||
unsafeInformation : DefinitionSafety
|
unsafeInformation : DefinitionSafety
|
||||||
hints : ReducibilityHints
|
hints : ReducibilityHints
|
||||||
|
equations : Option (Array CodeWithInfos)
|
||||||
deriving Inhabited
|
deriving Inhabited
|
||||||
|
|
||||||
abbrev InstanceInfo := DefinitionInfo
|
abbrev InstanceInfo := DefinitionInfo
|
||||||
|
@ -160,11 +161,45 @@ def OpaqueInfo.ofOpaqueVal (v : OpaqueVal) : MetaM OpaqueInfo := do
|
||||||
def isInstance (declName : Name) : MetaM Bool := do
|
def isInstance (declName : Name) : MetaM Bool := do
|
||||||
(instanceExtension.getState (←getEnv)).instanceNames.contains declName
|
(instanceExtension.getState (←getEnv)).instanceNames.contains declName
|
||||||
|
|
||||||
|
|
||||||
|
partial def stripArgs (e : Expr) : Expr :=
|
||||||
|
match e.consumeMData with
|
||||||
|
| Expr.lam name type body data =>
|
||||||
|
let name := name.eraseMacroScopes
|
||||||
|
stripArgs (Expr.instantiate1 body (mkFVar ⟨name⟩))
|
||||||
|
| Expr.forallE name type body data =>
|
||||||
|
let name := name.eraseMacroScopes
|
||||||
|
stripArgs (Expr.instantiate1 body (mkFVar ⟨name⟩))
|
||||||
|
| _ => e
|
||||||
|
|
||||||
|
def processEq (eq : Name) : MetaM CodeWithInfos := do
|
||||||
|
let type ← (mkConstWithFreshMVarLevels eq >>= inferType)
|
||||||
|
let final := stripArgs type
|
||||||
|
prettyPrintTerm final
|
||||||
|
|
||||||
|
def valueToEq (v : DefinitionVal) : MetaM Expr := withLCtx {} {} do
|
||||||
|
let env ← getEnv
|
||||||
|
withOptions (tactic.hygienic.set . false) do
|
||||||
|
lambdaTelescope v.value fun xs body => do
|
||||||
|
let us := v.levelParams.map mkLevelParam
|
||||||
|
let type ← mkEq (mkAppN (Lean.mkConst v.name us) xs) body
|
||||||
|
let type ← mkForallFVars xs type
|
||||||
|
type
|
||||||
|
|
||||||
def DefinitionInfo.ofDefinitionVal (v : DefinitionVal) : MetaM DefinitionInfo := do
|
def DefinitionInfo.ofDefinitionVal (v : DefinitionVal) : MetaM DefinitionInfo := do
|
||||||
let info ← Info.ofConstantVal v.toConstantVal
|
let info ← Info.ofConstantVal v.toConstantVal
|
||||||
-- Elaborating the value yields weird exceptions
|
try
|
||||||
--let value ← prettyPrintTerm v.value
|
let eqs? ← getEqnsFor? v.name
|
||||||
return DefinitionInfo.mk info v.safety v.hints
|
match eqs? with
|
||||||
|
| some eqs =>
|
||||||
|
let prettyEqs ← eqs.mapM processEq
|
||||||
|
DefinitionInfo.mk info v.safety v.hints prettyEqs
|
||||||
|
| none =>
|
||||||
|
let eq ← prettyPrintTerm $ stripArgs (←valueToEq v)
|
||||||
|
DefinitionInfo.mk info v.safety v.hints (some #[eq])
|
||||||
|
catch err =>
|
||||||
|
IO.println s!"WARNING: Failed to calculate equational lemmata for {v.name}: {←err.toMessageData.toString}"
|
||||||
|
return DefinitionInfo.mk info v.safety v.hints none
|
||||||
|
|
||||||
def getConstructorType (ctor : Name) : MetaM CodeWithInfos := do
|
def getConstructorType (ctor : Name) : MetaM CodeWithInfos := do
|
||||||
let env ← getEnv
|
let env ← getEnv
|
||||||
|
@ -254,7 +289,6 @@ def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := λ (name,
|
||||||
| ConstantInfo.axiomInfo i => some $ axiomInfo (←AxiomInfo.ofAxiomVal i)
|
| ConstantInfo.axiomInfo i => some $ axiomInfo (←AxiomInfo.ofAxiomVal i)
|
||||||
| ConstantInfo.thmInfo i => some $ theoremInfo (←TheoremInfo.ofTheoremVal i)
|
| ConstantInfo.thmInfo i => some $ theoremInfo (←TheoremInfo.ofTheoremVal i)
|
||||||
| ConstantInfo.opaqueInfo i => some $ opaqueInfo (←OpaqueInfo.ofOpaqueVal i)
|
| ConstantInfo.opaqueInfo i => some $ opaqueInfo (←OpaqueInfo.ofOpaqueVal i)
|
||||||
-- TODO: Find a way to extract equations nicely
|
|
||||||
| ConstantInfo.defnInfo i =>
|
| ConstantInfo.defnInfo i =>
|
||||||
if ← (isProjFn i.name) then
|
if ← (isProjFn i.name) then
|
||||||
none
|
none
|
||||||
|
@ -342,14 +376,15 @@ def process : MetaM AnalyzerResult := do
|
||||||
res := res.insert module (Module.mk module moduleDoc #[])
|
res := res.insert module (Module.mk module moduleDoc #[])
|
||||||
|
|
||||||
for cinfo in env.constants.toList do
|
for cinfo in env.constants.toList do
|
||||||
let d := ←DocInfo.ofConstant cinfo
|
try
|
||||||
match d with
|
let analysis := Prod.fst <$> Meta.MetaM.toIO (DocInfo.ofConstant cinfo) { maxHeartbeats := 5000000, options := ⟨[(`pp.tagAppFns, true)]⟩ } { env := env} {} {}
|
||||||
| some dinfo =>
|
if let some dinfo ← analysis then
|
||||||
let some modidx ← env.getModuleIdxFor? cinfo.fst | unreachable!
|
let some modidx ← env.getModuleIdxFor? dinfo.getName | unreachable!
|
||||||
let moduleName := env.allImportedModuleNames.get! modidx
|
let moduleName := env.allImportedModuleNames.get! modidx
|
||||||
let module := res.find! moduleName
|
let module := res.find! moduleName
|
||||||
res := res.insert moduleName {module with members := module.members.push dinfo}
|
res := res.insert moduleName {module with members := module.members.push dinfo}
|
||||||
| none => ()
|
catch e =>
|
||||||
|
IO.println s!"WARNING: Failed to obtain information for: {cinfo.fst}: {←e.toMessageData.toString}"
|
||||||
|
|
||||||
-- TODO: This is definitely not the most efficient way to store this data
|
-- TODO: This is definitely not the most efficient way to store this data
|
||||||
let mut adj := Array.mkArray res.size (Array.mkArray res.size false)
|
let mut adj := Array.mkArray res.size (Array.mkArray res.size false)
|
||||||
|
@ -370,4 +405,6 @@ def process : MetaM AnalyzerResult := do
|
||||||
importAdj := adj
|
importAdj := adj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end DocGen4
|
end DocGen4
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
leanprover/lean4:nightly-2022-02-01
|
leanprover/lean4:nightly-2022-02-04
|
Loading…
Reference in New Issue