Equations
- Lean.instInhabitedLocalInstance = { default := { className := default, fvar := default } }
Equations
Equations
- Lean.instBEqLocalInstance = { beq := fun i₁ i₂ => i₁.fvar == i₂.fvar }
Remove local instance with the given fvarId
. Do nothing if localInsts
does not contain any free variable with id fvarId
.
Equations
- One or more equations did not get rendered due to their size.
- natural: Lean.MetavarKind
- synthetic: Lean.MetavarKind
- syntheticOpaque: Lean.MetavarKind
Equations
- Lean.instInhabitedMetavarKind = { default := Lean.MetavarKind.natural }
Equations
- Lean.instReprMetavarKind = { reprPrec := [anonymous] }
Equations
- Lean.MetavarKind.isSyntheticOpaque _fun_discr = match _fun_discr with | Lean.MetavarKind.syntheticOpaque => true | x => false
Equations
- Lean.MetavarKind.isNatural _fun_discr = match _fun_discr with | Lean.MetavarKind.natural => true | x => false
- userName : Lean.Name
- lctx : Lean.LocalContext
- type : Lean.Expr
- depth : Nat
- localInstances : Lean.LocalInstances
- kind : Lean.MetavarKind
- numScopeArgs : Nat
- index : Nat
Equations
- One or more equations did not get rendered due to their size.
- lctx : Lean.LocalContext
- val : Lean.Expr
A delayed assignment for a metavariable ?m
. It represents an assignment of the form
?m := (fun fvars => val)
. The local context lctx
provides the declarations for fvars
.
Note that fvars
may not be defined in the local context for ?m
.
- TODO: after we delete the old frontend, we can remove the field
lctx
. This field is only used in old C++ implementation.
- depth : Nat
- mvarCounter : Nat
- lDepth : Std.PersistentHashMap Lean.MVarId Nat
- userNames : Std.PersistentHashMap Lean.Name Lean.MVarId
- lAssignment : Std.PersistentHashMap Lean.MVarId Lean.Level
- eAssignment : Std.PersistentHashMap Lean.MVarId Lean.Expr
- dAssignment : Std.PersistentHashMap Lean.MVarId Lean.DelayedMetavarAssignment
- getMCtx : m Lean.MetavarContext
- modifyMCtx : (Lean.MetavarContext → Lean.MetavarContext) → m Unit
Equations
- Lean.instMonadMCtx m n = { getMCtx := liftM Lean.getMCtx, modifyMCtx := fun f => liftM (Lean.modifyMCtx f) }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.addExprMVarDeclExp mctx mvarId userName lctx localInstances type kind = Lean.MetavarContext.addExprMVarDecl mctx mvarId userName lctx localInstances type kind
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.findDecl? mctx mvarId = Std.PersistentHashMap.find? mctx.decls mvarId
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.findUserName? mctx userName = Std.PersistentHashMap.find? mctx.userNames userName
Equations
- One or more equations did not get rendered due to their size.
Set the metavariable user facing name.
Equations
- One or more equations did not get rendered due to their size.
Low-level version of setMVarUserName
.
It does not update the table userNames
. Thus, findUserName?
cannot see the modification.
It is meant for mkForallFVars'
where we temporarily set the user facing name of metavariables to get more
meaningful binder names.
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.MetavarContext.findLevelDepth? mctx mvarId = Std.PersistentHashMap.find? mctx.lDepth mvarId
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.isAnonymousMVar mctx mvarId = match Lean.MetavarContext.findDecl? mctx mvarId with | none => false | some mvarDecl => Lean.Name.isAnonymous mvarDecl.userName
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.getLevelAssignment? m mvarId = Std.PersistentHashMap.find? m.lAssignment mvarId
Equations
- Lean.MetavarContext.getExprAssignment? m mvarId = Std.PersistentHashMap.find? m.eAssignment mvarId
Equations
- Lean.MetavarContext.getDelayedAssignment? m mvarId = Std.PersistentHashMap.find? m.dAssignment mvarId
Equations
- Lean.MetavarContext.isLevelAssigned m mvarId = Std.PersistentHashMap.contains m.lAssignment mvarId
Equations
- Lean.MetavarContext.isExprAssigned m mvarId = Std.PersistentHashMap.contains m.eAssignment mvarId
Equations
- Lean.MetavarContext.isDelayedAssigned m mvarId = Std.PersistentHashMap.contains m.dAssignment mvarId
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.isExprAssignable mctx mvarId = let decl := Lean.MetavarContext.getDecl mctx mvarId; decl.depth == mctx.depth
Equations
- One or more equations did not get rendered due to their size.
Return true iff the given level contains an assigned metavariable.
Return true
iff expression contains assigned (level/expr) metavariables or delayed assigned mvars
Equations
- One or more equations did not get rendered due to their size.
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.const a lvls a_1) = List.any lvls (Lean.MetavarContext.hasAssignedLevelMVar mctx)
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.sort lvl a) = Lean.MetavarContext.hasAssignedLevelMVar mctx lvl
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.fvar a a_1) = false
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.bvar a a_1) = false
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.lit a a_1) = false
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.mdata a e a_1) = (Lean.Expr.hasMVar e && Lean.MetavarContext.hasAssignedMVar mctx e)
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.proj a a_1 e a_2) = (Lean.Expr.hasMVar e && Lean.MetavarContext.hasAssignedMVar mctx e)
- Lean.MetavarContext.hasAssignedMVar mctx (Lean.Expr.mvar mvarId a) = (Lean.MetavarContext.isExprAssigned mctx mvarId || Lean.MetavarContext.isDelayedAssigned mctx mvarId)
Return true iff the given level contains a metavariable that can be assigned.
Return true
iff expression contains a metavariable that can be assigned.
Equations
- One or more equations did not get rendered due to their size.
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.const a lvls a_1) = List.any lvls (Lean.MetavarContext.hasAssignableLevelMVar mctx)
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.sort lvl a) = Lean.MetavarContext.hasAssignableLevelMVar mctx lvl
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.fvar a a_1) = false
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.bvar a a_1) = false
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.lit a a_1) = false
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.mdata a e a_1) = (Lean.Expr.hasMVar e && Lean.MetavarContext.hasAssignableMVar mctx e)
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.proj a a_1 e a_2) = (Lean.Expr.hasMVar e && Lean.MetavarContext.hasAssignableMVar mctx e)
- Lean.MetavarContext.hasAssignableMVar mctx (Lean.Expr.mvar mvarId a) = Lean.MetavarContext.isExprAssignable mctx mvarId
instantiateExprMVars main function
Equations
- Lean.MetavarContext.instMonadMCtxStateRefT'MetavarContextST = { getMCtx := get, modifyMCtx := modify }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.DependsOn.main mctx pf pm e = if (!Lean.Expr.hasFVar e && !Lean.Expr.hasMVar e) = true then pure false else Lean.MetavarContext.DependsOn.dep mctx pf pm e
Return true
iff e
depends on a free variable x
s.t. pf x
is true
, or an unassigned metavariable ?m
s.t. pm ?m
is true.
For each metavariable ?m
(that does not satisfy pm
occurring in x
1- If ?m := t
, then we visit t
looking for x
2- If ?m
is unassigned, then we consider the worst case and check whether x
is in the local context of ?m
.
This case is a "may dependency". That is, we may assign a term t
to ?m
s.t. t
contains x
.
Equations
- Lean.MetavarContext.findExprDependsOn mctx e pf pm = StateT.run' (Lean.MetavarContext.DependsOn.main mctx pf pm e) ∅
Similar to findExprDependsOn
, but checks the expressions in the given local declaration
depends on a free variable x
s.t. pf x
is true
or an unassigned metavariable ?m
s.t. pm ?m
is true.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.exprDependsOn mctx e fvarId = Lean.MetavarContext.findExprDependsOn mctx e fun a => fvarId == a
Equations
- Lean.MetavarContext.localDeclDependsOn mctx localDecl fvarId = Lean.MetavarContext.findLocalDeclDependsOn mctx localDecl fun a => fvarId == a
Similar to exprDependsOn
, but x
can be a free variable or an unassigned metavariable.
Equations
- One or more equations did not get rendered due to their size.
Similar to localDeclDependsOn
, but x
can be a free variable or an unassigned metavariable.
Equations
- One or more equations did not get rendered due to their size.
- revertFailure: Lean.MetavarContext → Lean.LocalContext → Array Lean.Expr → String → Lean.MetavarContext.MkBinding.Exception
Equations
- One or more equations did not get rendered due to their size.
- mctx : Lean.MetavarContext
- nextMacroScope : Lean.MacroScope
- ngen : Lean.NameGenerator
- cache : Std.HashMap Lean.ExprStructEq Lean.Expr
MkBinding
and elimMVarDepsAux
are mutually recursive, but cache
is only used at elimMVarDepsAux
.
We use a single state object for convenience.
We have a NameGenerator
because we need to generate fresh auxiliary metavariables.
- mainModule : Lean.Name
- preserveOrder : Bool
When creating binders for abstracted metavariables, we use the following
BinderInfo
.binderInfoForMVars : Lean.BinderInfoSet of unassigned metavariables being abstracted.
mvarIdsToAbstract : Lean.MVarIdSet
Equations
- Lean.MetavarContext.MkBinding.preserveOrder = do let a ← read pure a.preserveOrder
Equations
- One or more equations did not get rendered due to their size.
Given toRevert
an array of free variables s.t. lctx
contains their declarations,
return a new array of free variables that contains toRevert
and all free variables
in lctx
that may depend on toRevert
.
Remark: the result is sorted by LocalDecl
indices.
Remark: We used to throw an Exception.revertFailure
exception when an auxiliary declaration
had to be reversed. Recall that auxiliary declarations are created when compiling (mutually)
recursive definitions. The revertFailure
due to auxiliary declaration dependency was originally
introduced in Lean3 to address issue https://github.com/leanprover/lean/issues/1258.
In Lean4, this solution is not satisfactory because all definitions/theorems are potentially
recursive. So, even an simple (incomplete) definition such as
variables {α : Type} in
def f (a : α) : List α :=
_
would trigger the Exception.revertFailure
exception. In the definition above,
the elaborator creates the auxiliary definition f : {α : Type} → List α
.
The _
is elaborated as a new fresh variable ?m
that contains α : Type
, a : α
, and f : α → List α
in its context,
When we try to create the lambda fun {α : Type} (a : α) => ?m
, we first need to create
an auxiliary ?n
which do not contain α
and a
in its context. That is,
we create the metavariable ?n : {α : Type} → (a : α) → (f : α → List α) → List α
,
add the delayed assignment ?n #[α, a, f] := ?m α a f
, and create the lambda
fun {α : Type} (a : α) => ?n α a f
.
See elimMVarDeps
for more information.
If we kept using the Lean3 approach, we would get the Exception.revertFailure
exception because we are
reverting the auxiliary definition f
.
Note that https://github.com/leanprover/lean/issues/1258 is not an issue in Lean4 because we have changed how we compile recursive definitions.
Equations
- One or more equations did not get rendered due to their size.
Create a new LocalContext
by removing the free variables in toRevert
from lctx
.
We use this function when we create auxiliary metavariables at elimMVarDepsAux
.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.MkBinding.elimMVarDeps xs e = if (!Lean.Expr.hasMVar e) = true then pure e else Lean.MetavarContext.MkBinding.withFreshCache (Lean.MetavarContext.MkBinding.elim xs e)
Equations
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
.
elimMVarDeps
is defined later in this file.
Equations
- Lean.MetavarContext.MkBinding.abstractRange xs i e = do let e ← Lean.MetavarContext.MkBinding.elimMVarDeps xs e pure (Lean.Expr.abstractRange e i xs)
Similar to LocalContext.mkBinding
, but handles metavariables correctly.
If usedOnly == false
then forall
and lambda
expressions are created only for used variables.
If usedLetOnly == false
then let
expressions are created only for used (let-) variables.
Equations
- One or more equations did not get rendered due to their size.
- mainModule : Lean.Name
- lctx : Lean.LocalContext
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.mkLambda xs e usedOnly usedLetOnly binderInfoForMVars = do let a ← Lean.MetavarContext.mkBinding true xs e usedOnly usedLetOnly binderInfoForMVars pure a.fst
Equations
- Lean.MetavarContext.mkForall xs e usedOnly usedLetOnly binderInfoForMVars = do let a ← Lean.MetavarContext.mkBinding false xs e usedOnly usedLetOnly binderInfoForMVars pure a.fst
Equations
- One or more equations did not get rendered due to their size.
isWellFormed mctx lctx e
return true if
- All locals in
e
are declared inlctx
- All metavariables
?m
ine
have a local context which is a subprefix oflctx
or are assigned, and the assignment is well-formed.
- paramNamePrefix : Lean.Name
- except : Lean.MVarId → Bool
- mctx : Lean.MetavarContext
- nextParamIdx : Nat
- cache : Std.HashMap Lean.ExprStructEq Lean.Expr
Equations
- One or more equations did not get rendered due to their size.
- mctx : Lean.MetavarContext
- nextParamIdx : Nat
- expr : Lean.Expr
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.MetavarContext.getExprAssignmentDomain mctx = Std.PersistentHashMap.foldl mctx.eAssignment (fun a mvarId x => Array.push a mvarId) #[]