This module provides four (mutually dependent) goodies that are needed for building the elaborator and tactic frameworks. 1- Weak head normal form computation with support for metavariables and transparency modes. 2- Definitionally equality checking with support for metavariables (aka unification modulo definitional equality). 3- Type inference. 4- Type class resolution.
They are packed into the MetaM monad.
Configuration for projection reduction. See whnfCore.
- no : ProjReductionKind
Projections
s.iare not reduced atwhnfCore. - yes : ProjReductionKind
Projections
s.iare reduced atwhnfCore, andwhnfCoreis used atsduring the process. Recall thatwhnfCoredoes not performdeltareduction (i.e., it will not unfold constant declarations). - yesWithDelta : ProjReductionKind
- yesWithDeltaI : ProjReductionKind
Projections
s.iare reduced atwhnfCore, andwhnfAtMostIis used atsduring the process. Recall thatwhnfAtMostIis likewhnfbut uses transparency at mostinstances. This option is stronger thanyes, but weaker thanyesWithDelta. We use this option to ensure we reduce projections to prevent expensive defeq checks when unifying TC operations. When unifying e.g.(@Field.toNeg α inst1).1 =?= (@Field.toNeg α inst2).1, we only want to unify negation (and not all other field operations as well). Unifying the field instances slowed down unification: https://github.com/leanprover/lean4/issues/1986
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Configuration flags for the MetaM monad.
Many of them are used to control the isDefEq function that checks whether two terms are definitionally equal or not.
Recall that when isDefEq is trying to check whether
?m@C a₁ ... aₙ and t are definitionally equal (?m@C a₁ ... aₙ =?= t), where
?m@C as a shorthand for C |- ?m : t where t is the type of ?m.
We solve it using the assignment ?m := fun a₁ ... aₙ => t if
a₁ ... aₙare pairwise distinct free variables that are not let-variables.a₁ ... aₙare not inCtonly contains free variables inCand/or{a₁, ..., aₙ}- For every metavariable
?m'@C'occurring int,C'is a subprefix ofC ?mdoes not occur int
- foApprox : Bool
If
foApproxis set to true, and someaᵢis not a free variable, then we use first-order unification?m a_1 ... a_i a_{i+1} ... a_{i+k} =?= f b_1 ... b_kreduces to
?m a_1 ... a_i =?= f a_{i+1} =?= b_1 ... a_{i+k} =?= b_k - ctxApprox : Bool
When
ctxApproxis set to true, we relax condition 4, by creating an auxiliary metavariable?n'with a smaller context than?m'. - quasiPatternApprox : Bool
When
quasiPatternApproxis set to true, we ignore condition 2. - constApprox : Bool
When
constApproxis set to true, we solve?m t =?= cusing?m := fun _ => cwhen?m tis not a higher-order pattern andcis not an application as - isDefEqStuckEx : Bool
When the following flag is set,
isDefEqthrows the exceptionException.isDefEqStuckwhenever it encounters a constraint?m ... =?= twhere?mis read only. This feature is useful for type class resolution where we may want to notify the caller that the TC problem may be solvable later after it assigns?m. - unificationHints : Bool
Enable/disable the unification hints feature.
- proofIrrelevance : Bool
Enables proof irrelevance at
isDefEq - assignSyntheticOpaque : Bool
By default synthetic opaque metavariables are not assigned by
isDefEq. Motivation: we want to make sure typing constraints resolved during elaboration should not "fill" holes that are supposed to be filled using tactics. However, this restriction is too restrictive for tactics such asexact t. When elaboratingt, we dot not fill named holes when solving typing constraints or TC resolution. But, we ignore the restriction when we try to unify the type oftwith the goal target type. We claim this is not a hack and is defensible behavior because this last unification step is not really part of the term elaboration. - offsetCnstrs : Bool
Enable/Disable support for offset constraints such as
?x + 1 =?= e - transparency : TransparencyMode
- etaStruct : EtaStructMode
Eta for structures configuration mode.
- univApprox : Bool
When
univApproxis set to true, we use approximations when solving postponed universe constraints. Examples:max u ?v =?= uis solved with?v := uand ignoring the solution?v := 0.max u w =?= max u ?vis solved with?v := wignoring the solution?v := max u w
- iota : Bool
- beta : Bool
If
true, reduce terms such as(fun x => t[x]) aintot[a] - proj : ProjReductionKind
Control projection reduction at
whnfCore. - zeta : Bool
Zeta reduction:
let x := v; e[x]andhave x := v; e[x]reduce toe[v]. We say a let-declarationlet x := v; eis nondependent if it is equivalent to(fun x => e) v. Recall thatfun x : BitVec 5 => let n := 5; fun y : BitVec n => x = yis type correct, but
fun x : BitVec 5 => (fun n => fun y : BitVec n => x = y) 5is not. See also
zetaHave, for disabling the reduction nondependent lets (haveexpressions). - zetaDelta : Bool
Zeta-delta reduction: given a local context containing entry
x : t := e, free variablexreduces toe. - zetaUnused : Bool
- zetaHave : Bool
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- Lean.Meta.instReprConfig_2 = { reprPrec := Lean.Meta.instReprConfig_2.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Configuration with key produced by Config.toKey.
Instances For
Equations
- c.toConfigWithKey = { config := c }
Instances For
Function parameter information cache.
- binderInfo : BinderInfo
The binder annotation for the parameter.
- hasFwdDeps : Bool
hasFwdDepsis true if there is another parameter whose type depends on this one. backDepscontains the backwards dependencies. That is, the (0-indexed) position of previous parameters that this one depends on.- isProp : Bool
isPropis true if the parameter type is always a proposition. - isDecInst : Bool
- higherOrderOutParam : Bool
higherOrderOutParamis true if this parameter is a higher-order output parameter of local instance. Example:getElem : {cont : Type u_1} → {idx : Type u_2} → {elem : Type u_3} → {dom : cont → idx → Prop} → [self : GetElem cont idx elem dom] → (xs : cont) → (i : idx) → dom xs i → elemThis flag is true for the parameter
dombecause it is output parameter of[self : GetElem cont idx elem dom] - dependsOnHigherOrderOutParam : Bool
dependsOnHigherOrderOutParamis true if the type of this parameter depends on the higher-order output parameter of a previous local instance. Example:getElem : {cont : Type u_1} → {idx : Type u_2} → {elem : Type u_3} → {dom : cont → idx → Prop} → [self : GetElem cont idx elem dom] → (xs : cont) → (i : idx) → dom xs i → elemThis flag is true for the parameter with type
dom xs isincedomis an output parameter of the instance[self : GetElem cont idx elem dom]
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Function information cache. See ParamInfo.
Parameter information cache.
resultDepscontains the function result type backwards dependencies. That is, the (0-indexed) position of parameters that the result type depends on.
Instances For
Equations
Instances For
Equations
Equations
Instances For
Equations
- localInsts : LocalInstances
- type : Expr
- synthPendingDepth : Nat
Value of
synthPendingDepthwhen instance was synthesized or failed to be synthesized. See issue #2522.
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Lean.Meta.instBEqSynthInstanceCacheKey.beq x✝¹ x✝ = false
Instances For
Equations
Instances For
Equations
Instances For
Instances For
Equations
Instances For
Equations
Instances For
Instances For
Instances For
Instances For
Equations
Instances For
Equations
Equations
Instances For
A mapping (s, t) ↦ isDefEq s t.
TODO: consider more efficient representations (e.g., a proper set) and caching policies (e.g., imperfect cache).
We should also investigate the impact on memory consumption.
Instances For
Cache datastructures for type inference, type class resolution, whnf, and definitional equality.
- inferType : InferTypeCache
- funInfo : FunInfoCache
- synthInstance : SynthInstanceCache
- whnf : WhnfCache
- defEqTrans : DefEqCache
- defEqPerm : DefEqCache
Instances For
Equations
"Context" for a postponed universe constraint.
lhs and rhs are the surrounding isDefEq call when the postponed constraint was created.
- lhs : Expr
- rhs : Expr
- lctx : LocalContext
- localInstances : LocalInstances
Instances For
Auxiliary structure for representing postponed universe constraints.
Remark: the fields ref and rootDefEq? are used for error message generation only.
Remark: we may consider improving the error message generation in the future.
- ref : Syntax
We save the
refat entry creation time. This is used for reporting errors back to the user. - lhs : Level
- rhs : Level
- ctx? : Option DefEqContext
Context for the surrounding
isDefEqcall when the entry was created.
Instances For
Equations
Instances For
Number of times each declaration has been unfolded
Number of times
f a =?= f bheuristic has been used per functionf.Number of times a TC instance is used.
- synthPendingFailures : PHashMap Expr MessageData
Pending instances that were not synthesized because
maxSynthPendingDepthhas been reached.
Instances For
Equations
Instances For
Equations
MetaM monad state.
- mctx : MetavarContext
- cache : Cache
- zetaDeltaFVarIds : FVarIdSet
When
Context.trackZetaDelta == true, then any let-decl free variable that is zetaDelta-expanded byMetaMis stored inzetaDeltaFVarIds. - postponed : PersistentArray PostponedEntry
Array of postponed universe level constraints
- diag : Diagnostics
Instances For
Equations
Contextual information for the MetaM monad.
- keyedConfig : ConfigWithKey
- trackZetaDelta : Bool
When
trackZetaDelta = true, we track all free variables that have been zetaDelta-expanded. That is, suppose the local context contains the declarationx : t := v, and we reducextov, then we insertxintoState.zetaDeltaFVarIds. We usetrackZetaDeltato discover which let-declarationslet x := v; ecan be represented ashave x := v; e. When we find these declarations we set theirnondepflag withtrue. To find these let-declarations in a given terms, we 1- ResetState.zetaDeltaFVarIds2- SettrackZetaDelta := true3- Type-checks.Note that, we do not include this field in the
Configstructure because this field is not taken into account while caching results. See also fieldzetaDeltaSet. - zetaDeltaSet : FVarIdSet
If
config.zetaDelta := false, we may select specific local declarations to be unfolded using the fieldzetaDeltaSet. Note that, we do not include this field in theConfigstructure because this field is not taken into account while caching results. Moreover, we reset all caches whenever setting it. - lctx : LocalContext
Local context
- localInstances : LocalInstances
Local instances in
lctx. - defEqCtx? : Option DefEqContext
Not
nonewhen inside of anisDefEqtest. SeePostponedEntry. - synthPendingDepth : Nat
Track the number of nested
synthPendinginvocations. Nested invocations can happen when the type class resolution invokessynthPending.Remark:
synthPendingfails ifsynthPendingDepth > maxSynthPendingDepth. - canUnfold? : Option (Config → ConstantInfo → CoreM Bool)
A predicate to control whether a constant can be unfolded or not at
whnf. Note that we do not cache results atwhnfwhencanUnfold?is notnone. - univApprox : Bool
When
Config.univApprox := true, this flag is set totruewhen there is no progress processing universe constraints. - inTypeClassResolution : Bool
inTypeClassResolution := truewhenisDefEqis invoked attryResolvein the type class resolution module. We don't useisDefEqProjDeltawhen performing TC resolution due to performance issues. This is not a great solution, but a proper solution would require a more sophisticated caching mechanism.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- c.config = c.keyedConfig.config
Instances For
Equations
- c.configKey = c.keyedConfig.key
Instances For
The MetaM monad is a core component of Lean's metaprogramming framework, facilitating the
construction and manipulation of expressions (Lean.Expr) within Lean.
It builds on top of CoreM and additionally provides:
- A
LocalContextfor managing free variables. - A
MetavarContextfor managing metavariables. - A
Cachefor caching results of the keyMetaMoperations.
The key operations provided by MetaM are:
inferType, which attempts to automatically infer the type of a given expression.whnf, which reduces an expression to the point where the outermost part is no longer reducible but the inside may still contain unreduced expression.isDefEq, which determines whether two expressions are definitionally equal, possibly assigning meta variables in the process.forallTelescopeandlambdaTelescope, which make it possible to automatically move into (nested) binders while updating the local context.
The following is a small example that demonstrates how to obtain and manipulate the type of a
Fin expression:
public import Lean
open Lean Meta
def getFinBound (e : Expr) : MetaM (Option Expr) := do
let type ← whnf (← inferType e)
let_expr Fin bound := type | return none
return bound
def a : Fin 100 := 42
run_meta
match ← getFinBound (.const ``a []) with
| some limit => IO.println (← ppExpr limit)
| none => IO.println "no limit found"
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Meta.instInhabitedMetaM = { default := fun (x : Lean.Meta.Context) (x : ST.Ref IO.RealWorld Lean.Meta.State) => default }
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.Meta.instAddMessageContextMetaM = { addMessageContext := Lean.addMessageContextFull }
Equations
- Lean.Meta.saveState = do let __do_lift ← liftM Lean.Core.saveState let __do_lift_1 ← get pure { core := __do_lift, «meta» := __do_lift_1 }
Instances For
Restore backtrackable parts of the state.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Incremental reuse primitive: if reusableResult? is none, runs act and returns its result
together with the saved monadic state after act including the heartbeats used by it. If
reusableResult? on the other hand is some (a, state), restores full state including heartbeats
used and returns (a, state).
The intention is for steps that support incremental reuse to initially pass none as
reusableResult? and store the result and state in a snapshot. In a further run, if reuse is
possible, reusableResult? should be set to the previous result and state, ensuring that the state
after running withRestoreOrSaveFull is identical in both runs. Note however that necessarily this
is only an approximation in the case of heartbeats as heartbeats used by withRestoreOrSaveFull
itself after calling act as well as by reuse-handling code such as the one supplying
reusableResult? are not accounted for.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.instMonadBacktrackSavedStateMetaM = { saveState := Lean.Meta.saveState, restoreState := fun (s : Lean.Meta.SavedState) => s.restore }
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
- Lean.Meta.mapMetaM f x = controlAt Lean.MetaM fun (runInBase : {β : Type} → m β → Lean.MetaM (stM Lean.MetaM m β)) => f (runInBase x)
Instances For
Equations
- Lean.Meta.map1MetaM f k = controlAt Lean.MetaM fun (runInBase : {β : Type} → m β → Lean.MetaM (stM Lean.MetaM m β)) => f fun (b : β) => runInBase (k b)
Instances For
Equations
- Lean.Meta.map2MetaM f k = controlAt Lean.MetaM fun (runInBase : {β : Type} → m β → Lean.MetaM (stM Lean.MetaM m β)) => f fun (b : β) (c : γ) => runInBase (k b c)
Instances For
Equations
- Lean.Meta.map3MetaM f k = controlAt Lean.MetaM fun (runInBase : {β : Type} → m β → Lean.MetaM (stM Lean.MetaM m β)) => f fun (b : β) (c : γ) (d : δ) => runInBase (k b c d)
Instances For
Equations
- Lean.Meta.resetCache = Lean.Meta.modifyCache fun (x : Lean.Meta.Cache) => { }
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
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
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
If diagnostics are enabled, record that declName has been unfolded.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If diagnostics are enabled, record that heuristic for solving f a =?= f b has been used.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If diagnostics are enabled, record that instance declName was used during TC resolution.
Equations
- One or more equations did not get rendered due to their size.
Instances For
If diagnostics are enabled, record that synth pending failures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.getLocalInstances = do let __do_lift ← read pure __do_lift.localInstances
Instances For
Equations
- Lean.Meta.getConfig = do let __do_lift ← read pure __do_lift.config
Instances For
Equations
- Lean.Meta.getConfigWithKey = do let __do_lift ← Lean.Meta.getConfig pure __do_lift.toConfigWithKey
Instances For
Return the array of postponed universe level constraints.
Equations
- Lean.Meta.getPostponed = do let __do_lift ← get pure __do_lift.postponed
Instances For
Set the array of postponed universe level constraints.
Equations
- Lean.Meta.setPostponed postponed = modify fun (s : Lean.Meta.State) => { mctx := s.mctx, cache := s.cache, zetaDeltaFVarIds := s.zetaDeltaFVarIds, postponed := postponed, diag := s.diag }
Instances For
Modify the array of postponed universe level constraints.
Equations
- Lean.Meta.modifyPostponed f = modify fun (s : Lean.Meta.State) => { mctx := s.mctx, cache := s.cache, zetaDeltaFVarIds := s.zetaDeltaFVarIds, postponed := f s.postponed, diag := s.diag }
Instances For
useEtaStruct inductName return true if we eta for structures is enabled for
for the inductive datatype inductName.
Recall we have three different settings: .none (never use it), .all (always use it), .notClasses
(enabled only for structure-like inductive types that are not classes).
The parameter inductName affects the result only if the current setting is .notClasses.
Equations
- One or more equations did not get rendered due to their size.
Instances For
WARNING: The following 4 constants are a hack for simulating forward declarations.
They are defined later using the export attribute. This is hackish because we
have to hard-code the true arity of these definitions here, and make sure the C names match.
We have used another hack based on IO.Refs in the past, it was safer but less efficient.
Reduces an expression to its weak head normal form. This is when the "head" of the top-level expression has been fully reduced. The result may contain subexpressions that have not been reduced.
See Lean.Meta.whnfImp for the implementation.
Returns the inferred type of the given expression. Assumes the expression is type-correct.
The type inference algorithm does not do general type checking.
Type inference only looks at subterms that are necessary for determining an expression's type,
and as such if inferType succeeds it does not mean the term is type-correct.
If an expression is sufficiently ill-formed that it prevents inferType from computing a type,
then it will fail with a type error.
For typechecking during elaboration, see Lean.Meta.check.
(Note that we do not guarantee that the elaborator typechecker is as correct or as efficient as
the kernel typechecker. The kernel typechecker is invoked when a definition is added to the environment.)
Here are examples of type-incorrect terms for which inferType succeeds:
public import Lean
public section
open Lean Meta
/--
`@id.{1} Bool Nat.zero`.
In general, the type of `@id α x` is `α`.
-/
def e1 : Expr := mkApp2 (.const ``id [1]) (.const ``Bool []) (.const ``Nat.zero [])
#eval inferType e1
-- Lean.Expr.const `Bool []
#eval check e1
-- error: application type mismatch
/--
`let x : Int := Nat.zero; true`.
In general, the type of `let x := v; e`, if `e` does not reference `x`, is the type of `e`.
-/
def e2 : Expr := .letE `x (.const ``Int []) (.const ``Nat.zero []) (.const ``true []) false
#eval inferType e2
-- Lean.Expr.const `Bool []
#eval check e2
-- error: invalid let declaration
Here is an example of a type-incorrect term that makes inferType fail:
/--
`Nat.zero Nat.zero`
-/
def e3 : Expr := .app (.const ``Nat.zero []) (.const ``Nat.zero [])
#eval inferType e3
-- error: function expected
See Lean.Meta.inferTypeImp for the implementation of inferType.
Equations
- Lean.Meta.withIncRecDepth x = Lean.Meta.mapMetaM (fun {α : Type} => Lean.withIncRecDepth) x
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.mkFreshLevelMVar = do let mvarId ← Lean.mkFreshLMVarId Lean.modifyMCtx fun (mctx : Lean.MetavarContext) => mctx.addLevelMVarDecl mvarId pure (Lean.mkLevelMVar mvarId)
Instances For
Equations
- Lean.Meta.mkFreshExprMVar type? kind userName = Lean.Meta.mkFreshExprMVarImpl✝ type? kind userName
Instances For
Equations
- Lean.Meta.mkFreshTypeMVar kind userName = do let u ← Lean.Meta.mkFreshLevelMVar Lean.Meta.mkFreshExprMVar (some (Lean.mkSort u)) kind userName
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Lean.Meta.mkFreshExprMVarWithId mvarId (some type) kind userName = Lean.Meta.mkFreshExprMVarWithIdCore✝ mvarId type kind userName
Instances For
Equations
- Lean.Meta.mkFreshLevelMVars num = num.foldM (fun (x : Nat) (x : x < num) (us : List Lean.Level) => do let __do_lift ← Lean.Meta.mkFreshLevelMVar pure (__do_lift :: us)) []
Instances For
Equations
Instances For
Create a constant with the given name and new universe metavariables.
Example: mkConstWithFreshMVarLevels `Monad returns @Monad.{?u, ?v}
Equations
- Lean.Meta.mkConstWithFreshMVarLevels declName = do let info ← Lean.getConstInfo declName let __do_lift ← Lean.Meta.mkFreshLevelMVarsFor info pure (Lean.mkConst declName __do_lift)
Instances For
Return current transparency setting/mode.
Equations
- Lean.Meta.getTransparency = do let __do_lift ← Lean.Meta.getConfig pure __do_lift.transparency
Instances For
Equations
- Lean.Meta.shouldReduceAll = do let __do_lift ← Lean.Meta.getTransparency pure (__do_lift == Lean.Meta.TransparencyMode.all)
Instances For
Equations
- Lean.Meta.shouldReduceReducibleOnly = do let __do_lift ← Lean.Meta.getTransparency pure (__do_lift == Lean.Meta.TransparencyMode.reducible)
Instances For
Return some mvarDecl where mvarDecl is mvarId declaration in the current metavariable context.
Return none if mvarId has no declaration in the current metavariable context.
Equations
- mvarId.findDecl? = do let __do_lift ← Lean.getMCtx pure (__do_lift.findDecl? mvarId)
Instances For
Return mvarId declaration in the current metavariable context.
Throw an exception if mvarId is not declared in the current metavariable context.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return mvarId kind. Throw an exception if mvarId is not declared in the current metavariable context.
Instances For
Return true if e is a synthetic (or synthetic opaque) metavariable
Equations
- One or more equations did not get rendered due to their size.
Instances For
Set mvarId kind in the current metavariable context.
Equations
- mvarId.setKind kind = Lean.modifyMCtx fun (mctx : Lean.MetavarContext) => mctx.setMVarKind mvarId kind
Instances For
Update the type of the given metavariable. This function assumes the new type is definitionally equal to the current one
Equations
- mvarId.setType type = Lean.modifyMCtx fun (mctx : Lean.MetavarContext) => mctx.setMVarType mvarId type
Instances For
Return true if the given metavariable is "read-only".
That is, its depth is different from the current metavariable context depth.
Equations
- mvarId.isReadOnly = do let __do_lift ← mvarId.getDecl let __do_lift_1 ← Lean.getMCtx pure (__do_lift.depth != __do_lift_1.depth)
Instances For
Returns true if mvarId.isReadOnly returns true or if mvarId is a synthetic opaque metavariable.
Recall isDefEq will not assign a value to mvarId if mvarId.isReadOnlyOrSyntheticOpaque.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the level of the given universe level metavariable.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return true if the given universe metavariable is "read-only".
That is, its depth is different from the current metavariable context depth.
Equations
- mvarId.isReadOnly = do let __do_lift ← mvarId.getLevel let __do_lift_1 ← Lean.getMCtx pure (decide (__do_lift < __do_lift_1.levelAssignDepth))
Instances For
Set the user-facing name for the given metavariable.
Equations
- mvarId.setUserName newUserName = Lean.modifyMCtx fun (mctx : Lean.MetavarContext) => mctx.setMVarUserName mvarId newUserName
Instances For
Throw an exception saying fvarId is not declared in the current local context.
Equations
- fvarId.throwUnknown = Lean.throwError (Lean.toMessageData "unknown free variable `" ++ Lean.toMessageData (Lean.mkFVar fvarId) ++ Lean.toMessageData "`")
Instances For
Return the local declaration for the given free variable. Throw an exception if local declaration is not in the current local context.
Equations
- fvarId.getDecl = do let __do_lift ← Lean.getLCtx match __do_lift.find? fvarId with | some d => pure d | none => liftM fvarId.throwUnknown
Instances For
Return the binder information for the given free variable.
Equations
- fvarId.getBinderInfo = do let __do_lift ← fvarId.getDecl pure __do_lift.binderInfo
Instances For
Returns some value if the given free let-variable has a visible local definition in the current local context
(using Lean.LocalDecl.value?), and none otherwise.
Setting allowNondep := true allows access of the normally hidden value of a nondependent let declaration.
Equations
Instances For
Return the user-facing name for the given free variable.
Equations
- fvarId.getUserName = do let __do_lift ← fvarId.getDecl pure __do_lift.userName
Instances For
Returns true if the free variable is a let-variable with a visible local definition in the current local context
(using Lean.LocalDecl.isLet).
Setting allowNondep := true includes nondependent let declarations, whose values are normally hidden.
Equations
Instances For
Get the local declaration associated to the given Expr in the current local
context. Fails if the given expression is not a fvar or if no such declaration exists.
Equations
- Lean.Meta.getFVarLocalDecl fvar = fvar.fvarId!.getDecl
Instances For
Returns true if another local declaration in the local context depends on fvarId.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a user-facing name for a free variable, return its declaration in the current local context. Throw an exception if free variable is not declared.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a user-facing name for a free variable, return the free variable or throw if not declared.
Equations
- Lean.Meta.getFVarFromUserName userName = do let d ← Lean.Meta.getLocalDeclFromUserName userName pure (Lean.Expr.fvar d.fvarId)
Instances For
Lift a MkBindingM monadic action x to MetaM.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Similar to abstractM but consider only the first min n xs.size entries in xs
It is also similar to Expr.abstractRange, but handles metavariables correctly.
It uses elimMVarDeps to ensure e and the type of the free variables xs do not
contain a metavariable ?m s.t. local context of ?m contains a free variable in xs.
Equations
- e.abstractRangeM n xs = Lean.Meta.liftMkBindingM (Lean.MetavarContext.abstractRange e n xs)
Instances For
Collect forward dependencies for the free variables in toRevert.
Recall that when reverting free variables xs, we must also revert their forward dependencies.
When generalizeNondepLet := true (the default), then the values of nondependent lets are not considered
when computing forward dependencies.
Equations
- Lean.Meta.collectForwardDeps toRevert preserveOrder generalizeNondepLet = Lean.Meta.liftMkBindingM (Lean.MetavarContext.collectForwardDeps toRevert preserveOrder generalizeNondepLet)
Instances For
Takes an array xs of free variables or metavariables and a term e that may contain those variables, and abstracts and binds them as universal quantifiers.
- if
usedOnly = truethen only variables that the expression body depends on will appear. - if
usedLetOnly = truesame asusedOnlyexcept for let-bound variables. (That is, local constants which have been assigned a value.) - if
generalizeNondepLet = truethen nondependentldecls become foralls too.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Takes an array xs of free variables and metavariables and a
body term e and creates fun ..xs => e, suitably
abstracting e and the types in xs.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.mkLetFVars xs e usedLetOnly generalizeNondepLet binderInfoForMVars = Lean.Meta.mkLambdaFVars xs e false usedLetOnly false generalizeNondepLet binderInfoForMVars
Instances For
fun _ : Unit => a
Equations
- Lean.Meta.mkFunUnit a = do let __do_lift ← liftM (Lean.mkFreshUserName `x) pure (Lean.mkLambda __do_lift Lean.BinderInfo.default (Lean.mkConst `Unit) a)
Instances For
Equations
- Lean.Meta.elimMVarDeps xs e preserveOrder = if xs.isEmpty = true then pure e else Lean.Meta.liftMkBindingM (Lean.MetavarContext.elimMVarDeps xs e preserveOrder)
Instances For
withConfig f x executes x using the updated configuration object obtained by applying f.
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
Equations
- One or more equations did not get rendered due to their size.
Instances For
If s is nonempty, then withZetaDeltaSet s x executes x with zetaDeltaSet := s.
The cache is temporarily reset while executing x.
If s is empty, then runs x without changing zetaDeltaSet or resetting the cache.
See also withTrackingZetaDeltaSet for tracking zeta-delta reductions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Gets the current zetaDeltaFVarIds set.
If Context.trackZetaDelta is true, then whnf adds to this set
those local definitions that are unfolded ("zeta-delta reduced") .
See withTrackingZetaDelta and withTrackingZetaDeltaSet.
Equations
- Lean.Meta.getZetaDeltaFVarIds = do let __do_lift ← get pure __do_lift.zetaDeltaFVarIds
Instances For
Inserts fvarId into the zetaDeltaFVarIds set.
Equations
- One or more equations did not get rendered due to their size.
Instances For
withTrackingZetaDelta x executes x while tracking zeta-delta reductions performed by whnf.
Furthermore, the zetaDeltaFVarIds set is temporarily cleared,
and also the cache is temporarily reset so that reductions are accurately tracked.
Any zeta-delta reductions recorded while executing x will not persist when leaving withTrackingZetaDelta.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.resetZetaDeltaFVarIds = modify fun (s : Lean.Meta.State) => { mctx := s.mctx, cache := s.cache, postponed := s.postponed, diag := s.diag }
Instances For
withTrackingZetaDeltaSet s x executes x in a context where zetaDeltaFVarIds has been temporarily cleared.
- If
sis nonempty, zeta-delta tracking is enabled andzetaDeltaSet := s. Furthermore, the cache is temporarily reset so that zeta-delta tracking is accurate. - If
sis empty, then zeta-delta tracking is disabled. ThezetaDeltaSetis not modified, and the cache is not cleared.
Any zeta-delta reductions recorded while executing x will not persist when leaving withTrackingZetaDeltaSet.
See also withZetaDeltaSet, which does not interact with zeta-delta tracking.
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
- Lean.Meta.withTransparency mode = Lean.Meta.mapMetaM fun {α : Type} => withReader fun (x : Lean.Meta.Context) => Lean.Meta.Context.setTransparency✝ x mode
Instances For
withDefault x executes x using the default transparency setting.
Instances For
withReducible x executes x using the reducible transparency setting. In this setting only definitions tagged as [reducible] are unfolded.
Equations
Instances For
withReducibleAndInstances x executes x using the .instances transparency setting. In this setting only definitions tagged as [reducible]
or type class instances are unfolded.
Equations
Instances For
Execute x ensuring the transparency setting is at least mode.
Recall that .all > .default > .instances > .reducible.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute x allowing isDefEq to assign synthetic opaque metavariables.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Instances For
Add entry { className := className, fvar := fvar } to localInstances,
and then execute continuation k.
Equations
- Lean.Meta.withNewLocalInstance className fvar = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withNewLocalInstanceImp✝ className fvar
Instances For
isClass? type return some ClsName if type is an instance of the class ClsName.
Example:
#eval do
let x ← mkAppM ``Inhabited #[mkConst ``Nat]
IO.println (← isClass? x)
-- (some Inhabited)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Meta.withNewLocalInstances fvars j = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withNewLocalInstancesImpAux✝ fvars j
Instances For
Given type of the form forall xs, A, execute k xs A.
This combinator will declare local declarations, create free variables for them,
execute k with updated local context, and make sure the cache is restored after executing k.
If cleanupAnnotations is true, we apply Expr.cleanupAnnotations to each type in the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a monadic function f that takes a type and a term of that type and produces a new term,
lifts this to the monadic function that opens a ∀ telescope, applies f to the body,
and then builds the lambda telescope term for the new term.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a monadic function f that takes a term and produces a new term,
lifts this to the monadic function that opens a ∀ telescope, applies f to the body,
and then builds the lambda telescope term for the new term.
Equations
- Lean.Meta.mapForallTelescope f forallTerm = Lean.Meta.mapForallTelescope' (fun (x e : Lean.Expr) => f e) forallTerm
Instances For
Similar to forallTelescope, but given type of the form forall xs, A,
it reduces A and continues building the telescope if it is a forall.
If cleanupAnnotations is true, we apply Expr.cleanupAnnotations to each type in the telescope.
If whnfType is true, we give k the whnf of the resulting type. This is a free operation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Similar to forallTelescopeReducing, stops constructing the telescope when
it reaches size maxFVars.
If cleanupAnnotations is true, we apply Expr.cleanupAnnotations to each type in the telescope.
If whnfType is true, we give k the whnf of the resulting type.
This is a free operation unless maxFVars? == some 0, in which case it computes the whnf.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Similar to lambdaTelescope but for lambda and let expressions.
- If
cleanupAnnotationsistrue, we applyExpr.cleanupAnnotationsto each type in the telescope. - If
preserveNondepisfalse, allhaves are converted tolets.
See also mapLambdaLetTelescope for entering and rebuilding the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given e of the form fun ..xs => A, execute k xs A.
This combinator will declare local declarations, create free variables for them,
execute k with updated local context, and make sure the cache is restored after executing k.
If cleanupAnnotations is true, we apply Expr.cleanupAnnotations to each type in the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given e of the form fun ..xs ..ys => A, execute k xs (fun ..ys => A) where
xs.size ≤ maxFVars.
This combinator will declare local declarations, create free variables for them,
execute k with updated local context, and make sure the cache is restored after executing k.
If cleanupAnnotations is true, we apply Expr.cleanupAnnotations to each type in the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given e of the form let x₁ := v₁; ...; let xₙ := vₙ; A, executes k xs A,
where xs is an array of free variables for the binders.
The lets can also be haves.
- If
cleanupAnnotationsistrue, appliesExpr.cleanupAnnotationsto each type in the telescope. - If
preserveNondepisfalse, allhaves are converted tolets. - If
nondepLetOnlyistrue, then onlyhaves are consumed (it stops at the first dependentlet).
See also mapLetTelescope for entering and rebuilding the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Like letTelescope, but limits the number of let/haves consumed to maxFVars?.
If maxFVars? is none, then this is the same as letTelescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluates k from within a lambdaLetTelescope, then uses mkLetFVars to rebuild the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Evaluates k from within a letTelescope, then uses mkLetFVars to rebuild the telescope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given e of the form forall ..xs, A, this combinator will create a new
metavariable for each x in xs and instantiate A with these.
Returns a product containing
- the new metavariables
- the binder info for the
xs - the instantiated
A
Equations
Instances For
Similar to forallMetaTelescope, but if e = forall ..xs, A
it will reduce A to construct further mvars.
Equations
- Lean.Meta.forallMetaTelescopeReducing e maxMVars? kind = Lean.Meta.forallMetaTelescopeReducingAux✝ e true maxMVars? kind
Instances For
Similar to forallMetaTelescopeReducing, stops
constructing the telescope when it reaches size maxMVars.
Equations
- Lean.Meta.forallMetaBoundedTelescope e maxMVars kind = Lean.Meta.forallMetaTelescopeReducingAux✝ e true (some maxMVars) kind
Instances For
Similar to forallMetaTelescopeReducingAux but for lambda expressions.
Equations
- Lean.Meta.lambdaMetaTelescope e maxMVars? = Lean.Meta.lambdaMetaTelescope.process✝ maxMVars? #[] #[] 0 e
Instances For
Create a free variable x with name, binderInfo and type, add it to the context and run in k.
Then revert the context.
Equations
- Lean.Meta.withLocalDecl name bi type k kind = Lean.Meta.map1MetaM (fun {α : Type} (k : Lean.Expr → Lean.MetaM α) => Lean.Meta.withLocalDeclImp✝ name bi type k kind) k
Instances For
Equations
- Lean.Meta.withLocalDeclD name type k = Lean.Meta.withLocalDecl name Lean.BinderInfo.default type k
Instances For
Similar to withLocalDecl, but it does not check whether the new variable is a local instance or not.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Append an array of free variables xs to the local context and execute k xs.
declInfos takes the form of an array consisting of:
- the name of the variable
- the binder info of the variable
- a type constructor for the variable, where the array consists of all of the free variables defined prior to this one. This is needed because the type of the variable may depend on prior variables.
See withLocalDeclsD and withLocalDeclsDND for simpler variants.
Equations
- Lean.Meta.withLocalDecls declInfos k = Lean.Meta.withLocalDecls.loop✝ declInfos k #[]
Instances For
Variant of withLocalDecls using BinderInfo.default
Equations
- One or more equations did not get rendered due to their size.
Instances For
Simpler variant of withLocalDeclsD for bringing variables into scope whose types do not depend
on each other.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Declare an auxiliary local declaration shortDeclName : type for elaborating recursive
declaration declName, update the mapping auxDeclToFullName, and then execute k.
Equations
- Lean.Meta.withAuxDecl shortDeclName type declName k = Lean.Meta.map1MetaM (fun {α : Type} (k : Lean.Expr → Lean.MetaM α) => Lean.Meta.withAuxDeclImp✝ shortDeclName type declName k) k
Instances For
Equations
- Lean.Meta.withNewBinderInfos bs k = Lean.Meta.mapMetaM (fun {α : Type} (k : Lean.MetaM α) => Lean.Meta.withNewBinderInfosImp✝ bs k) k
Instances For
Execute k using a local context where any x in xs that is tagged as
instance implicit is treated as a regular implicit.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Add the local declaration <name> : <type> := <val> to the local context and execute k x, where x is a new
free variable corresponding to the let-declaration. After executing k x, the local context is restored.
Equations
- Lean.Meta.withLetDecl name type val k nondep kind = Lean.Meta.map1MetaM (fun {α : Type} (k : Lean.Expr → Lean.MetaM α) => Lean.Meta.withLetDeclImp✝ name type val k nondep kind) k
Instances For
Runs k x with the local declaration <name> : <type> := <val> added to the local context, where x is the new free variable.
Afterwards, the result is wrapped in the given let/have expression (according to the value of nondep).
- If
usedLetOnly := true(the default) then the thelet/haveis not created if the variable is unused.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Register any local instance in decls
Equations
- Lean.Meta.withLocalInstances decls = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withLocalInstancesImp decls
Instances For
withExistingLocalDecls decls k, adds the given local declarations to the local context,
and then executes k. This method assumes declarations in decls have valid FVarIds.
After executing k, the local context is restored.
Remark: this method is used, for example, to implement the match-compiler.
Each match-alternative comes with a local declarations (corresponding to pattern variables),
and we use withExistingLocalDecls to add them to the local context before we process
them.
Equations
- Lean.Meta.withExistingLocalDecls decls = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withExistingLocalDeclsImp✝ decls
Instances For
Removes fvarId from the local context, and replaces occurrences of it with e.
It is the responsibility of the caller to ensure that e is well-typed in the context
of any occurrence of fvarId.
Equations
- One or more equations did not get rendered due to their size.
Instances For
withNewMCtxDepth k executes k with a higher metavariable context depth,
where metavariables created outside the withNewMCtxDepth (with a lower depth) cannot be assigned.
If allowLevelAssignments is set to true, then the level metavariable depth
is not increased, and level metavariables from the outer scope can be
assigned. (This is used by TC synthesis.)
Equations
- Lean.Meta.withNewMCtxDepth k allowLevelAssignments = Lean.Meta.mapMetaM (fun {α : Type} => Lean.Meta.withNewMCtxDepthImp✝ allowLevelAssignments) k
Instances For
withLCtx lctx localInsts k replaces the local context and local instances, and then executes k.
The local context and instances are restored after executing k.
This method assumes that the local instances in localInsts are in the local context lctx.
Equations
- Lean.Meta.withLCtx lctx localInsts = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withLocalContextImp✝ lctx localInsts
Instances For
Simpler version of withLCtx which just updates the local context. It is the responsibility of the
caller ensure the local instances are also properly updated.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Runs k in a local environment with the fvarIds erased.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Ensures that the user names of all local declarations after index idx have a macro scope.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Executes x using the given metavariable LocalContext and LocalInstances.
The type class resolution cache is flushed when executing x if its LocalInstances are
different from the current ones.
Equations
- mvarId.withContext = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withMVarContextImp✝ mvarId
Instances For
withMCtx mctx k replaces the metavariable context and then executes k.
The metavariable context is restored after executing k.
This method is used to implement the type class resolution procedure.
Equations
- Lean.Meta.withMCtx mctx = Lean.Meta.mapMetaM fun {α : Type} => Lean.Meta.withMCtxImp✝ mctx
Instances For
withoutModifyingMCtx k executes k and then restores the metavariable context.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute x using approximate unification: foApprox, ctxApprox and quasiPatternApprox.
Equations
Instances For
Similar to approxDefEq, but uses all available approximations.
We don't use constApprox by default at approxDefEq because it often produces undesirable solution for monadic code.
For example, suppose we have pure (x > 0) which has type ?m Prop. We also have the goal [Pure ?m].
Now, assume the expected type is IO Bool. Then, the unification constraint ?m Prop =?= IO Bool could be solved
as ?m := fun _ => IO Bool using constApprox, but this spurious solution would generate a failure when we try to
solve [Pure (fun _ => IO Bool)]
Equations
Instances For
Instantiate assigned universe metavariables in u, and then normalize it.
Equations
- Lean.Meta.normalizeLevel u = do let u ← Lean.instantiateLevelMVars u pure u.normalize
Instances For
Mark declaration declName with the attribute [inline].
This method does not check whether the given declaration is a definition.
Recall that this attribute can only be set in the same module where declName has been declared.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given e of the form forall (a_1 : A_1) ... (a_n : A_n), B[a_1, ..., a_n] and p_1 : A_1, ... p_n : A_n, return B[p_1, ..., p_n].
Equations
Instances For
Given e of the form fun (a_1 : A_1) ... (a_n : A_n) => t[a_1, ..., a_n] and p_1 : A_1, ... p_n : A_n, return t[p_1, ..., p_n].
It uses whnf to reduce e if it is not a lambda
Equations
Instances For
A simpler version of ParamInfo for information about the parameter of a forall or lambda.
- name : Name
The name of the parameter.
- type : Expr
The type of the parameter.
- binderInfo : BinderInfo
The binder annotation for the parameter.
Instances For
Equations
Instances For
Given e of the form ∀ (p₁ : P₁) … (p₁ : P₁), B[p_1,…,p_n] and arg₁ : P₁, …, argₙ : Pₙ, returns
- the names
p₁, …, pₙ, - the binder infos,
- the binder types
P₁, P₂[arg₁], …, P[arg₁,…,argₙ₋₁], and - the type
B[arg₁,…,argₙ].
It uses whnf to reduce e if it is not a forall.
See also Lean.Meta.instantiateForall.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given e of the form fun (p₁ : P₁) … (p₁ : P₁) => t[p_1,…,p_n] and arg₁ : P₁, …, argₙ : Pₙ, returns
- the names
p₁, …, pₙ, - the binder infos,
- the binder types
P₁, P₂[arg₁], …, P[arg₁,…,argₙ₋₁], and - the term
t[arg₁,…,argₙ].
It uses whnf to reduce e if it is not a lambda.
See also Lean.Meta.instantiateLambda.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pretty-print the given expression.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Pretty-print the given expression.
Equations
- Lean.Meta.ppExpr e = (fun (x : Lean.FormatWithInfos) => x.fmt) <$> Lean.Meta.ppExprWithInfos e
Instances For
Equations
- Lean.Meta.orElse x y = do let s ← Lean.saveState tryCatch x fun (x : Lean.Exception) => do s.restore y ()
Instances For
Equations
- Lean.Meta.instOrElseMetaM = { orElse := Lean.Meta.orElse }
Equations
- One or more equations did not get rendered due to their size.
Similar to orelse, but merge errors. Note that internal errors are not caught.
The default mergeRef uses the ref (position information) for the first message.
The default mergeMsg combines error messages using Format.line ++ Format.line as a separator.
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, and apply f to the produced error message
Equations
- Lean.Meta.mapError x f = controlAt Lean.MetaM fun (runInBase : {β : Type} → m β → Lean.MetaM (stM Lean.MetaM m β)) => Lean.Meta.mapErrorImp (runInBase x) f
Instances For
Execute x. If it throws an error, indent and prepend msg to it.
Equations
- Lean.Meta.prependError msg x = Lean.Meta.mapError x fun (e : Lean.MessageData) => Lean.toMessageData msg ++ Lean.toMessageData (Lean.indentD e)
Instances For
Return true if indVal is an inductive predicate. That is, inductive type in Prop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return some info if declName is an inductive predicate where info : InductiveVal.
That is, inductive type in Prop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return true if declName is an inductive predicate. That is, inductive type in Prop.
Equations
- Lean.Meta.isInductivePredicate declName = do let __do_lift ← Lean.Meta.isInductivePredicate? declName pure __do_lift.isSome
Instances For
Equations
- Lean.Meta.isListLevelDefEqAux [] [] = pure true
- Lean.Meta.isListLevelDefEqAux (u :: us) (v :: vs) = (Lean.Meta.isLevelDefEqAux u v <&&> Lean.Meta.isListLevelDefEqAux us vs)
- Lean.Meta.isListLevelDefEqAux x✝¹ x✝ = pure false
Instances For
Equations
- Lean.Meta.getNumPostponed = do let __do_lift ← Lean.Meta.getPostponed pure __do_lift.size
Instances For
Equations
- Lean.Meta.getResetPostponed = do let ps ← Lean.Meta.getPostponed Lean.Meta.setPostponed { } pure ps
Instances For
Equations
- Lean.Meta.mkLevelStuckErrorMessage entry = Lean.Meta.mkLevelErrorMessageCore✝ "stuck at solving universe constraint" entry
Instances For
Equations
- Lean.Meta.mkLevelErrorMessage entry = Lean.Meta.mkLevelErrorMessageCore✝ "failed to solve universe constraint" entry
Instances For
checkpointDefEq x executes x and process all postponed universe level constraints produced by x.
We keep the modifications only if processPostponed return true and x returned true.
If mayPostpone == false, all new postponed universe level constraints must be solved before returning.
We currently try to postpone universe constraints as much as possible, even when by postponing them we
are not sure whether x really succeeded or not.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Determines whether two universe level expressions are definitionally equal to each other.
Equations
Instances For
Determines whether two expressions are definitionally equal to each other.
To control how metavariables are assigned and unified, metavariables and their context have a "depth".
Given a metavariable ?m and a MetavarContext mctx, ?m is not assigned if ?m.depth != mctx.depth.
The combinator withNewMCtxDepth x will bump the depth while executing x.
So, withNewMCtxDepth (isDefEq a b) is isDefEq without any mvar assignment happening
whereas isDefEq a b will assign any metavariables of the current depth in a and b to unify them.
For matching (where only mvars in b should be assigned), we create the term inside the withNewMCtxDepth.
For an example, see Lean.Meta.Simp.tryTheoremWithExtraArgs?
Equations
- Lean.Meta.isDefEq t s = Lean.Meta.isExprDefEq t s
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Similar to isDefEq, but returns false if an exception has been thrown.
Equations
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Realizes and caches a value for a given key with all environment objects derived from calling
enableRealizationsForConst forConst (fails if not called yet). If
this is the first environment branch passing the specific key, realize is called with the
environment and options at the time of calling enableRealizationsForConst if forConst is from
the current module and the state just after importing otherwise, thus helping achieve deterministic
results despite the non-deterministic choice of which thread is tasked with realization. In other
words, the result of realizeValue is as if realize had been called immediately after
enableRealizationsForConst forConst, with most effects but the return value discarded (see below).
Whether two calls of realizeValue with different forConsts but the same key share the result
is undefined; in practice, the key should usually uniquely determine forConst by e.g. including it
as a field.
realizeValue cannot check what other data is captured in the realize closure,
so it is best practice to extract it into a separate function and pass only arguments uniquely
determined by key. Traces, diagnostics, and raw std stream
output of realize are reported at all callers via Core.logSnapshotTask (so that the location of
generated diagnostics is deterministic). Note that, as realize is run using the options at
declaration time of forConst, trace options must be set prior to that (or, for imported constants,
on the cmdline) in order to be active. If realize throws an exception, it is rethrown at all
callers.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Makes the helper constant constName that is derived from forConst available in the environment.
enableRealizationsForConst forConst must have been called first on this environment branch. If
this is the first environment branch requesting constName to be realized (atomically), realize
is called with the environment and options at the time of calling enableRealizationsForConst if
forConst is from the current module and the state just after importing otherwise, thus helping
achieve deterministic results despite the non-deterministic choice of which thread is tasked with
realization. In other words, the state after calling realizeConst is as if realize had been
called immediately after enableRealizationsForConst forConst, though the effects of this call are
visible only after calling realizeConst. See below for more details on the replayed effects.
realizeConst cannot check what other data is captured in the realize closure,
so it is best practice to extract it into a separate function and pay close attention to the passed
arguments, if any. realize must return with constName added to the environment,
at which point all callers of realizeConst with this constName will be unblocked
and have access to an updated version of their own environment containing any new constants
realize added, including recursively realized constants. Traces, diagnostics, and raw std stream
output are reported at all callers via Core.logSnapshotTask (so that the location of generated
diagnostics is deterministic). Note that, as realize is run using the options at declaration time
of forConst, trace options must be set prior to that (or, for imported constants, on the cmdline)
in order to be active. The environment extension state at the end of realize is available to each
caller via EnvExtension.getState (asyncDecl := constName). If realize throws an exception or
fails to add constName to the environment, an appropriate diagnostic is reported to all callers
but no constants are added to the environment.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Turns a MetaM MessageData into a MessageData.lazy which will run the monadic value.
The optional array of expressions is used to set the hasSyntheticSorry fields, and should
comprise the expressions that are included in the message data.
Equations
- One or more equations did not get rendered due to their size.