From 590de785ccbdc750c74c8faee906f61daf5b68ac Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 5 Aug 2024 20:02:20 +0200 Subject: [PATCH] chore: cleanup `betaRev` (#4921) --- src/Lean/Expr.lean | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Lean/Expr.lean b/src/Lean/Expr.lean index c2dd647c6d2a..26885a353a45 100644 --- a/src/Lean/Expr.lean +++ b/src/Lean/Expr.lean @@ -1452,28 +1452,26 @@ partial def betaRev (f : Expr) (revArgs : Array Expr) (useZeta := false) (preser else let sz := revArgs.size let rec go (e : Expr) (i : Nat) : Expr := + let done (_ : Unit) : Expr := + let n := sz - i + mkAppRevRange (e.instantiateRange n sz revArgs) 0 n revArgs match e with - | Expr.lam _ _ b _ => + | .lam _ _ b _ => if i + 1 < sz then go b (i+1) else - let n := sz - (i + 1) - mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs - | Expr.letE _ _ v b _ => + b.instantiate revArgs + | .letE _ _ v b _ => if useZeta && i < sz then go (b.instantiate1 v) i else - let n := sz - i - mkAppRevRange (e.instantiateRange n sz revArgs) 0 n revArgs - | Expr.mdata k b => + done () + | .mdata _ b => if preserveMData then - let n := sz - i - mkMData k (mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs) + done () else go b i - | b => - let n := sz - i - mkAppRevRange (b.instantiateRange n sz revArgs) 0 n revArgs + | _ => done () go f 0 /--