feat: add mkFreshExprMVarWithId
This commit is contained in:
parent
f600c67bb4
commit
57533726f6
2 changed files with 18 additions and 2 deletions
|
|
@ -272,11 +272,16 @@ def unfoldDefinition? (ref : Syntax) (e : Expr) : TermElabM (Option Expr) := lif
|
|||
def instantiateMVars (ref : Syntax) (e : Expr) : TermElabM Expr := liftMetaM ref $ Meta.instantiateMVars e
|
||||
def instantiateLevelMVars (ref : Syntax) (u : Level) : TermElabM Level := liftMetaM ref $ Meta.instantiateLevelMVars u
|
||||
def isClass (ref : Syntax) (t : Expr) : TermElabM (Option Name) := liftMetaM ref $ Meta.isClass t
|
||||
def mkFreshId : TermElabM Name := liftMetaM Syntax.missing Meta.mkFreshId
|
||||
def mkFreshLevelMVar (ref : Syntax) : TermElabM Level := liftMetaM ref $ Meta.mkFreshLevelMVar
|
||||
def mkFreshExprMVar (ref : Syntax) (type? : Option Expr := none) (kind : MetavarKind := MetavarKind.natural) (userName? : Name := Name.anonymous) : TermElabM Expr :=
|
||||
match type? with
|
||||
| some type => liftMetaM ref $ Meta.mkFreshExprMVar type userName? kind
|
||||
| none => liftMetaM ref $ do u ← Meta.mkFreshLevelMVar; type ← Meta.mkFreshExprMVar (mkSort u); Meta.mkFreshExprMVar type userName? kind
|
||||
def mkFreshExprMVarWithId (ref : Syntax) (mvarId : MVarId) (type? : Option Expr := none) (kind : MetavarKind := MetavarKind.natural) (userName? : Name := Name.anonymous) : TermElabM Expr :=
|
||||
match type? with
|
||||
| some type => liftMetaM ref $ Meta.mkFreshExprMVarWithId mvarId type userName? kind
|
||||
| none => liftMetaM ref $ do u ← Meta.mkFreshLevelMVar; type ← Meta.mkFreshExprMVar (mkSort u); Meta.mkFreshExprMVarWithId mvarId type userName? kind
|
||||
def mkFreshTypeMVar (ref : Syntax) (kind : MetavarKind := MetavarKind.natural) (userName? : Name := Name.anonymous) : TermElabM Expr :=
|
||||
liftMetaM ref $ do u ← Meta.mkFreshLevelMVar; Meta.mkFreshExprMVar (mkSort u) userName? kind
|
||||
def getLevel (ref : Syntax) (type : Expr) : TermElabM Level := liftMetaM ref $ Meta.getLevel type
|
||||
|
|
|
|||
|
|
@ -233,18 +233,29 @@ let id := s.ngen.curr;
|
|||
modify $ fun s => { s with ngen := s.ngen.next };
|
||||
pure id
|
||||
|
||||
private def mkFreshExprMVarAtCore
|
||||
(mvarId : MVarId) (lctx : LocalContext) (localInsts : LocalInstances) (type : Expr) (userName : Name) (kind : MetavarKind) : MetaM Expr := do
|
||||
modify $ fun s => { s with mctx := s.mctx.addExprMVarDecl mvarId userName lctx localInsts type kind };
|
||||
pure $ mkMVar mvarId
|
||||
|
||||
def mkFreshExprMVarAt
|
||||
(lctx : LocalContext) (localInsts : LocalInstances) (type : Expr) (userName : Name := Name.anonymous) (kind : MetavarKind := MetavarKind.natural)
|
||||
: MetaM Expr := do
|
||||
mvarId ← mkFreshId;
|
||||
modify $ fun s => { s with mctx := s.mctx.addExprMVarDecl mvarId userName lctx localInsts type kind };
|
||||
pure $ mkMVar mvarId
|
||||
mkFreshExprMVarAtCore mvarId lctx localInsts type userName kind
|
||||
|
||||
def mkFreshExprMVar (type : Expr) (userName : Name := Name.anonymous) (kind : MetavarKind := MetavarKind.natural) : MetaM Expr := do
|
||||
lctx ← getLCtx;
|
||||
localInsts ← getLocalInstances;
|
||||
mkFreshExprMVarAt lctx localInsts type userName kind
|
||||
|
||||
/- Low-level version of `MkFreshExprMVar` which allows users to create/reserve a `mvarId` using `mkFreshId`, and then later create
|
||||
the metavar using this method. -/
|
||||
def mkFreshExprMVarWithId (mvarId : MVarId) (type : Expr) (userName : Name := Name.anonymous) (kind : MetavarKind := MetavarKind.natural) : MetaM Expr := do
|
||||
lctx ← getLCtx;
|
||||
localInsts ← getLocalInstances;
|
||||
mkFreshExprMVarAtCore mvarId lctx localInsts type userName kind
|
||||
|
||||
def mkFreshLevelMVar : MetaM Level := do
|
||||
mvarId ← mkFreshId;
|
||||
modify $ fun s => { s with mctx := s.mctx.addLevelMVarDecl mvarId };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue