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

fix: re-support Prop valued instances #244

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions DocGen4/Process/DocInfo.lean
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,22 @@ def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := fun (name,
let info ← TheoremInfo.ofTheoremVal i
if ← isProjFn i.name then
return some <| theoremInfo { info with render := false }
else if ← isInstance i.name then
let info ← InstanceInfo.ofTheoremVal i
return some <| instanceInfo info
else
return some <| theoremInfo info
| ConstantInfo.opaqueInfo i => return some <| opaqueInfo (← OpaqueInfo.ofOpaqueVal i)
| ConstantInfo.defnInfo i =>
if ← isProjFn i.name then
let info ← DefinitionInfo.ofDefinitionVal i
return some <| definitionInfo { info with render := false }
else if ← isInstance i.name then
let info ← InstanceInfo.ofDefinitionVal i
return some <| instanceInfo info
else
if ← isInstance i.name then
let info ← InstanceInfo.ofDefinitionVal i
return some <| instanceInfo info
else
let info ← DefinitionInfo.ofDefinitionVal i
return some <| definitionInfo info
let info ← DefinitionInfo.ofDefinitionVal i
return some <| definitionInfo info
| ConstantInfo.inductInfo i =>
let env ← getEnv
if isStructure env i.name then
Expand Down
39 changes: 32 additions & 7 deletions DocGen4/Process/InstanceInfo.lean
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,48 @@ def getInstPriority (name : Name) : MetaM (Option Nat) := do
else
return some priority

private def InstanceInfo.ofDefinitionInfo (info : DefinitionInfo) (type : Expr) :
MetaM InstanceInfo := do
let mut info := info

def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
let mut info ← DefinitionInfo.ofDefinitionVal v

if let some priority ← getInstPriority v.name then
if let some priority ← getInstPriority info.name then
info := { info with attrs := info.attrs.push s!"instance {priority}" }

let some className ← isClass? v.type | panic! s!"isClass? on {v.name} returned none"
if let some instAttr ← getDefaultInstance v.name className then
let some className ← isClass? type | panic! s!"isClass? on {info.name} returned none"
if let some instAttr ← getDefaultInstance info.name className then
info := { info with attrs := info.attrs.push instAttr }

let typeNames ← getInstanceTypes v.type
let typeNames ← getInstanceTypes type

return {
toDefinitionInfo := info,
className,
typeNames,
}

def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
let info ← DefinitionInfo.ofDefinitionVal v
InstanceInfo.ofDefinitionInfo info v.type

def InstanceInfo.ofTheoremVal (v : TheoremVal) : MetaM InstanceInfo := do
let info ← Info.ofConstantVal v.toConstantVal
/-
This is a bit of a shortcut but it avoids having to duplicate the instance infrastructure for
`Prop` and non-`Prop` valued instances for now. If we run into issues with this later on we
can still easily get the hack out as it is limited to this function.
-/
let info : DefinitionInfo := {
toInfo := info,
-- theorems can't be unsafe, only definitions
isUnsafe := false,
-- theorems can't have reducibility hints so just put default
hints := .regular 0,
-- theorems don't have equations of interest
equations := none,
-- theorems can't be noncomputable, only definitions
isNonComputable := false
}

InstanceInfo.ofDefinitionInfo info v.type

end DocGen4.Process
Loading