Equations
- Lean.instInhabitedLocalInstance = { default := { className := default, fvar := default } }
@[inline]
Equations
Equations
- Lean.instBEqLocalInstance = { beq := fun i₁ i₂ => i₁.fvar == i₂.fvar }
Equations
- Lean.LocalInstances.erase localInsts fvarId = match Array.findIdx? localInsts fun inst => Lean.Expr.fvarId! inst.fvar == fvarId with | some idx => Array.eraseIdx localInsts idx | x => localInsts
- natural: Lean.MetavarKind
- synthetic: Lean.MetavarKind
- syntheticOpaque: Lean.MetavarKind
Equations
- Lean.instReprMetavarKind = { reprPrec := [anonymous] }
Equations
- Lean.instInhabitedMetavarKind = { default := Lean.MetavarKind.natural }
Equations
- Lean.MetavarKind.isSyntheticOpaque x = match x with | Lean.MetavarKind.syntheticOpaque => true | x => false
Equations
- Lean.MetavarKind.isNatural x = match x 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
- Lean.instInhabitedMetavarDecl = { default := { userName := default, lctx := default, type := default, depth := default, localInstances := default, kind := default, numScopeArgs := default, index := default } }
- lctx : Lean.LocalContext
- fvars : Array Lean.Expr
- val : Lean.Expr
- depth : Nat
- mvarCounter : Nat
- lDepth : Std.PersistentHashMap Lean.MVarId Nat
- decls : Std.PersistentHashMap Lean.MVarId Lean.MetavarDecl
- 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
instance
Lean.instMonadMCtx
(m : Type → Type)
(n : Type → Type)
[inst : MonadLift m n]
[inst : Lean.MonadMCtx m]
:
Equations
- Lean.instMonadMCtx m n = { getMCtx := liftM Lean.getMCtx, modifyMCtx := fun f => liftM (Lean.modifyMCtx f) }
Equations
- Lean.MetavarContext.instInhabitedMetavarContext = { default := { 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 } } }
Equations
- Lean.MetavarContext.mkMetavarContext x = { 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 } }
def
Lean.MetavarContext.addExprMVarDecl
(mctx : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(userName : Lean.Name)
(lctx : Lean.LocalContext)
(localInstances : Lean.LocalInstances)
(type : Lean.Expr)
(kind : optParam Lean.MetavarKind Lean.MetavarKind.natural)
(numScopeArgs : optParam Nat 0)
:
Equations
- Lean.MetavarContext.addExprMVarDecl mctx mvarId userName lctx localInstances type kind numScopeArgs = { depth := mctx.depth, mvarCounter := mctx.mvarCounter + 1, lDepth := mctx.lDepth, decls := Std.PersistentHashMap.insert mctx.decls mvarId { userName := userName, lctx := lctx, type := type, depth := mctx.depth, localInstances := localInstances, kind := kind, numScopeArgs := numScopeArgs, index := mctx.mvarCounter }, userNames := if Lean.Name.isAnonymous userName = true then mctx.userNames else Std.PersistentHashMap.insert mctx.userNames userName mvarId, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
def
Lean.MetavarContext.addExprMVarDeclExp
(mctx : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(userName : Lean.Name)
(lctx : Lean.LocalContext)
(localInstances : Lean.LocalInstances)
(type : Lean.Expr)
(kind : Lean.MetavarKind)
:
Equations
- Lean.MetavarContext.addExprMVarDeclExp mctx mvarId userName lctx localInstances type kind = Lean.MetavarContext.addExprMVarDecl mctx mvarId userName lctx localInstances type kind
Equations
- Lean.MetavarContext.addLevelMVarDecl mctx mvarId = { depth := mctx.depth, mvarCounter := mctx.mvarCounter, lDepth := Std.PersistentHashMap.insert mctx.lDepth mvarId mctx.depth, decls := mctx.decls, userNames := mctx.userNames, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
Equations
- Lean.MetavarContext.findDecl? mctx mvarId = Std.PersistentHashMap.find? mctx.decls mvarId
Equations
- Lean.MetavarContext.getDecl mctx mvarId = match Std.PersistentHashMap.find? mctx.decls mvarId with | some decl => decl | none => panicWithPosWithDecl "Lean.MetavarContext" "Lean.MetavarContext.getDecl" 343 17 "unknown metavariable"
Equations
- Lean.MetavarContext.findUserName? mctx userName = Std.PersistentHashMap.find? mctx.userNames userName
def
Lean.MetavarContext.setMVarKind
(mctx : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(kind : Lean.MetavarKind)
:
Equations
- Lean.MetavarContext.setMVarKind mctx mvarId kind = let decl := Lean.MetavarContext.getDecl mctx mvarId; { depth := mctx.depth, mvarCounter := mctx.mvarCounter, lDepth := mctx.lDepth, decls := Std.PersistentHashMap.insert mctx.decls mvarId { userName := decl.userName, lctx := decl.lctx, type := decl.type, depth := decl.depth, localInstances := decl.localInstances, kind := kind, numScopeArgs := decl.numScopeArgs, index := decl.index }, userNames := mctx.userNames, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
def
Lean.MetavarContext.renameMVar
(mctx : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(userName : Lean.Name)
:
Equations
- Lean.MetavarContext.renameMVar mctx mvarId userName = let decl := Lean.MetavarContext.getDecl mctx mvarId; { depth := mctx.depth, mvarCounter := mctx.mvarCounter, lDepth := mctx.lDepth, decls := Std.PersistentHashMap.insert mctx.decls mvarId { userName := userName, lctx := decl.lctx, type := decl.type, depth := decl.depth, localInstances := decl.localInstances, kind := decl.kind, numScopeArgs := decl.numScopeArgs, index := decl.index }, userNames := let userNames := Std.PersistentHashMap.erase mctx.userNames decl.userName; if Lean.Name.isAnonymous userName = true then userNames else Std.PersistentHashMap.insert userNames userName mvarId, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
def
Lean.MetavarContext.setMVarType
(mctx : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(type : Lean.Expr)
:
Equations
- Lean.MetavarContext.setMVarType mctx mvarId type = let decl := Lean.MetavarContext.getDecl mctx mvarId; { depth := mctx.depth, mvarCounter := mctx.mvarCounter, lDepth := mctx.lDepth, decls := Std.PersistentHashMap.insert mctx.decls mvarId { userName := decl.userName, lctx := decl.lctx, type := type, depth := decl.depth, localInstances := decl.localInstances, kind := decl.kind, numScopeArgs := decl.numScopeArgs, index := decl.index }, userNames := mctx.userNames, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
Equations
- Lean.MetavarContext.findLevelDepth? mctx mvarId = Std.PersistentHashMap.find? mctx.lDepth mvarId
Equations
- Lean.MetavarContext.getLevelDepth mctx mvarId = match Lean.MetavarContext.findLevelDepth? mctx mvarId with | some d => d | none => panicWithPosWithDecl "Lean.MetavarContext" "Lean.MetavarContext.getLevelDepth" 372 14 "unknown metavariable"
Equations
- Lean.MetavarContext.isAnonymousMVar mctx mvarId = match Lean.MetavarContext.findDecl? mctx mvarId with | none => false | some mvarDecl => Lean.Name.isAnonymous mvarDecl.userName
def
Lean.MetavarContext.assignLevel
(m : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(val : Lean.Level)
:
Equations
- Lean.MetavarContext.assignLevel m mvarId val = { depth := m.depth, mvarCounter := m.mvarCounter, lDepth := m.lDepth, decls := m.decls, userNames := m.userNames, lAssignment := Std.PersistentHashMap.insert m.lAssignment mvarId val, eAssignment := m.eAssignment, dAssignment := m.dAssignment }
def
Lean.MetavarContext.assignExpr
(m : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(val : Lean.Expr)
:
Equations
- Lean.MetavarContext.assignExpr m mvarId val = { depth := m.depth, mvarCounter := m.mvarCounter, lDepth := m.lDepth, decls := m.decls, userNames := m.userNames, lAssignment := m.lAssignment, eAssignment := Std.PersistentHashMap.insert m.eAssignment mvarId val, dAssignment := m.dAssignment }
def
Lean.MetavarContext.assignDelayed
(m : Lean.MetavarContext)
(mvarId : Lean.MVarId)
(lctx : Lean.LocalContext)
(fvars : Array Lean.Expr)
(val : Lean.Expr)
:
Equations
- Lean.MetavarContext.assignDelayed m mvarId lctx fvars val = { depth := m.depth, mvarCounter := m.mvarCounter, lDepth := m.lDepth, decls := m.decls, userNames := m.userNames, lAssignment := m.lAssignment, eAssignment := m.eAssignment, dAssignment := Std.PersistentHashMap.insert m.dAssignment mvarId { lctx := lctx, fvars := fvars, val := val } }
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
- Lean.MetavarContext.eraseDelayed m mvarId = { depth := m.depth, mvarCounter := m.mvarCounter, lDepth := m.lDepth, decls := m.decls, userNames := m.userNames, lAssignment := m.lAssignment, eAssignment := m.eAssignment, dAssignment := Std.PersistentHashMap.erase m.dAssignment mvarId }
Equations
- Lean.MetavarContext.isLevelAssignable mctx mvarId = match Std.PersistentHashMap.find? mctx.lDepth mvarId with | some d => d == mctx.depth | x => panicWithPosWithDecl "Lean.MetavarContext" "Lean.MetavarContext.isLevelAssignable" 427 14 "unknown universe metavariable"
Equations
- Lean.MetavarContext.isExprAssignable mctx mvarId = let decl := Lean.MetavarContext.getDecl mctx mvarId; decl.depth == mctx.depth
Equations
- Lean.MetavarContext.incDepth mctx = { depth := mctx.depth + 1, mvarCounter := mctx.mvarCounter, lDepth := mctx.lDepth, decls := mctx.decls, userNames := mctx.userNames, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
Equations
- Lean.MetavarContext.hasAssignedLevelMVar mctx (Lean.Level.succ lvl x_1) = (Lean.Level.hasMVar lvl && Lean.MetavarContext.hasAssignedLevelMVar mctx lvl)
- Lean.MetavarContext.hasAssignedLevelMVar mctx (Lean.Level.max lvl₁ lvl₂ x_1) = (Lean.Level.hasMVar lvl₁ && Lean.MetavarContext.hasAssignedLevelMVar mctx lvl₁ || Lean.Level.hasMVar lvl₂ && Lean.MetavarContext.hasAssignedLevelMVar mctx lvl₂)
- Lean.MetavarContext.hasAssignedLevelMVar mctx (Lean.Level.imax lvl₁ lvl₂ x_1) = (Lean.Level.hasMVar lvl₁ && Lean.MetavarContext.hasAssignedLevelMVar mctx lvl₁ || Lean.Level.hasMVar lvl₂ && Lean.MetavarContext.hasAssignedLevelMVar mctx lvl₂)
- Lean.MetavarContext.hasAssignedLevelMVar mctx (Lean.Level.mvar mvarId x_1) = Lean.MetavarContext.isLevelAssigned mctx mvarId
- Lean.MetavarContext.hasAssignedLevelMVar mctx (Lean.Level.zero x_1) = false
- Lean.MetavarContext.hasAssignedLevelMVar mctx (Lean.Level.param x_1 x_2) = false
Equations
- Lean.MetavarContext.hasAssignableLevelMVar mctx (Lean.Level.succ lvl x_1) = (Lean.Level.hasMVar lvl && Lean.MetavarContext.hasAssignableLevelMVar mctx lvl)
- Lean.MetavarContext.hasAssignableLevelMVar mctx (Lean.Level.max lvl₁ lvl₂ x_1) = (Lean.Level.hasMVar lvl₁ && Lean.MetavarContext.hasAssignableLevelMVar mctx lvl₁ || Lean.Level.hasMVar lvl₂ && Lean.MetavarContext.hasAssignableLevelMVar mctx lvl₂)
- Lean.MetavarContext.hasAssignableLevelMVar mctx (Lean.Level.imax lvl₁ lvl₂ x_1) = (Lean.Level.hasMVar lvl₁ && Lean.MetavarContext.hasAssignableLevelMVar mctx lvl₁ || Lean.Level.hasMVar lvl₂ && Lean.MetavarContext.hasAssignableLevelMVar mctx lvl₂)
- Lean.MetavarContext.hasAssignableLevelMVar mctx (Lean.Level.mvar mvarId x_1) = Lean.MetavarContext.isLevelAssignable mctx mvarId
- Lean.MetavarContext.hasAssignableLevelMVar mctx (Lean.Level.zero x_1) = false
- Lean.MetavarContext.hasAssignableLevelMVar mctx (Lean.Level.param x_1 x_2) = false
partial def
Lean.MetavarContext.instantiateLevelMVars
{m : Type → Type}
[inst : Monad m]
[inst : Lean.MonadMCtx m]
:
Lean.Level → m Lean.Level
partial def
Lean.MetavarContext.instantiateExprMVars
{m : Type → Type}
{ω : outParam Type}
[inst : Monad m]
[inst : Lean.MonadMCtx m]
[inst : STWorld ω m]
[inst : MonadLiftT (ST ω) m]
(e : Lean.Expr)
:
Equations
- Lean.MetavarContext.instMonadMCtxStateRefT'MetavarContextST = { getMCtx := get, modifyMCtx := modify }
Equations
- Lean.MetavarContext.instantiateMVars mctx e = if (!Lean.Expr.hasMVar e) = true then (e, mctx) else let instantiate := fun {ω} e => Lean.MetavarContext.instantiateExprMVars e; runST fun x => StateRefT'.run (Lean.MonadCacheT.run (instantiate e)) mctx
def
Lean.MetavarContext.instantiateLCtxMVars
(mctx : Lean.MetavarContext)
(lctx : Lean.LocalContext)
:
Equations
- Lean.MetavarContext.instantiateLCtxMVars mctx lctx = Lean.LocalContext.foldl lctx (fun x ldecl => match x with | (lctx, mctx) => match ldecl with | Lean.LocalDecl.cdecl x fvarId userName type bi => let x := Lean.MetavarContext.instantiateMVars mctx type; match x with | (type, mctx) => (Lean.LocalContext.mkLocalDecl lctx fvarId userName type bi, mctx) | Lean.LocalDecl.ldecl x fvarId userName type value nonDep => let x := Lean.MetavarContext.instantiateMVars mctx type; match x with | (type, mctx) => let x := Lean.MetavarContext.instantiateMVars mctx value; match x with | (value, mctx) => (Lean.LocalContext.mkLetDecl lctx fvarId userName type value nonDep, mctx)) ({ 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 } }, mctx)
def
Lean.MetavarContext.instantiateMVarDeclMVars
(mctx : Lean.MetavarContext)
(mvarId : Lean.MVarId)
:
Equations
- Lean.MetavarContext.instantiateMVarDeclMVars mctx mvarId = let mvarDecl := Lean.MetavarContext.getDecl mctx mvarId; let x := Lean.MetavarContext.instantiateLCtxMVars mctx mvarDecl.lctx; match x with | (lctx, mctx) => let x := Lean.MetavarContext.instantiateMVars mctx mvarDecl.type; match x with | (type, mctx) => { depth := mctx.depth, mvarCounter := mctx.mvarCounter, lDepth := mctx.lDepth, decls := Std.PersistentHashMap.insert mctx.decls mvarId { userName := mvarDecl.userName, lctx := lctx, type := type, depth := mvarDecl.depth, localInstances := mvarDecl.localInstances, kind := mvarDecl.kind, numScopeArgs := mvarDecl.numScopeArgs, index := mvarDecl.index }, userNames := mctx.userNames, lAssignment := mctx.lAssignment, eAssignment := mctx.eAssignment, dAssignment := mctx.dAssignment }
@[inline]
def
Lean.MetavarContext.DependsOn.main
(mctx : Lean.MetavarContext)
(p : Lean.FVarId → Bool)
(e : Lean.Expr)
:
Equations
- Lean.MetavarContext.DependsOn.main mctx p e = if (!Lean.Expr.hasFVar e && !Lean.Expr.hasMVar e) = true then pure false else Lean.MetavarContext.DependsOn.dep mctx p e
@[inline]
def
Lean.MetavarContext.findExprDependsOn
(mctx : Lean.MetavarContext)
(e : Lean.Expr)
(p : Lean.FVarId → Bool)
:
Equations
- Lean.MetavarContext.findExprDependsOn mctx e p = StateT.run' (Lean.MetavarContext.DependsOn.main mctx p e) ∅
@[inline]
def
Lean.MetavarContext.findLocalDeclDependsOn
(mctx : Lean.MetavarContext)
(localDecl : Lean.LocalDecl)
(p : Lean.FVarId → Bool)
:
Equations
- Lean.MetavarContext.findLocalDeclDependsOn mctx localDecl p = match localDecl with | Lean.LocalDecl.cdecl x x_1 x_2 t x_3 => Lean.MetavarContext.findExprDependsOn mctx t p | Lean.LocalDecl.ldecl x x_1 x_2 t v x_3 => StateT.run' (Lean.MetavarContext.DependsOn.main mctx p t <||> Lean.MetavarContext.DependsOn.main mctx p v) ∅
def
Lean.MetavarContext.exprDependsOn
(mctx : Lean.MetavarContext)
(e : Lean.Expr)
(fvarId : Lean.FVarId)
:
Equations
- Lean.MetavarContext.exprDependsOn mctx e fvarId = Lean.MetavarContext.findExprDependsOn mctx e fun fvarId' => fvarId == fvarId'
def
Lean.MetavarContext.localDeclDependsOn
(mctx : Lean.MetavarContext)
(localDecl : Lean.LocalDecl)
(fvarId : Lean.FVarId)
:
Equations
- Lean.MetavarContext.localDeclDependsOn mctx localDecl fvarId = Lean.MetavarContext.findLocalDeclDependsOn mctx localDecl fun fvarId' => fvarId == fvarId'
- revertFailure: Lean.MetavarContext → Lean.LocalContext → Array Lean.Expr → Lean.LocalDecl → Lean.MetavarContext.MkBinding.Exception
Equations
- Lean.MetavarContext.MkBinding.instToStringException = { toString := fun x => match x with | Lean.MetavarContext.MkBinding.Exception.revertFailure x lctx toRevert decl => "failed to revert " ++ toString (Array.map (fun x => "'" ++ toString (Lean.LocalDecl.userName (Lean.LocalContext.getFVar! lctx x)) ++ "'") toRevert) ++ ", '" ++ toString (Lean.LocalDecl.userName decl) ++ "' depends on them, and it is an auxiliary declaration created by the elaborator" ++ " (possible solution: use tactic 'clear' to remove '" ++ toString (Lean.LocalDecl.userName decl) ++ "' from local context)" }
- mctx : Lean.MetavarContext
- ngen : Lean.NameGenerator
- cache : Std.HashMap Lean.ExprStructEq Lean.Expr
@[inline]
@[inline]
Equations
- Lean.MetavarContext.MkBinding.instMonadHashMapCacheAdapterExprStructEqExprMInstBEqExprStructEqInstHashableExprStructEq = { getCache := do let s ← get pure s.cache, modifyCache := fun f => modify fun s => { mctx := s.mctx, ngen := s.ngen, cache := f s.cache } }
def
Lean.MetavarContext.MkBinding.collectDeps
(mctx : Lean.MetavarContext)
(lctx : Lean.LocalContext)
(toRevert : Array Lean.Expr)
(preserveOrder : Bool)
:
Equations
- Lean.MetavarContext.MkBinding.collectDeps mctx lctx toRevert preserveOrder = if (Array.size toRevert == 0) = true then pure toRevert else let _do_jp := fun y => let newToRevert := if preserveOrder = true then toRevert else Array.mkEmpty (Array.size toRevert); let firstDeclToVisit := Lean.MetavarContext.MkBinding.getLocalDeclWithSmallestIdx lctx toRevert; let initSize := Array.size newToRevert; Lean.LocalContext.foldlM lctx (fun newToRevert decl => if Nat.any (fun i => Lean.LocalDecl.fvarId decl == Lean.Expr.fvarId! (Array.get! newToRevert i)) initSize = true then pure newToRevert else if Array.any toRevert (fun x => Lean.LocalDecl.fvarId decl == Lean.Expr.fvarId! x) 0 (Array.size toRevert) = true then pure (Array.push newToRevert (Lean.LocalDecl.toExpr decl)) else if (Lean.MetavarContext.findLocalDeclDependsOn mctx decl fun fvarId => Array.any newToRevert (fun x => Lean.Expr.fvarId! x == fvarId) 0 (Array.size newToRevert)) = true then pure (Array.push newToRevert (Lean.LocalDecl.toExpr decl)) else pure newToRevert) newToRevert (Lean.LocalDecl.index firstDeclToVisit); if preserveOrder = true then do let y ← Nat.forM (Array.size toRevert) fun i => let fvar := Array.getOp toRevert i; let decl := Lean.LocalContext.getFVar! lctx fvar; Nat.forM i fun j => let prevFVar := Array.getOp toRevert j; let prevDecl := Lean.LocalContext.getFVar! lctx prevFVar; if Lean.MetavarContext.localDeclDependsOn mctx prevDecl (Lean.Expr.fvarId! fvar) = true then throw (Lean.MetavarContext.MkBinding.Exception.revertFailure mctx lctx toRevert prevDecl) else pure PUnit.unit _do_jp y else do let y ← pure PUnit.unit _do_jp y
def
Lean.MetavarContext.MkBinding.reduceLocalContext
(lctx : Lean.LocalContext)
(toRevert : Array Lean.Expr)
:
Equations
- Lean.MetavarContext.MkBinding.reduceLocalContext lctx toRevert = Array.foldr (fun x lctx => Lean.LocalContext.erase lctx (Lean.Expr.fvarId! x)) lctx toRevert (Array.size toRevert)
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
@[inline]
Equations
- Lean.MetavarContext.MkBinding.abstractRange xs i e = do let e ← Lean.MetavarContext.MkBinding.elimMVarDeps xs e pure (Lean.Expr.abstractRange e i xs)
@[specialize]
def
Lean.MetavarContext.MkBinding.mkBinding
(isLambda : Bool)
(lctx : Lean.LocalContext)
(xs : Array Lean.Expr)
(e : Lean.Expr)
(usedOnly : Bool)
(usedLetOnly : Bool)
:
Equations
- Lean.MetavarContext.MkBinding.mkBinding isLambda lctx xs e usedOnly usedLetOnly = do let e ← Lean.MetavarContext.MkBinding.abstractRange xs (Array.size xs) e Nat.foldRevM (fun i p => let x := p; match x with | (e, num) => let x := Array.getOp xs i; match Lean.LocalContext.getFVar! lctx x with | Lean.LocalDecl.cdecl x x_1 n type bi => if (!usedOnly || Lean.Expr.hasLooseBVar e 0) = true then let type := Lean.Expr.headBeta type; do let type ← Lean.MetavarContext.MkBinding.abstractRange xs i type if isLambda = true then pure (Lean.mkLambda n bi type e, num + 1) else pure (Lean.mkForall n bi type e, num + 1) else pure (Lean.Expr.lowerLooseBVars e 1 1, num) | Lean.LocalDecl.ldecl x x_1 n type value nonDep => if (!usedLetOnly || Lean.Expr.hasLooseBVar e 0) = true then do let type ← Lean.MetavarContext.MkBinding.abstractRange xs i type let value ← Lean.MetavarContext.MkBinding.abstractRange xs i value pure (Lean.mkLet n type value e nonDep, num + 1) else pure (Lean.Expr.lowerLooseBVars e 1 1, num)) (e, 0) (Array.size xs)
@[inline]
def
Lean.MetavarContext.elimMVarDeps
(xs : Array Lean.Expr)
(e : Lean.Expr)
(preserveOrder : Bool)
:
Equations
- Lean.MetavarContext.elimMVarDeps xs e preserveOrder x = Lean.MetavarContext.MkBinding.elimMVarDeps xs e preserveOrder
def
Lean.MetavarContext.revert
(xs : Array Lean.Expr)
(mvarId : Lean.MVarId)
(preserveOrder : Bool)
:
Equations
- Lean.MetavarContext.revert xs mvarId preserveOrder x = Lean.MetavarContext.MkBinding.revert xs mvarId preserveOrder
def
Lean.MetavarContext.mkBinding
(isLambda : Bool)
(xs : Array Lean.Expr)
(e : Lean.Expr)
(usedOnly : optParam Bool false)
(usedLetOnly : optParam Bool true)
:
Equations
- Lean.MetavarContext.mkBinding isLambda xs e usedOnly usedLetOnly lctx = Lean.MetavarContext.MkBinding.mkBinding isLambda lctx xs e usedOnly usedLetOnly false
@[inline]
def
Lean.MetavarContext.mkLambda
(xs : Array Lean.Expr)
(e : Lean.Expr)
(usedOnly : optParam Bool false)
(usedLetOnly : optParam Bool true)
:
Equations
- Lean.MetavarContext.mkLambda xs e usedOnly usedLetOnly = do let discr ← Lean.MetavarContext.mkBinding true xs e usedOnly usedLetOnly let x : Lean.Expr × Nat := discr match x with | (e, x) => pure e
@[inline]
def
Lean.MetavarContext.mkForall
(xs : Array Lean.Expr)
(e : Lean.Expr)
(usedOnly : optParam Bool false)
(usedLetOnly : optParam Bool true)
:
Equations
- Lean.MetavarContext.mkForall xs e usedOnly usedLetOnly = do let discr ← Lean.MetavarContext.mkBinding false xs e usedOnly usedLetOnly let x : Lean.Expr × Nat := discr match x with | (e, x) => pure e
@[inline]
Equations
partial def
Lean.MetavarContext.isWellFormed
(mctx : Lean.MetavarContext)
(lctx : Lean.LocalContext)
:
- mctx : Lean.MetavarContext
- paramNames : Array Lean.Name
- nextParamIdx : Nat
- cache : Std.HashMap Lean.ExprStructEq Lean.Expr
@[inline]
Equations
- Lean.MetavarContext.LevelMVarToParam.instMonadCacheExprStructEqExprM = { findCached? := fun e => do let a ← get pure (Std.HashMap.find? a.cache e), cache := fun e v => modify fun s => { mctx := s.mctx, paramNames := s.paramNames, nextParamIdx := s.nextParamIdx, cache := Std.HashMap.insert s.cache e v } }
partial def
Lean.MetavarContext.LevelMVarToParam.main.visitApp
(f : Lean.Expr)
(args : Array Lean.Expr)
:
- mctx : Lean.MetavarContext
- newParamNames : Array Lean.Name
- nextParamIdx : Nat
- expr : Lean.Expr
def
Lean.MetavarContext.levelMVarToParam
(mctx : Lean.MetavarContext)
(alreadyUsedPred : Lean.Name → Bool)
(e : Lean.Expr)
(paramNamePrefix : optParam Lean.Name `u)
(nextParamIdx : optParam Nat 1)
:
Equations
- Lean.MetavarContext.levelMVarToParam mctx alreadyUsedPred e paramNamePrefix nextParamIdx = let x := Lean.MetavarContext.LevelMVarToParam.main e { paramNamePrefix := paramNamePrefix, alreadyUsedPred := alreadyUsedPred } { mctx := mctx, paramNames := #[], nextParamIdx := nextParamIdx, cache := ∅ }; match x with | (e, s) => { mctx := s.mctx, newParamNames := s.paramNames, nextParamIdx := s.nextParamIdx, expr := e }
Equations
- Lean.MetavarContext.getExprAssignmentDomain mctx = Std.PersistentHashMap.foldl mctx.eAssignment (fun a mvarId x => Array.push a mvarId) #[]