refactor: Target&LocalDecl => Replace

This commit is contained in:
Leonardo de Moura 2020-09-17 13:59:22 -07:00
parent 4ea8db2722
commit 3dbe2076b9
3 changed files with 11 additions and 26 deletions

View file

@ -9,9 +9,8 @@ import Lean.Meta.Tactic.Apply
import Lean.Meta.Tactic.Revert
import Lean.Meta.Tactic.Clear
import Lean.Meta.Tactic.Assert
import Lean.Meta.Tactic.Target
import Lean.Meta.Tactic.Rewrite
import Lean.Meta.Tactic.Generalize
import Lean.Meta.Tactic.LocalDecl
import Lean.Meta.Tactic.Replace
import Lean.Meta.Tactic.Induction
import Lean.Meta.Tactic.Cases

View file

@ -1,24 +0,0 @@
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.AppBuilder
import Lean.Meta.Tactic.Util
import Lean.Meta.Tactic.Assert
import Lean.Meta.Tactic.Intro
import Lean.Meta.Tactic.Clear
namespace Lean
namespace Meta
def replaceLocalDecl (mvarId : MVarId) (fvarId : FVarId) (newType : Expr) (eqProof : Expr) : MetaM (FVarId × MVarId) := do
withMVarContext mvarId $ do
localDecl ← getLocalDecl fvarId;
newTypePr ← mkEqMP eqProof (mkFVar fvarId);
mvarId ← assert mvarId localDecl.userName newType newTypePr;
(fvarIdNew, mvarId) ← intro1 mvarId;
(do mvarId ← clear mvarId fvarId; pure (fvarIdNew, mvarId)) <|> pure (fvarIdNew, mvarId)
end Meta
end Lean

View file

@ -7,6 +7,8 @@ import Lean.Meta.AppBuilder
import Lean.Meta.Tactic.Util
import Lean.Meta.Tactic.Revert
import Lean.Meta.Tactic.Intro
import Lean.Meta.Tactic.Clear
import Lean.Meta.Tactic.Assert
namespace Lean
namespace Meta
@ -46,6 +48,14 @@ withMVarContext mvarId do
assignExprMVar mvarId newMVar;
pure newMVar.mvarId!
def replaceLocalDecl (mvarId : MVarId) (fvarId : FVarId) (newType : Expr) (eqProof : Expr) : MetaM (FVarId × MVarId) := do
withMVarContext mvarId $ do
localDecl ← getLocalDecl fvarId;
newTypePr ← mkEqMP eqProof (mkFVar fvarId);
mvarId ← assert mvarId localDecl.userName newType newTypePr;
(fvarIdNew, mvarId) ← intro1 mvarId;
(do mvarId ← clear mvarId fvarId; pure (fvarIdNew, mvarId)) <|> pure (fvarIdNew, mvarId)
def change (mvarId : MVarId) (targetNew : Expr) : MetaM MVarId :=
withMVarContext mvarId do
target ← getMVarType mvarId;