chore: move to new frontend

This commit is contained in:
Leonardo de Moura 2020-10-19 11:50:42 -07:00
parent 7f5ef0c30b
commit 9778eca9b2

View file

@ -1,3 +1,4 @@
#lang lean4
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
@ -7,38 +8,37 @@ import Lean.Data.Occurrences
import Lean.HeadIndex
import Lean.Meta.ExprDefEq
namespace Lean
namespace Meta
private partial def kabstractAux (occs : Occurrences) (p : Expr) (pHeadIdx : HeadIndex) (pNumArgs : Nat) : Expr → Nat → StateRefT Nat MetaM Expr
| e, offset =>
let visitChildren : Unit → StateRefT Nat MetaM Expr := fun _ =>
match e with
| Expr.app f a _ => do f ← kabstractAux f offset; a ← kabstractAux a offset; pure $ e.updateApp! f a
| Expr.mdata _ b _ => do b ← kabstractAux b offset; pure $ e.updateMData! b
| Expr.proj _ _ b _ => do b ← kabstractAux b offset; pure $ e.updateProj! b
| Expr.letE _ t v b _ => do t ← kabstractAux t offset; v ← kabstractAux v offset; b ← kabstractAux b (offset+1); pure $ e.updateLet! t v b
| Expr.lam _ d b _ => do d ← kabstractAux d offset; b ← kabstractAux b (offset+1); pure $ e.updateLambdaE! d b
| Expr.forallE _ d b _ => do d ← kabstractAux d offset; b ← kabstractAux b (offset+1); pure $ e.updateForallE! d b
| e => pure e;
if e.hasLooseBVars then visitChildren ()
else if e.toHeadIndex == pHeadIdx && e.headNumArgs == pNumArgs then
condM (isDefEq e p)
(do i ← get;
set (i+1);
if occs.contains i then
pure (mkBVar offset)
else
visitChildren ())
(visitChildren ())
else
visitChildren ()
namespace Lean.Meta
def kabstract {m} [MonadLiftT MetaM m] (e : Expr) (p : Expr) (occs : Occurrences := Occurrences.all) : m Expr := liftMetaM do
if p.isFVar && occs == Occurrences.all then
pure $ e.abstract #[p] -- Easy case
return e.abstract #[p] -- Easy case
else
(kabstractAux occs p p.toHeadIndex p.headNumArgs e 0).run' 1
let pHeadIdx := p.toHeadIndex
let pNumArgs := p.headNumArgs
let rec visit (e : Expr) (offset : Nat) : StateRefT Nat MetaM Expr := do
let visitChildren : Unit → StateRefT Nat MetaM Expr := fun _ => do
match e with
| Expr.app f a _ => return e.updateApp! (← visit f offset) (← visit a offset)
| Expr.mdata _ b _ => return e.updateMData! (← visit b offset)
| Expr.proj _ _ b _ => return e.updateProj! (← visit b offset)
| Expr.letE _ t v b _ => return e.updateLet! (← visit t offset) (← visit v offset) (← visit b (offset+1))
| Expr.lam _ d b _ => return e.updateLambdaE! (← visit d offset) (← visit b (offset+1))
| Expr.forallE _ d b _ => return e.updateForallE! (← visit d offset) (← visit b (offset+1))
| e => return e
if e.hasLooseBVars then
visitChildren ()
else if e.toHeadIndex != pHeadIdx || e.headNumArgs != pNumArgs then
visitChildren ()
else if (← isDefEq e p) then
let i ← get
set (i+1)
if occs.contains i then
pure (mkBVar offset)
else
visitChildren ()
else
visitChildren ()
(visit e 0).run' 1
end Meta
end Lean
end Lean.Meta