feat: use Kyle Miller's instance analysis algorithm
parent
8bccb92b53
commit
ec2561f34b
|
@ -16,14 +16,18 @@ 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 (_, names) ← args.mapM (Expr.forEach · findName) |>.run .empty
|
let (_, bis, _) ← forallMetaTelescopeReducing (← inferType tail.getAppFn)
|
||||||
|
let (_, names) ← (bis.zip args).mapM findName |>.run .empty
|
||||||
return names
|
return names
|
||||||
where
|
where
|
||||||
findName : Expr → StateRefT (Array Name) MetaM Unit
|
findName : BinderInfo × Expr → StateRefT (Array Name) MetaM Unit
|
||||||
| .const name _ => modify (·.push name)
|
| (.default, .sort .zero) => modify (·.push "_builtin_prop")
|
||||||
| .sort .zero => modify (·.push "_builtin_prop")
|
| (.default, .sort (.succ _)) => modify (·.push "_builtin_typeu")
|
||||||
| .sort (.succ _) => modify (·.push "_builtin_typeu")
|
| (.default, .sort _) => modify (·.push "_builtin_sortu")
|
||||||
| .sort _ => modify (·.push "_builtin_sortu")
|
| (.default, e) =>
|
||||||
|
match e.getAppFn with
|
||||||
|
| .const name .. => modify (·.push name)
|
||||||
|
| _ => return ()
|
||||||
| _ => return ()
|
| _ => return ()
|
||||||
|
|
||||||
def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
|
def InstanceInfo.ofDefinitionVal (v : DefinitionVal) : MetaM InstanceInfo := do
|
||||||
|
|
Loading…
Reference in New Issue