feat: add withNewMCtxDepth

This commit is contained in:
Leonardo de Moura 2019-11-26 07:52:46 -08:00
parent 04417fafe8
commit f9376fe04b
2 changed files with 13 additions and 0 deletions

View file

@ -672,5 +672,15 @@ do fvarId ← mkFreshId;
adaptReader (fun (ctx : Context) => { lctx := lctx, .. ctx }) $
withNewFVar fvar type k
/--
Save cache and `MetavarContext`, bump the `MetavarContext` depth, execute `x`,
and restore saved data. -/
@[inline] def withNewMCtxDepth {α} (x : MetaM α) : MetaM α :=
do s ← get;
let savedCache := s.cache;
let savedMCtx := s.mctx;
modify $ fun s => { mctx := s.mctx.incDepth, .. s };
finally x (modify $ fun s => { cache := savedCache, mctx := savedMCtx, .. s })
end Meta
end Lean

View file

@ -310,6 +310,9 @@ def isExprAssignable (mctx : MetavarContext) (mvarId : Name) : Bool :=
let decl := mctx.getDecl mvarId;
decl.depth == mctx.depth
def incDepth (mctx : MetavarContext) : MetavarContext :=
{ depth := mctx.depth + 1, .. mctx }
/-- Return true iff the given level contains an assigned metavariable. -/
def hasAssignedLevelMVar (mctx : MetavarContext) : Level → Bool
| Level.succ lvl _ => lvl.hasMVar && hasAssignedLevelMVar lvl