Documentation

Lean.Meta.Basic

structure Lean.Meta.Config:
Type
  • foApprox : Bool
  • ctxApprox : Bool
  • quasiPatternApprox : Bool
  • When constApprox is set to true, we solve ?m t =?= c using ?m := fun _ => c when ?m t is not a higher-order pattern and c is not an application as

    constApprox : Bool
  • When the following flag is set, isDefEq throws the exeption Exeption.isDefEqStuck whenever it encounters a constraint ?m ... =?= t where ?m is read only. This feature is useful for type class resolution where we may want to notify the caller that the TC problem may be solveable later after it assigns ?m.

    isDefEqStuckEx : Bool
  • If zetaNonDep == false, then non dependent let-decls are not zeta expanded.

    zetaNonDep : Bool
  • When trackZeta == true, we store zetaFVarIds all free variables that have been zeta-expanded.

    trackZeta : Bool
  • unificationHints : Bool
  • Enables proof irrelevance at isDefEq

    proofIrrelevance : 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 as exact t. When elaborating t, 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 of t with 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.

    assignSyntheticOpaque : Bool
  • When ignoreLevelDepth is false, only universe level metavariables with depth == metavariable context depth can be assigned. We used to have ignoreLevelDepth == false always, but this setting produced counterintuitive behavior in a few cases. Recall that universe levels are often ignored by users, they may not even be aware they exist. We still use this restriction for regular metavariables. See discussion at the beginning of MetavarContext.lean. We claim it is reasonable to ignore this restriction for universe metavariables because their values are often contrained by the terms is instances and simp theorems. TODO: we should delete this configuration option and the method isReadOnlyLevelMVar after we have more tests.

    ignoreLevelMVarDepth : Bool
  • Enable/Disable support for offset constraints such as ?x + 1 =?= e

    offsetCnstrs : Bool
  • Eta for structures configuration mode.

structure Lean.Meta.ParamInfo:
Type
Equations
structure Lean.Meta.FunInfo:
Type
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
structure Lean.Meta.DefEqContext:
Type

"Context" for a postponed universe constraint. lhs and rhs are the surrounding isDefEq call when the postponed constraint was created.

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.

Equations
Equations
Equations
structure Lean.Meta.Context:
Type
Equations
  • Lean.Meta.instInhabitedMetaM = { default := fun x x => default }
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations

