blob: 747ae4b7d4ebf8fb19ec7c14600f26998fe07800 [file]
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Gabriel Ebner, Sebastian Ullrich
-/
module
prelude
public import Lean.Expr
public import Lean.Util.PtrSet
public section
namespace Lean.Expr
@[extern "lean_replace_expr"]
opaque replaceImpl (f? : @& (Expr → Option Expr)) (e : @& Expr) : Expr
@[inline] def replace (f? : Expr → Option Expr) (e : Expr) : Expr :=
replaceImpl f? e
@[specialize]
def replaceNoCache (f? : Expr → Option Expr) (e : Expr) : Expr :=
match f? e with
| some eNew => eNew
| none => match e with
| .forallE _ d b _ => let d := replaceNoCache f? d; let b := replaceNoCache f? b; e.updateForallE! d b
| .lam _ d b _ => let d := replaceNoCache f? d; let b := replaceNoCache f? b; e.updateLambdaE! d b
| .mdata _ b => let b := replaceNoCache f? b; e.updateMData! b
| .letE _ t v b _ => let t := replaceNoCache f? t; let v := replaceNoCache f? v; let b := replaceNoCache f? b; e.updateLetE! t v b
| .app f a => let f := replaceNoCache f? f; let a := replaceNoCache f? a; e.updateApp! f a
| .proj _ _ b => let b := replaceNoCache f? b; e.updateProj! b
| e => e
end Lean.Expr