feat: term info at many more constants

This commit is contained in:
Sebastian Ullrich 2021-03-19 15:58:45 +01:00 committed by Leonardo de Moura
parent 83ecff44c6
commit 29c7db3ed2
8 changed files with 20 additions and 14 deletions

View file

@ -271,7 +271,7 @@ def elabMutual : CommandElab := fun stx => do
let attrs ← elabAttrs attrInsts
let idents := stx[4].getArgs
for ident in idents do withRef ident <| liftTermElabM none do
let declName ← resolveGlobalConstNoOverload ident.getId
let declName ← resolveGlobalConstNoOverloadWithInfo ident
Term.applyAttributes declName attrs
for attrName in toErase do
Attribute.erase declName attrName

View file

@ -32,8 +32,8 @@ def applyDerivingHandlers (className : Name) (typeNames : Array Name) : CommandE
@[builtinCommandElab «deriving»] def elabDeriving : CommandElab
| `(deriving instance $[$classes],* for $[$declNames],*) => do
let classes ← classes.mapM (resolveGlobalConstNoOverload ·.getId)
let declNames ← declNames.mapM (resolveGlobalConstNoOverload ·.getId)
let classes ← classes.mapM resolveGlobalConstNoOverloadWithInfo
let declNames ← declNames.mapM resolveGlobalConstNoOverloadWithInfo
for cls in classes do
try
applyDerivingHandlers cls declNames
@ -46,12 +46,12 @@ structure DerivingClassView where
className : Name
/- leading_parser optional (atomic ("deriving " >> notSymbol "instance") >> sepBy1 ident ", ") -/
def getOptDerivingClasses [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] (optDeriving : Syntax) : m (Array DerivingClassView) := do
def getOptDerivingClasses [Monad m] [MonadEnv m] [MonadResolveName m] [MonadError m] [MonadInfoTree m] (optDeriving : Syntax) : m (Array DerivingClassView) := do
if optDeriving.isNone then
return #[]
else
optDeriving[0][1].getSepArgs.mapM fun ident => do
let className ← resolveGlobalConstNoOverload ident.getId
let className ← resolveGlobalConstNoOverloadWithInfo ident
return { ref := ident, className := className }
def DerivingClassView.applyHandlers (view : DerivingClassView) (declNames : Array Name) : CommandElabM Unit :=

View file

@ -191,11 +191,17 @@ def pushInfoLeaf (t : Info) : m Unit := do
if (← getInfoState).enabled then
pushInfoTree <| InfoTree.node (children := {}) t
def resolveGlobalConstWithInfos [MonadResolveName m] [MonadEnv m] [MonadError m] (id : Syntax) : m (List Name) := do
let ns ← resolveGlobalConst id.getId
def resolveGlobalConstNoOverloadWithInfo [MonadResolveName m] [MonadEnv m] [MonadError m] (stx : Syntax) (id := stx.getId) : m Name := do
let n ← resolveGlobalConstNoOverload id
if (← getInfoState).enabled then
pushInfoLeaf <| Info.ofTermInfo { lctx := LocalContext.empty, expr := (← mkConstWithLevelParams n), stx := stx }
return n
def resolveGlobalConstWithInfos [MonadResolveName m] [MonadEnv m] [MonadError m] (stx : Syntax) (id := stx.getId) : m (List Name) := do
let ns ← resolveGlobalConst id
if (← getInfoState).enabled then
for n in ns do
pushInfoLeaf <| Info.ofTermInfo { lctx := LocalContext.empty, expr := (← mkConstWithLevelParams n), stx := id }
pushInfoLeaf <| Info.ofTermInfo { lctx := LocalContext.empty, expr := (← mkConstWithLevelParams n), stx := stx }
return ns
def mkInfoNode (info : Info) : m Unit := do

View file

@ -115,7 +115,7 @@ private def printAxiomsOf (constName : Name) : CommandElabM Unit := do
@[builtinCommandElab «printAxioms»] def elabPrintAxioms : CommandElab
| `(#print%$tk axioms $id) => withRef tk do
let cs ← resolveGlobalConst id.getId
let cs ← resolveGlobalConstWithInfos id
cs.forM printAxiomsOf
| _ => throwUnsupportedSyntax

View file

@ -113,7 +113,7 @@ where
`isDescr == true` if the type of `resolvedParserName` is a `ParserDescr`. -/
resolveParserName (parserName : Name) : ToParserDescrM (List (Name × Bool)) := do
try
let candidates ← resolveGlobalConst parserName
let candidates ← resolveGlobalConstWithInfos (← getRef) parserName
/- Convert `candidates` in a list of pairs `(c, isDescr)`, where `c` is the parser name,
and `isDescr` is true iff `c` has type `Lean.ParserDescr` or `Lean.TrailingParser` -/
candidates.filterMap fun c =>
@ -142,7 +142,7 @@ where
processNullaryOrCat (stx : Syntax) := do
let id := stx[0].getId.eraseMacroScopes
match (← resolveParserName id) with
match (← withRef stx[0] <| resolveParserName id) with
| [(c, true)] => ensureNoPrec stx; return mkIdentFrom stx c
| [(c, false)] => ensureNoPrec stx; `(ParserDescr.parser $(quote c))
| cs@(_ :: _ :: _) => throwError "ambiguous parser declaration {cs.map (·.1)}"

View file

@ -317,7 +317,7 @@ private def getElimNameInfo (optElimId : Syntax) (targets : Array Expr) (inducti
pure (elimName, ← getElimInfo elimName)
else
let elimId := optElimId[1]
let elimName ← withRef elimId do resolveGlobalConstNoOverload elimId.getId.eraseMacroScopes
let elimName ← withRef elimId do resolveGlobalConstNoOverloadWithInfo elimId elimId.getId.eraseMacroScopes
pure (elimName, ← withRef elimId do getElimInfo elimName)
@[builtinTactic Lean.Parser.Tactic.induction] def evalInduction : Tactic := fun stx => focus do

View file

@ -51,7 +51,7 @@ private def elabSimpLemmas (stx : Syntax) (ctx : Simp.Context) (eraseLocal : Boo
-- We use `eraseCore` because the simp lemma for the hypothesis was not added yet
lemmas ← lemmas.eraseCore arg[1].getId
else
let declName ← resolveGlobalConstNoOverload arg[1].getId
let declName ← resolveGlobalConstNoOverloadWithInfo arg[1]
lemmas ← lemmas.erase declName
else
let post :=

View file

@ -1404,7 +1404,7 @@ def elabScientificLit : TermElab := fun stx expectedType? => do
@[builtinTermElab doubleQuotedName] def elabDoubleQuotedName : TermElab := fun stx _ => do
match stx[1].isNameLit? with
| some val => toExpr (← resolveGlobalConstNoOverload val)
| some val => toExpr (← resolveGlobalConstNoOverloadWithInfo stx[1] val)
| none => throwIllFormedSyntax
@[builtinTermElab typeOf] def elabTypeOf : TermElab := fun stx _ => do