feat: Filter projection functions from defs

main
Henrik Böving 2021-12-02 11:09:54 +01:00
parent 006b92deaa
commit 989e7bce2b
1 changed files with 22 additions and 2 deletions

View File

@ -42,6 +42,7 @@ structure InductiveInfo extends Info where
deriving Repr deriving Repr
structure StructureInfo extends Info where structure StructureInfo extends Info where
-- TODO: Later on we probably also want the type of projection fns etc.
fieldInfo : Array StructureFieldInfo fieldInfo : Array StructureFieldInfo
parents : Array Name parents : Array Name
ctor : (Name × Syntax) ctor : (Name × Syntax)
@ -123,8 +124,22 @@ def isBlackListed (declName : Name) : MetaM Bool := do
<||> isRec declName <||> isRec declName
<||> isMatcher declName <||> isMatcher declName
-- TODO: Is this actually the best way?
def isProjFn (declName : Name) : MetaM Bool := do
let env ← getEnv
match declName with
| Name.str parent name _ =>
if isStructure env parent then
match getStructureInfo? env parent with
| some i =>
match i.fieldNames.find? (· == name) with
| some _ => true
| none => false
| none => panic! s!"{parent} is not a structure"
else
false
| _ => false
-- TODO: Figure out how to associate names etc. with where they actually came from module wise
def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := λ (name, info) => do def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := λ (name, info) => do
if (←isBlackListed name) then if (←isBlackListed name) then
return none return none
@ -136,7 +151,12 @@ def ofConstant : (Name × ConstantInfo) → MetaM (Option DocInfo) := λ (name,
-- TODO: Instances are definitions as well (for example coeTrans), figure out: -- TODO: Instances are definitions as well (for example coeTrans), figure out:
-- - how we can know whether they are instances -- - how we can know whether they are instances
-- - how we can access unnamed instances (they probably have internal names?, change the blacklist?) -- - how we can access unnamed instances (they probably have internal names?, change the blacklist?)
| ConstantInfo.defnInfo i => some $ definitionInfo (←DefinitionInfo.ofDefinitionVal i) -- TODO: Filter out projection fns
| ConstantInfo.defnInfo i =>
if (←isProjFn i.name) then
none
else
some $ definitionInfo (←DefinitionInfo.ofDefinitionVal i)
-- TODO: Differentiate between all the different types of inductives (structures, classes etc.) -- TODO: Differentiate between all the different types of inductives (structures, classes etc.)
| ConstantInfo.inductInfo i => | ConstantInfo.inductInfo i =>
if isStructure (←getEnv) i.name then if isStructure (←getEnv) i.name then