chore: simplify LocalContext mk functions
This commit is contained in:
parent
b896069246
commit
dec24f3410
4 changed files with 14 additions and 13 deletions
|
|
@ -435,11 +435,10 @@ modifyGet $ fun s =>
|
|||
def localContext : Elab LocalContext :=
|
||||
do scope ← getScope; pure scope.lctx
|
||||
|
||||
def mkLocalDecl (userName : Name) (type : Expr) (bi : BinderInfo := BinderInfo.default) : Elab LocalDecl :=
|
||||
def mkLocalDecl (userName : Name) (type : Expr) (bi : BinderInfo := BinderInfo.default) : Elab Expr :=
|
||||
do idx ← mkFreshName;
|
||||
modifyGetScope $ fun scope =>
|
||||
let (decl, lctx) := scope.lctx.mkLocalDecl idx userName type bi;
|
||||
(decl, { lctx := lctx, .. scope })
|
||||
modifyScope $ fun scope => { lctx := scope.lctx.mkLocalDecl idx userName type bi, .. scope };
|
||||
pure (Expr.fvar idx)
|
||||
|
||||
def mkLambda (xs : Array Expr) (b : Expr) : Elab Expr :=
|
||||
do lctx ← localContext; pure $ lctx.mkLambda xs b
|
||||
|
|
|
|||
|
|
@ -148,8 +148,9 @@ match b.getKind with
|
|||
args.mmap $ fun arg => do
|
||||
let id := arg.getId;
|
||||
hole ← mkHoleFor arg;
|
||||
decl ← mkLocalDecl id hole;
|
||||
pure (mkLocal decl)
|
||||
-- decl ← mkLocalDecl id hole; -- HACK: this file will be deleted
|
||||
-- pure (mkLocal decl)
|
||||
mkLocalDecl id hole
|
||||
| `Lean.Parser.Term.explicitBinder =>
|
||||
let ids := (b.getArg 1).getArgs;
|
||||
let optType := b.getArg 2;
|
||||
|
|
@ -165,8 +166,9 @@ match b.getKind with
|
|||
pure $ Expr.app (Expr.app (Expr.const `optParam []) type) defVal
|
||||
| `Lean.Parser.Term.binderTactic => logErrorAndThrow optDef "old elaborator does not support tactics in parameters"
|
||||
| _ => throw "unknown binder default value annotation";
|
||||
decl ← mkLocalDecl id type;
|
||||
pure (mkLocal decl)
|
||||
-- decl ← mkLocalDecl id type; -- HACK: this file will be deleted
|
||||
-- pure (mkLocal decl)
|
||||
mkLocalDecl id type
|
||||
| `Lean.Parser.Term.implicitBinder => do runIO (IO.println $ ">> implict " ++ (toString b)); pure #[]
|
||||
| `Lean.Parser.Term.instBinder => do runIO (IO.println $ ">> inst " ++ (toString b)); pure #[]
|
||||
| _ => throw "unknown binder kind"
|
||||
|
|
|
|||
|
|
@ -75,20 +75,20 @@ lctx.nameToDecl.isEmpty
|
|||
|
||||
/- Low level API for creating local declarations. It is used to implement actions in the monads `Elab` and `Tactic`. It should not be used directly since the argument `(name : Name)` is assumed to be "unique". -/
|
||||
@[export lean_local_ctx_mk_local_decl]
|
||||
def mkLocalDecl (lctx : LocalContext) (name : Name) (userName : Name) (type : Expr) (bi : BinderInfo := BinderInfo.default) : LocalDecl × LocalContext :=
|
||||
def mkLocalDecl (lctx : LocalContext) (name : Name) (userName : Name) (type : Expr) (bi : BinderInfo := BinderInfo.default) : LocalContext :=
|
||||
match lctx with
|
||||
| { nameToDecl := map, decls := decls } =>
|
||||
let idx := decls.size;
|
||||
let decl := LocalDecl.cdecl idx name userName type bi;
|
||||
(decl, { nameToDecl := map.insert name decl, decls := decls.push decl })
|
||||
{ nameToDecl := map.insert name decl, decls := decls.push decl }
|
||||
|
||||
@[export lean_local_ctx_mk_let_decl]
|
||||
def mkLetDecl (lctx : LocalContext) (name : Name) (userName : Name) (type : Expr) (value : Expr) : LocalDecl × LocalContext :=
|
||||
def mkLetDecl (lctx : LocalContext) (name : Name) (userName : Name) (type : Expr) (value : Expr) : LocalContext :=
|
||||
match lctx with
|
||||
| { nameToDecl := map, decls := decls } =>
|
||||
let idx := decls.size;
|
||||
let decl := LocalDecl.ldecl idx name userName type value;
|
||||
(decl, { nameToDecl := map.insert name decl, decls := decls.push decl })
|
||||
{ nameToDecl := map.insert name decl, decls := decls.push decl }
|
||||
|
||||
@[export lean_local_ctx_find]
|
||||
def find (lctx : LocalContext) (name : Name) : Option LocalDecl :=
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ partial def introduceMVars (lctx : LocalContext) (locals : Array Expr) : Context
|
|||
partial def introduceLocals : Nat → LocalContext → Array Expr → Expr → LocalContext × Expr × Array Expr
|
||||
| nextIdx, lctx, ls, Expr.forallE name info domain body =>
|
||||
let idxName : Name := mkNumName (mkSimpleName "_tmp") nextIdx;
|
||||
let ⟨lDecl, lctx⟩ := lctx.mkLocalDecl idxName name domain info;
|
||||
let lctx := lctx.mkLocalDecl idxName name domain info;
|
||||
let l : Expr := Expr.fvar idxName;
|
||||
introduceLocals (nextIdx + 1) lctx (ls.push l) (body.instantiate1 l)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue