The kind of a tactic metavariable, used for additional error reporting.
- term : TacticMVarKind
Standard tactic metavariable, arising from
by ...syntax. - autoParam
(argName : Name)
: TacticMVarKind
Tactic metavariable arising from an autoparam for a function application.
- fieldAutoParam
(fieldName structName : Name)
: TacticMVarKind
Tactic metavariable arising from an autoparam for a structure field.
Instances For
We use synthetic metavariables as placeholders for pending elaboration steps.
- typeClass
(extraErrorMsg? : Option MessageData)
: SyntheticMVarKind
Use typeclass resolution to synthesize value for metavariable. If
extraErrorMsg?issome msg,msgcontains additional information to include in error messages regarding type class synthesis failure. - coe
(header? : Option String)
(expectedType e : Expr)
(f? : Option Expr)
(mkErrorMsg? : Option (MVarId → Expr → Expr → MetaM MessageData))
: SyntheticMVarKind
Use coercion to synthesize value for the metavariable. If synthesis fails, then throws an error.
- If
mkErrorMsg?is provided, then the errormkErrorMsg expectedType eis thrown. ThemkErrorMsgfunction is allowed to throw an error itself. - Otherwise, throws a default type mismatch error message.
If
header?is not provided, the default header is "type mismatch". Iff?is provided, then throws an application type mismatch error.
- If
- tactic
(tacticCode : Syntax)
(ctx : SavedContext)
(kind : TacticMVarKind)
(delayOnMVars : Bool := false)
: SyntheticMVarKind
Use tactic to synthesize value for metavariable.
If
delayOnMVarsis true, the tactic will not be executed until the goal is free of unassigned expr metavariables. - postponed
(ctx : SavedContext)
: SyntheticMVarKind
Metavariable represents a hole whose elaboration has been postponed.
Instances For
Convert an "extra" optional error message into a message "\n{msg}" (if some msg) and MessageData.nil (if none)
Equations
- Lean.Elab.Term.extraMsgToMsg (some msg) = Lean.toMessageData "\n" ++ Lean.toMessageData msg
- Lean.Elab.Term.extraMsgToMsg extraErrorMsg? = Lean.MessageData.nil
Instances For
Equations
- One or more equations did not get rendered due to their size.
- stx : Syntax
- kind : SyntheticMVarKind
Instances For
Equations
Instances For
We can optionally associate an error context with a metavariable (see MVarErrorInfo).
We have three different kinds of error context.
- implicitArg
(lctx : LocalContext)
(ctx : Expr)
: MVarErrorKind
Metavariable for implicit arguments.
ctxis the parent application,lctxis a local context where it is valid (necessary for eta feature for named arguments). - hole : MVarErrorKind
Metavariable for explicit holes provided by the user (e.g.,
_and?m) - custom
(msgData : MessageData)
: MVarErrorKind
"Custom",
msgDatastores the additional error messages.
Instances For
Equations
- One or more equations did not get rendered due to their size.
We can optionally associate an error context with metavariables.
- mvarId : MVarId
- ref : Syntax
- kind : MVarErrorKind
Instances For
Equations
Instances For
When reporting unexpected universe level metavariables, it is useful to localize the errors
to particular terms, especially at let bindings and function binders,
where universe polymorphism is not permitted.
- lctx : LocalContext
- expr : Expr
- ref : Syntax
- msgData? : Option MessageData
Instances For
Equations
Instances For
Nested let rec expressions are eagerly lifted by the elaborator.
We store the information necessary for performing the lifting here.
- ref : Syntax
- fvarId : FVarId
- shortDeclName : Name
- declName : Name
- lctx : LocalContext
- localInstances : LocalInstances
- type : Expr
- val : Expr
- mvarId : MVarId
- termination : TerminationHints
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
State of the TermElabM monad.
- syntheticMVars : MVarIdMap SyntheticMVarDecl
- mvarErrorInfos : List MVarErrorInfo
List of errors associated to a metavariable that are shown to the user if the metavariable could not be fully instantiated
- levelMVarErrorInfos : List LevelMVarErrorInfo
List of data to be able to localize universe level metavariable errors to particular expressions.
mvarArgNamesstores the argument names associated to metavariables. These are used in combination withmvarErrorInfosfor throwing errors about metavariables that could not be fully instantiated. For example when elaboratingList _, the argument name of the placeholder will beα.While elaborating an application,
mvarArgNamesis set for each metavariable argument, using the available argument name. This may happen before or after themvarErrorInfosis set for the same metavariable.We used to store the argument names in
mvarErrorInfos, updating theMVarErrorInfosto add the argument name when it is available, but this doesn't work if the argument name is available before themvarErrorInfosis set for that metavariable.- letRecsToLift : List LetRecToLift
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
State of the TacticM monad.
Instances For
Equations
Instances For
Equations
Snapshots are used to implement the save tactic.
This tactic caches the state of the system, and allows us to "replay"
expensive proofs efficiently. This is only relevant implementing the
LSP server.
- core : Core.State
- meta : Meta.State
- term : Term.State
- tactic : State
- stx : Syntax
Instances For
Equations
Instances For
Equations
Instances For
Snapshot after finishing execution of a tactic.
- state? : Option SavedState
State saved for reuse, if no fatal exception occurred.
- moreSnaps : Array (Language.SnapshotTask Language.SnapshotTree)
Untyped snapshots from
logSnapshotTask, saved at this level for cancellation.
Instances For
Equations
Instances For
Equations
- Lean.Elab.Tactic.instToSnapshotTreeTacticFinishedSnapshot = { toSnapshotTree := fun (s : Lean.Elab.Tactic.TacticFinishedSnapshot) => { element := s.toSnapshot, children := s.moreSnaps } }
Snapshot just before execution of a tactic.
- stx : Syntax
Syntax tree of the tactic, stored and compared for incremental reuse.
- inner? : Option (Language.SnapshotTask TacticParsedSnapshot)
Task for nested incrementality, if enabled for tactic.
- finished : Language.SnapshotTask TacticFinishedSnapshot
Task for state after tactic execution.
Tasks for subsequent, potentially parallel, tactic steps.
Instances For
Equations
Instances For
- macroStack : MacroStack
- mayPostpone : Bool
When
mayPostpone == true, an elaboration function may interrupt its execution by throwingException.postpone. The functionelabTermcatches this exception and creates fresh synthetic metavariable?m, stores?min the list of pending synthetic metavariables, and returns?m. - errToSorry : Bool
When
errToSorryis set to true, the methodelabTermcatches exceptions and converts them into syntheticsorrys. The implementation of choice nodes and overloaded symbols rely on the fact that whenerrToSorryis set to false for an elaboration functionF, thenerrToSorryremainsfalsefor all elaboration functions invoked byF. That is, it is safe to transitionerrToSorryfromtruetofalse, but we must not seterrToSorrytotruewhen it is currently set tofalse. - autoBoundImplicit : Bool
When
autoBoundImplicitis set to true, instead of producing an "unknown identifier" error for unbound variables, we generate an internal exception. This exception is caught atwithAutoBoundImplicitwhich adds an implicit declaration for the unbound variable and tries again. A name
nis only eligible to be an auto implicit name ifautoBoundImplicitForbidden n = false. We use this predicate to disallowfto be considered an auto implicit name in a definition such asdef f : f → Bool := fun _ => trueMap from user name to internal unique name
Map from internal name to fvar
- implicitLambda : Bool
Enable/disable implicit lambdas feature.
- heedElabAsElim : Bool
Heed
elab_as_elimattribute. - isNoncomputableSection : Bool
Noncomputable sections automatically add the
noncomputablemodifier to any declaration we cannot generate code for. - ignoreTCFailures : Bool
When
truewe skip TC failures. We use this option when processing patterns. - inPattern : Bool
truewhen elaborating patterns. It affects how we elaborate named holes. - tacSnap? : Option (Language.SnapshotBundle Tactic.TacticParsedSnapshot)
Snapshot for incremental processing of current tactic, if any.
Invariant: if the bundle's
old?is set, then the state up to the start of the tactic is unchanged, i.e. reuse is possible. - saveRecAppSyntax : Bool
If
true, we store in theExprtheSyntaxfor recursive applications (i.e., applications of free variables tagged withisAuxDecl). We store theSyntaxusingmkRecAppWithSyntax. We use theSyntaxobject to produce better error messages atStructural.leanandWF.lean. - holesAsSyntheticOpaque : Bool
If
holesAsSyntheticOpaqueistrue, then we mark metavariables associated with_s assyntheticOpaqueif they do not occur in patterns. This option is useful when elaborating terms in tactics such asrefine'where we want holes there to become new goals. See issue #1681, we have `refine' (fun x => _) - checkDeprecated : Bool
If
checkDeprecated := true, thenLinter.checkDeprecatedwhen creating constants.
Instances For
Equations
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.saveState = do let __do_lift ← liftM Lean.Meta.saveState let __do_lift_1 ← get pure { «meta» := __do_lift, «elab» := __do_lift_1 }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Like Meta.withRestoreOrSaveFull for TermElabM, but also takes a tacSnap? that
- when running
act, is set asContext.tacSnap? - otherwise (i.e. on restore) is used to update the new snapshot promise to the old task's
value.
This extra restore step is necessary because while
reusableResult?can be used to replay any effects onState,Context.tacSnap?is not part of it but changed via anIOside effect, so it needs to be replayed separately.
We use an explicit parameter instead of accessing Context.tacSnap? directly because this prevents
withRestoreOrSaveFull and withReader from being used in the wrong order.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.instMonadBacktrackSavedStateTermElabM = { saveState := Lean.Elab.Term.saveState, restoreState := fun (b : Lean.Elab.Term.SavedState) => b.restore }
Incremental elaboration helper. Avoids leakage of data from outside syntax via the monadic context
when running act on stx by
- setting
stxas therefand - deactivating
suppressElabErrorsifstxismissing-free, which also helps with not hiding useful errors in this part of the input. Note that ifstxhasmissing, this should always be true for the outer syntax as well, so taking the old value ofsuppressElabErrorsinto account should not introduce data leakage.
This combinator should always be used when narrowing reuse to a syntax subtree, usually (in the case
of tactics, to be generalized) via withNarrowed(Arg)TacticReuse.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Manages reuse information for nested tactics by splitting given syntax into an outer and inner
part. act is then run on the inner part but with reuse information adjusted as following:
- If the old (from
tacSnap?'sSyntaxGuarded.stx) and new (fromstx) outer syntax are not identical according toSyntax.eqWithInfo, reuse is disabled. - Otherwise, the old syntax as stored in
tacSnap?is updated to the old inner syntax. - In any case,
withReuseContextis used on the new inner syntax to further prepare the monadic context.
For any tactic that participates in reuse, withNarrowedTacticReuse should be applied to the
tactic's syntax and act should be used to do recursive tactic evaluation of nested parts. Also,
after this function, getAndEmptySnapshotTasks should be called and the result stored in a snapshot
so that the tasks don't end up in a snapshot further up and are cancelled together with it; see
note [Incremental Cancellation].
Equations
- One or more equations did not get rendered due to their size.
Instances For
A variant of withNarrowedTacticReuse that uses stx[argIdx] as the inner syntax and all stx
child nodes before that as the outer syntax, i.e. reuse is disabled if there was any change before
argIdx.
NOTE: child nodes after argIdx are not tested (which would almost always disable reuse as they are
necessarily shifted by changes at argIdx) so it must be ensured that the result of arg does not
depend on them (i.e. they should not be inspected beforehand).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Disables incremental tactic reuse and reporting for act if cond is true by setting tacSnap?
to none. This should be done for tactic blocks that are run multiple times as otherwise the
reported progress will jump back and forth (and partial reuse for these kinds of tact blocks is
similarly questionable).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Disables incremental tactic reuse for act if cond is true.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Wraps the given action for use in BaseIO.asTask etc., discarding its final state except for
logSnapshotTask tasks, which are reported as part of the returned tree. The given cancellation
token, if any, should be stored in a SnapshotTask for the server to trigger it when the result is
no longer needed.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
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.
Instances For
Apply the result/exception and state captured with observing.
We use this method to implement overloaded notation and symbols.
Equations
- Lean.Elab.Term.applyResult (EStateM.Result.ok a r) = do r.restore true pure a
- Lean.Elab.Term.applyResult (EStateM.Result.error ex r) = do r.restore true throw ex
Instances For
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
Instances For
Return the universe level names explicitly provided by the user.
Equations
- Lean.Elab.Term.getLevelNames = do let __do_lift ← get pure __do_lift.levelNames
Instances For
Given a free variable fvar, return its declaration.
This function panics if fvar is not a free variable.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Instances For
Equations
- Lean.Elab.Term.mkTermElabAttributeUnsafe ref = Lean.Elab.mkElabAttribute Lean.Elab.Term.TermElab `builtin_term_elab `term_elab `Lean.Parser.Term `Lean.Elab.Term.TermElab "term" ref
Instances For
Registers a term elaborator for the given syntax node kind.
A term elaborator should have type Lean.Elab.Term.TermElab (which is
Lean.Syntax → Option Lean.Expr → Lean.Elab.Term.TermElabM Lean.Expr), i.e. should take syntax of
the given syntax node kind and an optional expected type as parameters and produce an expression.
The elab_rules and elab commands should usually be preferred over using this attribute
directly.
Auxiliary datatype for presenting a Lean lvalue modifier.
We represent an unelaborated lvalue as a Syntax (or Expr) and List LVal.
Example: a.foo.1 is represented as the Syntax a and the list
[LVal.fieldName "foo", LVal.fieldIdx 1].
- fieldIdx (ref : Syntax) (i : Nat) : LVal
- fieldName
(ref : Syntax)
(name : String)
(suffix? : Option Name)
(fullRef : Syntax)
: LVal
Field
suffix?is for producing better error messages becausex.ymay be a field access or a hierarchical/composite name.refis the syntax object representing the field.fullRefincludes the LHS.
Instances For
Equations
- (Lean.Elab.Term.LVal.fieldIdx ref i).getRef = ref
- (Lean.Elab.Term.LVal.fieldName ref name suffix? fullRef).getRef = ref
Instances For
Equations
- (Lean.Elab.Term.LVal.fieldName ref name suffix? fullRef).isFieldName = true
- x✝.isFieldName = false
Instances For
Equations
- One or more equations did not get rendered due to their size.
Return the name of the declaration being elaborated if available.
Equations
- Lean.Elab.Term.getDeclName? = do let __do_lift ← read pure __do_lift.declName?
Instances For
Return the list of nested let rec declarations that need to be lifted.
Equations
- Lean.Elab.Term.getLetRecsToLift = do let __do_lift ← get pure __do_lift.letRecsToLift
Instances For
Return the declaration of the given metavariable
Equations
- Lean.Elab.Term.getMVarDecl mvarId = do let __do_lift ← Lean.getMCtx pure (__do_lift.getDecl mvarId)
Instances For
Equations
- Lean.Elab.Term.instMonadParentDeclTermElabM = { getParentDeclName? := Lean.Elab.Term.getDeclName? }
Executes x in the context of the given declaration name. Ensures that the info tree is set up
correctly and adjusts the declaration name generator to generate names below this name, resetting
the nested counter.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute x using levelNames as the universe level parameter names. See getLevelNames.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute x without converting errors (i.e., exceptions) to sorry applications.
Recall that when errToSorry = true, the method elabTerm catches exceptions and converts them into sorry applications.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute x without heeding the elab_as_elim attribute. Useful when there is
no expected type (so elabAppArgs would fail), but expect that the user wants
to use such constants.
Equations
Instances For
Execute x but discard changes performed at Term.State and Meta.State.
Recall that the Environment, InfoState and messages are 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 InfoTrees are not discarded, however, and wrapped in InfoTree.Context
to store their metavariable context.
Equations
- Lean.Elab.Term.withoutModifyingElabMetaStateWithInfo x = do let s ← get let sMeta ← getThe Lean.Meta.State tryFinally (Lean.Elab.withSaveInfoContext x) do set s set sMeta
Instances For
Wraps the trees returned from getInfoTrees, if any, in an InfoTree.context node based on the
current monadic context and state. This is mainly used to report info trees early via
Snapshot.infoTree?. The trees are not removed from the getInfoTrees state as the final info tree
of the elaborated command should be complete and not depend on whether parts have been reported
early.
As InfoTree.context can have only one child, this function panics if trees contains more than 1
tree. Also, PartialContextInfo.parentDeclCtx is not currently generated as that information is not
available in the monadic context and only needed for the final info tree.
Equations
- One or more equations did not get rendered due to their size.
Instances For
For testing TermElabM methods. The #eval command will sign the error.
Equations
- Lean.Elab.Term.throwErrorIfErrors = do let __do_lift ← Lean.MonadLog.hasErrors if __do_lift = true then Lean.throwError (Lean.toMessageData "Error(s)") else pure PUnit.unit
Instances For
Equations
- Lean.Elab.Term.traceAtCmdPos cls msg = Lean.withRef Lean.Syntax.missing (Lean.trace cls msg)
Instances For
Equations
- Lean.Elab.Term.ppGoal mvarId = liftM (Lean.Meta.ppGoal mvarId)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Elaborate x with stx on the macro stack and produce macro expansion info
Equations
- Lean.Elab.Term.withMacroExpansion beforeStx afterStx x = Lean.Elab.withMacroExpansionInfo beforeStx afterStx (Lean.Elab.Term.withPushMacroExpansionStack beforeStx afterStx x)
Instances For
Add the given metavariable to the list of pending synthetic metavariables.
The method synthesizeSyntheticMVars is used to process the metavariables on this list.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.registerSyntheticMVarWithCurrRef mvarId kind = do let __do_lift ← Lean.getRef Lean.Elab.Term.registerSyntheticMVar __do_lift mvarId kind
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.registerMVarErrorHoleInfo mvarId ref = Lean.Elab.Term.registerMVarErrorInfo { mvarId := mvarId, ref := ref, kind := Lean.Elab.Term.MVarErrorKind.hole }
Instances For
Equations
- Lean.Elab.Term.registerMVarErrorCustomInfo mvarId ref msgData = Lean.Elab.Term.registerMVarErrorInfo { mvarId := mvarId, ref := ref, kind := Lean.Elab.Term.MVarErrorKind.custom msgData }
Instances For
Equations
- Lean.Elab.Term.registerCustomErrorIfMVar e ref msgData = match e.getAppFn with | Lean.Expr.mvar mvarId => Lean.Elab.Term.registerMVarErrorCustomInfo mvarId ref msgData | x => pure ()
Instances For
Auxiliary method for reporting errors of the form "... contains metavariables ...".
This kind of error is thrown, for example, at Match.lean where elaboration
cannot continue if there are metavariables in patterns.
We only want to log it if we haven't logged any errors so far.
Equations
- Lean.Elab.Term.throwMVarError m = do let __do_lift ← Lean.MonadLog.hasErrors if __do_lift = true then Lean.Elab.throwAbortTerm else Lean.throwError m
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Try to log errors for unassigned level metavariables pendingLevelMVarIds.
Returns true if there are any relevant LevelMVarErrorInfos and we should "abort" the declaration.
Remark: we only log unassigned level metavariables as new errors if no error has been logged so far.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Instances For
Execute x without allowing it to postpone elaboration tasks.
That is, tryPostpone is a noop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates syntax for ( <ident> : <type> )
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert unassigned universe level metavariables into parameters.
The new parameter names are fresh names of the form u_i with regard to ctx.levelNames, which is updated with the new names.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a fresh inaccessible binder name based on x.
Equivalent to Lean.Core.mkFreshUserName `x.
Do not confuse with Lean.mkFreshId, for creating fresh free variable and metavariable ids.
Equations
Instances For
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 canonical = do let __do_lift ← Lean.Elab.Term.mkFreshBinderName pure (Lean.mkIdentFrom ref __do_lift canonical)
Instances For
Apply given attributes at a given application time
Equations
- Lean.Elab.Term.applyAttributesAt declName attrs applicationTime = Lean.Elab.Term.applyAttributesCore✝ declName attrs (some applicationTime)
Instances For
Equations
- Lean.Elab.Term.applyAttributes declName attrs = Lean.Elab.Term.applyAttributesCore✝ declName attrs none
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Lean.Elab.Term.throwTypeMismatchError header? expectedType eType e (some f) _extraMsg? = Lean.Meta.throwAppTypeMismatch f e
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
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.
Instances For
Try to synthesize metavariable using type class resolution.
This method assumes the local context and local instances of instMVar coincide
with the current local context and local instances.
Return true if the instance was synthesized successfully, and false if
the instance contains unassigned metavariables that are blocking the type class
resolution procedure. Throw an exception if resolution or assignment irrevocably fails.
If extraErrorMsg? is not none, it contains additional information that should be attached
to type class synthesis failures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.mkCoeWithErrorMsgs expectedType e mkImmedErrorMsg mkErrorMsg = Lean.Elab.Term.mkCoe expectedType e none none (some mkErrorMsg) (some mkImmedErrorMsg)
Instances For
If expectedType? is some t, then ensures t and eType are definitionally equal by inserting a coercion if necessary.
Argument f? is used only for generating error messages when inserting coercions fails.
Equations
- One or more equations did not get rendered due to their size.
- Lean.Elab.Term.ensureHasType expectedType? e errorMsgHeader? f? = pure e
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Lean.Elab.Term.ensureHasTypeWithErrorMsgs expectedType? e mkImmedErrorMsg mkErrorMsg = pure e
Instances For
Log the given exception, and create a synthetic sorry for representing the failed
elaboration step with exception ex.
Equations
- Lean.Elab.Term.exceptionToSorry ex expectedType? = do Lean.Elab.logException ex Lean.Elab.Term.mkSyntheticSorryFor✝ expectedType?
Instances For
If mayPostpone == true, throw Exception.postpone.
Equations
- Lean.Elab.Term.tryPostpone = do let __do_lift ← read if __do_lift.mayPostpone = true then Lean.Elab.throwPostpone else pure PUnit.unit
Instances For
Return true if e reduces (by unfolding only [reducible] declarations) to ?m ...
Equations
- Lean.Elab.Term.isMVarApp e = do let __do_lift ← liftM (Lean.Meta.whnfR e) pure __do_lift.getAppFn.isMVar
Instances For
If mayPostpone == true and e's head is a metavariable, throw Exception.postpone.
Equations
- Lean.Elab.Term.tryPostponeIfMVar e = do let __do_lift ← Lean.Elab.Term.isMVarApp e if __do_lift = true then Lean.Elab.Term.tryPostpone else pure PUnit.unit
Instances For
Throws Exception.postpone, if expectedType? contains unassigned metavariables.
It is a noop if mayPostpone == false.
Equations
- One or more equations did not get rendered due to their size.
- Lean.Elab.Term.tryPostponeIfHasMVars? expectedType? = do Lean.Elab.Term.tryPostponeIfNoneOrMVar expectedType? pure none
Instances For
Throws Exception.postpone, if expectedType? contains unassigned metavariables.
If mayPostpone == false, it throws error msg.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Save relevant context for term elaboration postponement.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute x with the context saved using saveContext.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.getSyntheticMVarDecl? mvarId = do let __do_lift ← get pure (Std.TreeMap.get? __do_lift.syntheticMVars mvarId)
Instances For
Creates a new metavariable of type type that will be synthesized using the tactic code.
The tacticCode syntax is the full by .. syntax.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Create an auxiliary annotation to make sure we create an Info even if e is a metavariable.
See mkTermInfo.
We use this function 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 returns 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 e.isMVar = true then Lean.mkAnnotation `save_info e else e
Instances For
Equations
- Lean.Elab.Term.isSaveInfoAnnotation? e = Lean.annotation? `save_info e
Instances For
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.
- Lean.Elab.Term.isTacticOrPostponedHole? e = pure none
Instances For
Pushes a new leaf node to the info tree associating the expression e to the syntax stx.
As a result, when the user hovers over stx they will see the type of e, and if e
is a constant they will see the constant's doc string.
expectedType?: the expected type ofeat the point of elaboration, if availablelctx?: the local context in which to interprete(otherwise it will use← getLCtx)elaborator: a declaration name used as an alternative target for go-to-definitionisBinder: if true, this will be treated as defininge(which should be a local constant) for the purpose of go-to-definition on local variablesforce: In patterns, the effect ofaddTermInfois usually suppressed and replaced by apatternWithRef?annotation which will be turned into a term info on the post-match-elaboration expression. This flag overrides that behavior and adds the term info immediately. (See https://github.com/leanprover/lean4/pull/1664.)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.addTermInfo' stx e expectedType? lctx? elaborator isBinder = discard (Lean.Elab.Term.addTermInfo stx e expectedType? lctx? elaborator isBinder)
Instances For
Info node capturing def/let rec bodies, used by the unused variables linter.
The body as a fully elaborated term.
noneif the body failed to elaborate.
Instances For
Creates an Info.ofCustomInfo node backed by a BodyInfo.
Equations
- Lean.Elab.Term.mkBodyInfo stx value? = Lean.Elab.Info.ofCustomInfo { stx := stx, value := Dynamic.mk { value? := value? } }
Instances For
Extracts a BodyInfo custom info.
Equations
- Lean.Elab.Term.getBodyInfo? (Lean.Elab.Info.ofCustomInfo { stx := stx, value := value }) = Dynamic.get? Lean.Elab.Term.BodyInfo value
- Lean.Elab.Term.getBodyInfo? x✝ = none
Instances For
Postpone the elaboration of stx, return a metavariable that acts as a placeholder, and
ensures the info tree is updated and a hole id is introduced.
When stx is elaborated, new info nodes are created and attached to the new hole id in the info tree.
Equations
- Lean.Elab.Term.postponeElabTerm stx expectedType? = Lean.Elab.Term.withTermInfoContext' Lean.Name.anonymous stx (Lean.Elab.Term.postponeElabTermCore✝ stx expectedType?) expectedType?
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.hasNoImplicitLambdaAnnotation type = (Lean.annotation? `noImplicitLambda type).isSome
Instances For
Equations
- Lean.Elab.Term.mkNoImplicitLambdaAnnotation type = if Lean.Elab.Term.hasNoImplicitLambdaAnnotation type = true then type else Lean.mkAnnotation `noImplicitLambda type
Instances For
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.
Instances For
Return true iff stx is a Syntax.ident, and it is a local variable.
Equations
- Lean.Elab.Term.isLocalIdent? (Lean.Syntax.ident info rawVal val preresolved) = do let r? ← Lean.resolveLocalName val match r? with | some (fvar, []) => pure (some fvar) | x => pure none
- Lean.Elab.Term.isLocalIdent? stx = pure none
Instances For
- no : UseImplicitLambdaResult
- yes (expectedType : Expr) : UseImplicitLambdaResult
- postpone : UseImplicitLambdaResult
Instances For
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 == false, 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)
Instances For
Similar to Lean.Elab.Term.elabTerm, but ensures that the type of the elaborated term is expectedType?
by inserting coercions if necessary.
If errToSorry is true, then if coercion insertion fails, this function returns sorry and logs the error.
Otherwise, it throws the error.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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?)
Instances For
Create a new metavariable with the given type, and try to synthesize it.
If type class resolution cannot be executed (e.g., it is stuck because of metavariables in type),
register metavariable as a pending one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Make sure e is a type by inferring its type and making sure it is an 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.
Instances For
Elaborate stx and ensure result is a type.
Equations
- Lean.Elab.Term.elabType stx = do let u ← liftM Lean.Meta.mkFreshLevelMVar let type ← Lean.Elab.Term.elabTerm stx (some (Lean.mkSort u)) Lean.withRef stx (Lean.Elab.Term.ensureType type)
Instances For
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.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
Instances For
Adds an InlayHintInfo for the fvar auto implicits in autos at inlayHintPos.
The inserted inlay hint has a hover that denotes the type of the auto-implicit (with meta-variables)
and can be inserted at inlayHintPos.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return autoBoundImplicits ++ xs
This method 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.
If inlayHintPos? is set, this function also inserts an inlay hint denoting autoBoundImplicits.
See addAutoBoundImplicitsInlayHint for more information.
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.
Instances For
Similar to addAutoBoundImplicits, but converts all metavariables into free variables.
It uses mkForallFVars + forallBoundedTelescope to convert metavariables 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.
Instances For
Equations
- Lean.Elab.Term.mkAuxName suffix = Lean.mkAuxDeclName suffix
Instances For
Return true if mvarId is an auxiliary metavariable created for compiling let rec or it
is delayed assigned to one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
If checkDeprecated := true, then Linter.checkDeprecated is invoked.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Term.checkDeprecated ref e = match e.getAppFn with | Lean.Expr.const declName us => Lean.withRef ref (Lean.Elab.Term.checkDeprecatedCore✝ declName) | x => pure PUnit.unit
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.
- Lean.Elab.Term.resolveName' ident explicitLevels expectedType? = Lean.throwError (Lean.toMessageData "identifier expected")
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Lean.Elab.Term.resolveId? stx kind withInfo = Lean.withRef stx (Lean.throwError (Lean.toMessageData "identifier expected"))
Instances For
Equations
Instances For
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
Instances For
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.
Instances For
Equations
- One or more equations did not get rendered due to their size.