Restore backtrackable parts of the state.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.MetaM.run {α : Type} (x : Lean.MetaM α) (ctx : optParam Lean.Meta.Context { config := { foApprox := false, ctxApprox := false, quasiPatternApprox := false, constApprox := false, isDefEqStuckEx := false, transparency := Lean.Meta.TransparencyMode.default, zetaNonDep := true, trackZeta := false, unificationHints := true, proofIrrelevance := true, assignSyntheticOpaque := false, ignoreLevelMVarDepth := true, offsetCnstrs := true, etaStruct := Lean.Meta.EtaStructMode.all }, lctx := { fvarIdToDecl := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, decls := { root := Std.PersistentArrayNode.node (Array.mkEmpty (USize.toNat Std.PersistentArray.branching)), tail := Array.mkEmpty (USize.toNat Std.PersistentArray.branching), size := 0, shift := Std.PersistentArray.initShift, tailOff := 0 } }, localInstances := #[], defEqCtx? := none, synthPendingDepth := 0, canUnfold? := none }) (s : optParam Lean.Meta.State { mctx := { depth := 0, mvarCounter := 0, lDepth := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, decls := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, userNames := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, lAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, eAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, dAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, cache := { inferType := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, funInfo := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, synthInstance := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, whnfDefault := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, whnfAll := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, defEqDefault := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, defEqAll := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, zetaFVarIds := , postponed := { root := Std.PersistentArrayNode.node (Array.mkEmpty (USize.toNat Std.PersistentArray.branching)), tail := Array.mkEmpty (USize.toNat Std.PersistentArray.branching), size := 0, shift := Std.PersistentArray.initShift, tailOff := 0 } }) :
Equations
@[inline]
def Lean.Meta.MetaM.run' {α : Type} (x : Lean.MetaM α) (ctx : optParam Lean.Meta.Context { config := { foApprox := false, ctxApprox := false, quasiPatternApprox := false, constApprox := false, isDefEqStuckEx := false, transparency := Lean.Meta.TransparencyMode.default, zetaNonDep := true, trackZeta := false, unificationHints := true, proofIrrelevance := true, assignSyntheticOpaque := false, ignoreLevelMVarDepth := true, offsetCnstrs := true, etaStruct := Lean.Meta.EtaStructMode.all }, lctx := { fvarIdToDecl := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, decls := { root := Std.PersistentArrayNode.node (Array.mkEmpty (USize.toNat Std.PersistentArray.branching)), tail := Array.mkEmpty (USize.toNat Std.PersistentArray.branching), size := 0, shift := Std.PersistentArray.initShift, tailOff := 0 } }, localInstances := #[], defEqCtx? := none, synthPendingDepth := 0, canUnfold? := none }) (s : optParam Lean.Meta.State { mctx := { depth := 0, mvarCounter := 0, lDepth := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, decls := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, userNames := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, lAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, eAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, dAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, cache := { inferType := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, funInfo := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, synthInstance := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, whnfDefault := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, whnfAll := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, defEqDefault := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, defEqAll := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, zetaFVarIds := , postponed := { root := Std.PersistentArrayNode.node (Array.mkEmpty (USize.toNat Std.PersistentArray.branching)), tail := Array.mkEmpty (USize.toNat Std.PersistentArray.branching), size := 0, shift := Std.PersistentArray.initShift, tailOff := 0 } }) :
Equations
@[inline]
def Lean.Meta.MetaM.toIO {α : Type} (x : Lean.MetaM α) (ctxCore : Lean.Core.Context) (sCore : Lean.Core.State) (ctx : optParam Lean.Meta.Context { config := { foApprox := false, ctxApprox := false, quasiPatternApprox := false, constApprox := false, isDefEqStuckEx := false, transparency := Lean.Meta.TransparencyMode.default, zetaNonDep := true, trackZeta := false, unificationHints := true, proofIrrelevance := true, assignSyntheticOpaque := false, ignoreLevelMVarDepth := true, offsetCnstrs := true, etaStruct := Lean.Meta.EtaStructMode.all }, lctx := { fvarIdToDecl := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, decls := { root := Std.PersistentArrayNode.node (Array.mkEmpty (USize.toNat Std.PersistentArray.branching)), tail := Array.mkEmpty (USize.toNat Std.PersistentArray.branching), size := 0, shift := Std.PersistentArray.initShift, tailOff := 0 } }, localInstances := #[], defEqCtx? := none, synthPendingDepth := 0, canUnfold? := none }) (s : optParam Lean.Meta.State { mctx := { depth := 0, mvarCounter := 0, lDepth := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, decls := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, userNames := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, lAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, eAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, dAssignment := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, cache := { inferType := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, funInfo := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, synthInstance := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, whnfDefault := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, whnfAll := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, defEqDefault := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 }, defEqAll := { root := Std.PersistentHashMap.Node.entries Std.PersistentHashMap.mkEmptyEntriesArray, size := 0 } }, zetaFVarIds := , postponed := { root := Std.PersistentArrayNode.node (Array.mkEmpty (USize.toNat Std.PersistentArray.branching)), tail := Array.mkEmpty (USize.toNat Std.PersistentArray.branching), size := 0, shift := Std.PersistentArray.initShift, tailOff := 0 } }) :
Equations
instance Lean.Meta.instMetaEvalMetaM {α : Type} [inst : Lean.MetaEval α] :
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.liftMetaM {m : TypeType u_1} {α : Type} [inst : MonadLiftT Lean.MetaM m] (x : Lean.MetaM α) :
m α
Equations
@[inline]
def Lean.Meta.mapMetaM {m : TypeType u_1} [inst : MonadControlT Lean.MetaM m] [inst : Monad m] (f : {α : Type} → Lean.MetaM αLean.MetaM α) {α : Type} (x : m α) :
m α
Equations
@[inline]
def Lean.Meta.map1MetaM {m : TypeType u_1} {β : Sort u_2} [inst : MonadControlT Lean.MetaM m] [inst : Monad m] (f : {α : Type} → (βLean.MetaM α) → Lean.MetaM α) {α : Type} (k : βm α) :
m α
Equations
@[inline]
def Lean.Meta.map2MetaM {m : TypeType u_1} {β : Sort u_2} {γ : Sort u_3} [inst : MonadControlT Lean.MetaM m] [inst : Monad m] (f : {α : Type} → (βγLean.MetaM α) → Lean.MetaM α) {α : Type} (k : βγm α) :
m α
Equations
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • Lean.Meta.setMCtx mctx = modify fun s => { mctx := mctx, cache := s.cache, zetaFVarIds := s.zetaFVarIds, postponed := s.postponed }
Equations
Equations
@[inline]
Equations
Equations
  • One or more equations did not get rendered due to their size.
@[extern 6 lean_whnf]

Reduces an expression to its Weak Head Normal Form. This is when the topmost expression has been fully reduced, but may contain subexpressions which have not been reduced.

@[extern 6 lean_infer_type]

Returns the inferred type of the given expression, or fails if it is not type-correct.

@[extern 7 lean_is_expr_def_eq]
@[extern 7 lean_is_level_def_eq]
@[extern 6 lean_synth_pending]
def Lean.Meta.withIncRecDepth {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (x : n α) :
n α
Equations
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations

Return true if e contains mvarId directly or indirectly

Equations
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
Equations
  • One or more equations did not get rendered due to their size.

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 = true then only variables that the expression body depends on will appear.
  • if usedLetOnly = true same as usedOnly except for let-bound variables. (That is, local constants which have been assigned a value.)
Equations
  • One or more equations did not get rendered due to their size.

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.
Equations

Creates the expression d → b

Equations
@[inline]
def Lean.Meta.withConfig {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (f : Lean.Meta.ConfigLean.Meta.Config) :
n αn α
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.withTrackingZeta {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (x : n α) :
n α
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.withoutProofIrrelevance {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (x : n α) :
n α
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.withTransparency {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (mode : Lean.Meta.TransparencyMode) :
n αn α
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.withDefault {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (x : n α) :
n α
Equations
@[inline]
def Lean.Meta.withReducible {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (x : n α) :
n α
Equations
@[inline]
def Lean.Meta.withAtLeastTransparency {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (mode : Lean.Meta.TransparencyMode) (x : n α) :
n α
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.withAssignableSyntheticOpaque {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (x : n α) :
n α

Execute x allowing isDefEq to assign synthetic opaque metavariables.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.savingCache {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} :
n αn α
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.resettingSynthInstanceCache {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} :
n αn α

Reset synthInstance cache, execute x, and restore cache

Equations
  • Lean.Meta.resettingSynthInstanceCache = Lean.Meta.mapMetaM fun {α} => Lean.Meta.resettingSynthInstanceCacheImpl
@[inline]
def Lean.Meta.resettingSynthInstanceCacheWhen {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (b : Bool) (x : n α) :
n α
Equations
def Lean.Meta.withNewLocalInstance {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (className : Lean.Name) (fvar : Lean.Expr) :
n αn α

Add entry { className := className, fvar := fvar } to localInstances, and then execute continuation k. It resets the type class cache using resettingSynthInstanceCache.

Equations
def Lean.Meta.withNewLocalInstances {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (fvars : Array Lean.Expr) (j : Nat) :
n αn α
Equations
def Lean.Meta.forallTelescope {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (type : Lean.Expr) (k : Array Lean.ExprLean.Exprn α) :
n α

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.

Equations
def Lean.Meta.forallTelescopeReducing {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (type : Lean.Expr) (k : Array Lean.ExprLean.Exprn α) :
n α

Similar to forallTelescope, but given type of the form forall xs, A, it reduces A and continues bulding the telescope if it is a forall.

Equations
def Lean.Meta.forallBoundedTelescope {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (type : Lean.Expr) (maxFVars? : Option Nat) (k : Array Lean.ExprLean.Exprn α) :
n α

Similar to forallTelescopeReducing, stops constructing the telescope when it reaches size maxFVars.

Equations
def Lean.Meta.lambdaLetTelescope {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (e : Lean.Expr) (k : Array Lean.ExprLean.Exprn α) :
n α

Similar to lambdaTelescope but for lambda and let expressions.

Equations
def Lean.Meta.lambdaTelescope {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (e : Lean.Expr) (k : Array Lean.ExprLean.Exprn α) :
n α

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.

Equations

Return the parameter names for the given global declaration.

Equations
  • One or more equations did not get rendered due to their size.

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

Similar to forallMetaTelescope, but if e = forall ..xs, A it will reduce A to construct further mvars.

Equations

Similar to forallMetaTelescopeReducingAux but for lambda expressions.

Equations
def Lean.Meta.withLocalDecl {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (name : Lean.Name) (bi : Lean.BinderInfo) (type : Lean.Expr) (k : Lean.Exprn α) :
n α

Create a free variable x with name, binderInfo and type, add it to the context and run in k. Then revert the context.

Equations
def Lean.Meta.withLocalDeclD {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (name : Lean.Name) (type : Lean.Expr) (k : Lean.Exprn α) :
n α
Equations
def Lean.Meta.withLocalDecls {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} [inst : Inhabited α] (declInfos : Array (Lean.Name × Lean.BinderInfo × (Array Lean.Exprn Lean.Expr))) (k : Array Lean.Exprn α) :
n α

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.
Equations
partial def Lean.Meta.withLocalDecls.loop {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (declInfos : Array (Lean.Name × Lean.BinderInfo × (Array Lean.Exprn Lean.Expr))) (k : Array Lean.Exprn α) [inst : Inhabited α] (acc : Array Lean.Expr) :
n α
def Lean.Meta.withLocalDeclsD {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} [inst : Inhabited α] (declInfos : Array (Lean.Name × (Array Lean.Exprn Lean.Expr))) (k : Array Lean.Exprn α) :
n α
Equations
  • One or more equations did not get rendered due to their size.
def Lean.Meta.withNewBinderInfos {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (bs : Array (Lean.FVarId × Lean.BinderInfo)) (k : n α) :
n α
Equations
def Lean.Meta.withLetDecl {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (name : Lean.Name) (type : Lean.Expr) (val : Lean.Expr) (k : Lean.Exprn α) :
n α
Equations
Equations
  • One or more equations did not get rendered due to their size.
def Lean.Meta.withLocalInstances {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (decls : List Lean.LocalDecl) :
n αn α

Register any local instance in decls

Equations
def Lean.Meta.withExistingLocalDecls {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (decls : List Lean.LocalDecl) :
n αn α
Equations
def Lean.Meta.withNewMCtxDepth {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} :
n αn α

Save cache and MetavarContext, bump the MetavarContext depth, execute x, and restore saved data.

Metavariable context depths are used to control which metavariables may be assigned in isDefEq. See the docstring of isDefEq for more information.

Equations
def Lean.Meta.withLCtx {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (lctx : Lean.LocalContext) (localInsts : Lean.LocalInstances) :
n αn α
Equations
def Lean.Meta.withMVarContext {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (mvarId : Lean.MVarId) :
n αn α

Execute 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
def Lean.Meta.withMCtx {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} (mctx : Lean.MetavarContext) :
n αn α
Equations
@[inline]
def Lean.Meta.approxDefEq {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} :
n αn α

Execute x using approximate unification: foApprox, ctxApprox and quasiPatternApprox.

Equations
@[inline]
def Lean.Meta.fullApproxDefEq {n : TypeType u_1} [inst : MonadControlT Lean.MetaM n] [inst : Monad n] {α : Type} :
n αn α

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
Equations
  • One or more equations did not get rendered due to their size.

Return true iff e depends on the free variable fvarId

Equations

Return true iff e depends on the free variable fvarId

Equations

Return true iff e depends on a free variable x s.t. pf x, or an unassigned metavariable ?m s.t. pm ?m is true.

Equations

Return true iff the local declaration localDecl depends on a free variable x s.t. pf x, an unassigned metavariable ?m s.t. pm ?m is true.

Equations
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lean.Meta.orElse {α : Type} (x : Lean.MetaM α) (y : UnitLean.MetaM α) :
Equations
instance Lean.Meta.instOrElseMetaM {α : Type} :
Equations
  • Lean.Meta.instOrElseMetaM = { orElse := Lean.Meta.orElse }
@[inline]
def Lean.Meta.orelseMergeErrors {m : TypeType u_1} {α : Type} [inst : MonadControlT Lean.MetaM m] [inst : Monad m] (x : m α) (y : m α) (mergeRef : optParam (Lean.SyntaxLean.SyntaxLean.Syntax) fun r₁ x => r₁) (mergeMsg : optParam (Lean.MessageDataLean.MessageDataLean.MessageData) fun m₁ m₂ => m₁ ++ Lean.MessageData.ofFormat Lean.Format.line ++ Lean.MessageData.ofFormat Lean.Format.line ++ m₂) :
m α

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

Execute x, and apply f to the produced error message

Equations
@[inline]
def Lean.Meta.mapError {m : TypeType u_1} {α : Type} [inst : MonadControlT Lean.MetaM m] [inst : Monad m] (x : m α) (f : Lean.MessageDataLean.MessageData) :
m α
Equations

Sort free variables using an order x < y iff x was defined before y. If a free variable is not in the local context, we use their id.

Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
Equations
  • One or more equations did not get rendered due to their size.
def Lean.Meta.processPostponed (mayPostpone : optParam Bool true) (exceptionOnFailure : optParam Bool false) :
Equations
  • One or more equations did not get rendered due to their size.
partial def Lean.Meta.processPostponed.loop (mayPostpone : optParam Bool true) (exceptionOnFailure : optParam Bool false) :
@[specialize]

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.
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.
@[inline]

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
Equations
  • One or more equations did not get rendered due to their size.

Eta expand the given expression. Example:

etaExpand (mkConst `Nat.add)

produces fun x y => Nat.add x y

Equations
  • One or more equations did not get rendered due to their size.