feat: look for builtin type instances

main
Henrik Böving 2022-11-20 11:47:53 +01:00
parent 664a86e08b
commit e402ee94b1
1 changed files with 7 additions and 4 deletions

View File

@ -16,11 +16,14 @@ open Lean Meta
def getInstanceTypes (typ : Expr) : MetaM (Array Name) := do def getInstanceTypes (typ : Expr) : MetaM (Array Name) := do
let (_, _, tail) ← forallMetaTelescopeReducing typ let (_, _, tail) ← forallMetaTelescopeReducing typ
let args := tail.getAppArgs let args := tail.getAppArgs
let (_, bar) ← args.mapM (Expr.forEach · findName) |>.run .empty let (_, names) ← args.mapM (Expr.forEach · findName) |>.run .empty
pure bar return names
where where
findName : Expr → StateRefT (Array Name) MetaM Unit findName : Expr → StateRefT (Array Name) MetaM Unit
| .const name _ => do set <| (←get).push name | .const name _ => modify (·.push name)
| .sort .zero => modify (·.push "_builtin_prop")
| .sort (.succ _) => modify (·.push "_builtin_typeu")
| .sort _ => modify (·.push "_builtin_sortu")
| _ => pure () | _ => pure ()
def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
@ -30,7 +33,7 @@ def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
info := { info with attrs := info.attrs.push instAttr } info := { info with attrs := info.attrs.push instAttr }
let typeNames ← getInstanceTypes v.type let typeNames ← getInstanceTypes v.type
pure { return {
toDefinitionInfo := info, toDefinitionInfo := info,
className, className,
typeNames typeNames