- options : Lean.Options
- openDecls : List Lean.OpenDecl
- macroStack : Lean.Elab.MacroStack
- errToSorry : Bool
Saved context for postponed terms and tactics to be executed.
- typeClass: Lean.Elab.Term.SyntheticMVarKind
- coe: Option String → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Expr → Option Lean.Expr → Lean.Elab.Term.SyntheticMVarKind
- tactic: Lean.Syntax → Lean.Elab.Term.SavedContext → Lean.Elab.Term.SyntheticMVarKind
- postponed: Lean.Elab.Term.SavedContext → Lean.Elab.Term.SyntheticMVarKind
We use synthetic metavariables as placeholders for pending elaboration steps.
Equations
- One or more equations did not get rendered due to their size.
- mvarId : Lean.MVarId
- stx : Lean.Syntax
- implicitArg: Lean.Expr → Lean.Elab.Term.MVarErrorKind
- hole: Lean.Elab.Term.MVarErrorKind
- custom: Lean.MessageData → Lean.Elab.Term.MVarErrorKind
Equations
- Lean.Elab.Term.instInhabitedMVarErrorKind = { default := Lean.Elab.Term.MVarErrorKind.implicitArg default }
Equations
- One or more equations did not get rendered due to their size.
- mvarId : Lean.MVarId
- ref : Lean.Syntax
- kind : Lean.Elab.Term.MVarErrorKind
Equations
- Lean.Elab.Term.instInhabitedMVarErrorInfo = { default := { mvarId := default, ref := default, kind := default, argName? := default } }
- ref : Lean.Syntax
- fvarId : Lean.FVarId
- attrs : Array Lean.Elab.Attribute
- shortDeclName : Lean.Name
- declName : Lean.Name
- lctx : Lean.LocalContext
- localInstances : Lean.LocalInstances
- type : Lean.Expr
- val : Lean.Expr
- mvarId : Lean.MVarId
Equations
- One or more equations did not get rendered due to their size.
- syntheticMVars : List Lean.Elab.Term.SyntheticMVarDecl
- mvarErrorInfos : Lean.MVarIdMap Lean.Elab.Term.MVarErrorInfo
- letRecsToLift : List Lean.Elab.Term.LetRecToLift
- infoState : Lean.Elab.InfoState
Equations
- Lean.Elab.Term.instInhabitedState = { default := { levelNames := default, syntheticMVars := default, mvarErrorInfos := default, letRecsToLift := default, infoState := default } }
Equations
- Lean.Elab.Tactic.instInhabitedState = { default := { goals := default } }
- core : Lean.Core.State
- meta : Lean.Meta.State
- term : Lean.Elab.Term.State
- tactic : Lean.Elab.Tactic.State
- stx : Lean.Syntax
Equations
- Lean.Elab.Tactic.instInhabitedSnapshot = { default := { core := default, meta := default, term := default, tactic := default, stx := default } }
Equations
- Lean.Elab.Tactic.instBEqCacheKey = { beq := [anonymous] }
Equations
- Lean.Elab.Tactic.instHashableCacheKey = { hash := [anonymous] }
Equations
- Lean.Elab.Tactic.instInhabitedCacheKey = { default := { mvarId := default, pos := default } }
Equations
- Lean.Elab.Tactic.instInhabitedCache = { default := { pre := default, post := default } }
- macroStack : Lean.Elab.MacroStack
When
mayPostpone == true
, an elaboration function may interrupt its execution by throwingException.postpone
. The functionelabTerm
catches this exception and creates fresh synthetic metavariable?m
, stores?m
in the list of pending synthetic metavariables, and returns?m
.mayPostpone : BoolWhen
errToSorry
is set to true, the methodelabTerm
catches exceptions and converts them into syntheticsorry
s. The implementation of choice nodes and overloaded symbols rely on the fact that whenerrToSorry
is set to false for an elaboration functionF
, thenerrToSorry
remainsfalse
for all elaboration functions invoked byF
. That is, it is safe to transitionerrToSorry
fromtrue
tofalse
, but we must not seterrToSorry
totrue
when it is currently set tofalse
.errToSorry : BoolWhen
autoBoundImplicit
is set to true, instead of producing an "unknown identifier" error for unbound variables, we generate an internal exception. This exception is caught atelabBinders
andelabTypeWithUnboldImplicit
. Both methods add implicit declarations for the unbound variable and try again.autoBoundImplicit : Bool- autoBoundImplicits : Std.PArray Lean.Expr
A name
n
is only eligible to be an auto implicit name ifautoBoundImplicitForbidden n = false
. We use this predicate to disallowf
to be considered an auto implicit name in a definition such asdef f : f → Bool := fun _ => true
Map from user name to internal unique name
sectionVars : Lean.NameMap Lean.NameMap from internal name to fvar
sectionFVars : Lean.NameMap Lean.ExprEnable/disable implicit lambdas feature.
implicitLambda : BoolNoncomputable sections automatically add the
noncomputable
modifier to any declaration we cannot generate code forisNoncomputableSection : BoolWhen
true
we skip TC failures. We use this option when processing patternsignoreTCFailures : Booltrue
when elaborating patterns. It affects how we elaborate named holes.inPattern : Bool- tacticCache? : Option (IO.Ref Lean.Elab.Tactic.Cache)
If
true
, we store in theExpr
theSyntax
for recursive applications (i.e., applications of free variables tagged withisAuxDecl
). We store theSyntax
usingmkRecAppWithSyntax
. We use theSyntax
object to produce better error messages atStructural.lean
andWF.lean
.saveRecAppSyntax : Bool
Equations
Equations
- Lean.Elab.Term.instMonadTermElabM = let i := inferInstanceAs (Monad Lean.Elab.TermElabM); Monad.mk
- meta : Lean.Meta.SavedState
- elab : Lean.Elab.Term.State
Equations
- Lean.Elab.Term.instInhabitedSavedState = { default := { meta := default, elab := default } }
Equations
- Lean.Elab.Term.saveState = do let a ← liftM Lean.Meta.saveState let a_1 ← get pure { meta := a, elab := a_1 }
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.instMonadBacktrackSavedStateTermElabM = { saveState := Lean.Elab.Term.saveState, restoreState := fun b => Lean.Elab.Term.SavedState.restore b false }
Equations
- Lean.Elab.Term.instInhabitedTermElabResult = { default := EStateM.Result.ok default default }
Execute x
, save resulting expression and new state.
We remove any Info
created by x
.
The info nodes are committed when we execute applyResult
.
We use observing
to implement overloaded notation and decls.
We want to save Info
nodes for the chosen alternative.
Equations
- One or more equations did not get rendered due to their size.
Apply the result/exception and state captured with observing
.
We use this method to implement overloaded notation and symbols.
Equations
- One or more equations did not get rendered due to their size.
Execute x
, but keep state modifications only if x
did not postpone.
This method is useful to implement elaboration functions that cannot decide whether
they need to postpone or not without updating the state.
Equations
Equations
- Lean.Elab.Term.getLevelNames = do let a ← get pure a.levelNames
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Execute x
but discard changes performed at Term.State
and Meta.State
.
Recall that the environment is at Core.State
. Thus, any updates to it will
be preserved. This method is useful for performing computations where all
metavariable must be resolved or discarded.
The info trees are not discarded, however, and wrapped in InfoTree.Context
to store their metavariable context.
Equations
- One or more equations did not get rendered due to their size.
Execute x
without storing Syntax
for recursive applications. See saveRecAppSyntax
field at Context
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
- fieldIdx: Lean.Syntax → Nat → Lean.Elab.Term.LVal
- fieldName: Lean.Syntax → String → Option Lean.Name → Lean.Syntax → Lean.Elab.Term.LVal
- getOp: Lean.Syntax → Lean.Syntax → Lean.Elab.Term.LVal
Auxiliary datatatype for presenting a Lean lvalue modifier.
We represent a unelaborated lvalue as a Syntax
(or Expr
) and List LVal
.
Example: a.foo[i].1
is represented as the Syntax
a
and the list
[LVal.fieldName "foo", LVal.getOp i, LVal.fieldIdx 1]
.
Recall that the notation a[i]
is not just for accessing arrays in Lean.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.LVal.isFieldName _fun_discr = match _fun_discr with | Lean.Elab.Term.LVal.fieldName ref name suffix? targetStx => true | x => false
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.getDeclName? = do let a ← read pure a.declName?
Equations
- Lean.Elab.Term.getLetRecsToLift = do let a ← get pure a.letRecsToLift
Equations
- Lean.Elab.Term.isExprMVarAssigned mvarId = do let a ← Lean.getMCtx pure (Lean.MetavarContext.isExprAssigned a mvarId)
Equations
- Lean.Elab.Term.getMVarDecl mvarId = do let a ← Lean.getMCtx pure (Lean.MetavarContext.getDecl a mvarId)
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
For testing TermElabM
methods. The #eval command will sign the error.
Equations
- Lean.Elab.Term.throwErrorIfErrors = do let a ← Lean.MonadLog.hasErrors if a = true then Lean.throwError (Lean.toMessageData "Error(s)") else pure PUnit.unit
Equations
- Lean.Elab.Term.traceAtCmdPos cls msg = Lean.withRef Lean.Syntax.missing (Lean.Elab.trace cls msg)
Equations
- Lean.Elab.Term.ppGoal mvarId = liftM (Lean.Meta.ppGoal mvarId)
Equations
- One or more equations did not get rendered due to their size.
Equations
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.registerSyntheticMVarWithCurrRef mvarId kind = do let a ← Lean.getRef Lean.Elab.Term.registerSyntheticMVar a mvarId kind
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.registerMVarErrorHoleInfo mvarId ref = Lean.Elab.Term.registerMVarErrorInfo { mvarId := mvarId, ref := ref, kind := Lean.Elab.Term.MVarErrorKind.hole, argName? := none }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.getMVarErrorInfo? mvarId = do let a ← get pure (Std.RBMap.find? a.mvarErrorInfos mvarId)
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.throwMVarError m = do let a ← Lean.MonadLog.hasErrors if a = true then Lean.Elab.throwAbortTerm else Lean.throwError m
Equations
- One or more equations did not get rendered due to their size.
Append mvarErrorInfo
argument name (if available) to the message.
Remark: if the argument name contains macro scopes we do not append it.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.MVarErrorInfo.logError.appendExtra extraMsg? msg = match extraMsg? with | none => msg | some extraMsg => msg ++ extraMsg
Try to log errors for the unassigned metavariables pendingMVarIds
.
Return true
if there were "unfilled holes", and we should "abort" declaration.
TODO: try to fill "all" holes using synthetic "sorry's"
Remark: We only log the "unfilled holes" as new errors if no error has been logged so far.
Equations
- One or more equations did not get rendered due to their size.
Ensure metavariables registered using registerMVarErrorInfos
(and used in the given declaration) have been assigned.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Creates syntax for (
:
)
Equations
- One or more equations did not get rendered due to their size.
Convert unassigned universe level metavariables into parameters.
The new parameter names are of the form u_i
where i >= nextParamIdx
.
The method returns the updated expression and new nextParamIdx
.
Remark: we make sure the generated parameter names do not clash with the universe at ctx.levelNames
.
Equations
- One or more equations did not get rendered due to their size.
Variant of levelMVarToParam
where nextParamIdx
is stored in a state monad.
Equations
- One or more equations did not get rendered due to their size.
Auxiliary method for creating fresh binder names. Do not confuse with the method for creating fresh free/meta variable ids.
Equations
- Lean.Elab.Term.mkFreshBinderName = Lean.withFreshMacroScope (Lean.MonadQuotation.addMacroScope `x)
Auxiliary method for creating a Syntax.ident
containing
a fresh name. This method is intended for creating fresh binder names.
It is just a thin layer on top of mkFreshUserName
.
Equations
- Lean.Elab.Term.mkFreshIdent ref = do let a ← Lean.Elab.Term.mkFreshBinderName pure (Lean.mkIdentFrom ref a).raw
Apply given attributes at a given application time
Equations
- Lean.Elab.Term.applyAttributesAt declName attrs applicationTime = Lean.Elab.Term.applyAttributesCore declName attrs (some applicationTime)
Equations
- Lean.Elab.Term.applyAttributes declName attrs = Lean.Elab.Term.applyAttributesCore declName attrs none
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
See containsPostponedTerm
Return true
if e
contains a pending metavariable. Remark: it also visits let-declarations.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.synthesizeCoeInstMVarCore instMVar = do let a ← Lean.getOptions Lean.Elab.Term.synthesizeInstMVarCore instMVar (some (Lean.Option.get a Lean.Elab.Term.maxCoeSize))
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
If expectedType?
is some t
, then ensure t
and eType
are definitionally equal.
If they are not, then try coercions.
Argument f?
is used only for generating error messages.
Equations
- One or more equations did not get rendered due to their size.
If expectedType?
is some t
, then ensure t
and type of e
are definitionally equal.
If they are not, then try coercions.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.exceptionToSorry ex expectedType? = do let syntheticSorry ← Lean.Elab.Term.mkSyntheticSorryFor expectedType? Lean.Elab.logException ex pure syntheticSorry
If mayPostpone == true
, throw Expection.postpone
.
Equations
- Lean.Elab.Term.tryPostpone = do let a ← read if a.mayPostpone = true then Lean.Elab.throwPostpone else pure PUnit.unit
If mayPostpone == true
and e
's head is a metavariable, throw Exception.postpone
.
Equations
- Lean.Elab.Term.tryPostponeIfMVar e = do let e ← liftM (Lean.Meta.whnfR e) if Lean.Expr.isMVar (Lean.Expr.getAppFn e) = true then Lean.Elab.Term.tryPostpone else pure PUnit.unit
Equations
- Lean.Elab.Term.tryPostponeIfNoneOrMVar e? = match e? with | some e => Lean.Elab.Term.tryPostponeIfMVar e | none => Lean.Elab.Term.tryPostpone
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.getSyntheticMVarDecl? mvarId = do let a ← get pure (List.find? (fun d => d.mvarId == mvarId) a.syntheticMVars)
Create an auxiliary annotation to make sure we create a Info
even if e
is a metavariable.
See mkTermInfo
.
We use this functions because some elaboration functions elaborate subterms that may not be immediately part of the resulting term. Example:
let_mvar% ?m := b; wait_if_type_mvar% ?m; body
If the type of b
is not known, then wait_if_type_mvar% ?m; body
is postponed and just return a fresh
metavariable ?n
. The elaborator for
let_mvar% ?m := b; wait_if_type_mvar% ?m; body
returns mkSaveInfoAnnotation ?n
to make sure the info nodes created when elaborating b
are "saved".
This is a bit hackish, but elaborators like let_mvar%
are rare.
Equations
- Lean.Elab.Term.mkSaveInfoAnnotation e = if Lean.Expr.isMVar e = true then Lean.mkAnnotation `save_info e else e
Equations
- Lean.Elab.Term.isSaveInfoAnnotation? e = Lean.annotation? `save_info e
Return some mvarId
if e
corresponds to a hole that is going to be filled "later" by executing a tactic or resuming elaboration.
We do not save ofTermInfo
for this kind of node in the InfoTree
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.addTermInfo' stx e expectedType? lctx? elaborator isBinder = discard (Lean.Elab.Term.addTermInfo stx e expectedType? lctx? elaborator isBinder)
Equations
- Lean.Elab.Term.withInfoContext' stx x mkInfo = do let a ← read if a.inPattern = true then do let e ← x pure (Lean.mkPatternWithRef e stx) else Lean.Elab.withInfoContext' x mkInfo
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.hasNoImplicitLambdaAnnotation type = Option.isSome (Lean.annotation? `noImplicitLambda type)
Equations
- Lean.Elab.Term.mkNoImplicitLambdaAnnotation type = if Lean.Elab.Term.hasNoImplicitLambdaAnnotation type = true then type else Lean.mkAnnotation `noImplicitLambda type
Block usage of implicit lambdas if stx
is @f
or @f arg1 ...
or fun
with an implicit binder annotation.
Equations
- One or more equations did not get rendered due to their size.
Store in the InfoTree
that e
is a "dot"-completion target.
Equations
- One or more equations did not get rendered due to their size.
Main function for elaborating terms.
It extracts the elaboration methods from the environment using the node kind.
Recall that the environment has a mapping from SyntaxNodeKind
to TermElab
methods.
It creates a fresh macro scope for executing the elaboration method.
All unlogged trace messages produced by the elaboration method are logged using
the position information at stx
. If the elaboration method throws an Exception.error
and errToSorry == true
,
the error is logged and a synthetic sorry expression is returned.
If the elaboration throws Exception.postpone
and catchExPostpone == true
,
a new synthetic metavariable of kind SyntheticMVarKind.postponed
is created, registered,
and returned.
The option catchExPostpone == false
is used to implement resumeElabTerm
to prevent the creation of another synthetic metavariable when resuming the elaboration.
If implicitLambda == true
, then disable implicit lambdas feature for the given syntax, but not for its subterms.
We use this flag to implement, for example, the @
modifier. If Context.implicitLambda == false
, then this parameter has no effect.
Equations
- Lean.Elab.Term.elabTerm stx expectedType? catchExPostpone implicitLambda = Lean.withRef stx (Lean.Elab.Term.elabTermAux expectedType? catchExPostpone implicitLambda stx)
Execute x
and then restore syntheticMVars
, levelNames
, mvarErrorInfos
, and letRecsToLift
.
We use this combinator when we don't want the pending problems created by x
to persist after its execution.
Equations
- One or more equations did not get rendered due to their size.
Execute x
and return some
if no new errors were recorded or exceptions was thrown. Otherwise, return none
Equations
- One or more equations did not get rendered due to their size.
Adapt a syntax transformation to a regular, term-producing elaborator.
Equations
- Lean.Elab.Term.adaptExpander exp stx expectedType? = do let stx' ← exp stx Lean.Elab.Term.withMacroExpansion stx stx' (Lean.Elab.Term.elabTerm stx' expectedType? true true)
Equations
- One or more equations did not get rendered due to their size.
Make sure e
is a type by inferring its type and making sure it is a Expr.sort
or is unifiable with Expr.sort
, or can be coerced into one.
Equations
- One or more equations did not get rendered due to their size.
Elaborate stx
and ensure result is a type.
Equations
- One or more equations did not get rendered due to their size.
Enable auto-bound implicits, and execute k
while catching auto bound implicit exceptions. When an exception is caught,
a new local declaration is created, registered, and k
is tried to be executed again.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Collect unassigned metavariables in type
that are not already in init
and not satisfying except
.
Equations
- One or more equations did not get rendered due to their size.
Return autoBoundImplicits ++ xs
This methoid throws an error if a variable in autoBoundImplicits
depends on some x
in xs
.
The autoBoundImplicits
may contain free variables created by the auto-implicit feature, and unassigned free variables.
It avoids the hack used at autoBoundImplicitsOld
.
Remark: we cannot simply replace every occurrence of addAutoBoundImplicitsOld
with this one because a particular
use-case may not be able to handle the metavariables in the array being given to k
.
Equations
- One or more equations did not get rendered due to their size.
Similar to autoBoundImplicits
, but immediately if the resulting array of expressions contains metavariables,
it immediately use mkForallFVars
+ forallBoundedTelescope
to convert them into free variables.
The type type
is modified during the process if type depends on xs
.
We use this method to simplify the conversion of code using autoBoundImplicitsOld
to autoBoundImplicits
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.resolveLocalName n = do let lctx ← Lean.getLCtx let view : Lean.MacroScopesView := Lean.extractMacroScopes n pure (Lean.Elab.Term.resolveLocalName.loop lctx view view.name [])
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Create an Expr.const
using the given name and explicit levels.
Remark: fresh universe metavariables are created if the constant has more universe
parameters than explicitLevels
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Similar to resolveName
, but creates identifiers for the main part and each projection with position information derived from ident
.
Example: Assume resolveName v.head.bla.boo
produces (v.head, ["bla", "boo"])
, then this method produces
(v.head, id, [f₁, f₂])
where id
is an identifier for v.head
, and f₁
and f₂
are identifiers for fields "bla"
and "boo"
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.TermElabM.run x ctx s = Lean.Meta.withConfig Lean.Elab.Term.setElabConfig (StateRefT'.run (x ctx) s)
Equations
- Lean.Elab.Term.TermElabM.run' x ctx s = (fun a => a.fst) <$> Lean.Elab.Term.TermElabM.run x ctx s
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Execute x
and then tries to solve pending universe constraints.
Note that, stuck constraints will not be discarded.
Equations
- Lean.Elab.Term.universeConstraintsCheckpoint x = do let a ← x discard (liftM (Lean.Meta.processPostponed true true)) pure a
Equations
- One or more equations did not get rendered due to their size.
Helper function for "embedding" an Expr
in Syntax
.
It creates a named hole ?m
and immediately assigns e
to it.
Examples:
let e := mkConst ``Nat.zero
`(Nat.succ $(← exprToSyntax e))
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.withoutModifyingStateWithInfoAndMessages x = controlAt Lean.Elab.TermElabM fun runInBase => Lean.Elab.Term.withoutModifyingStateWithInfoAndMessagesImpl (runInBase x)