blob: 9764bca588a0a855c1f87e1ba23b43a6d1a27a8b [file]
/-
Copyright (c) 2026 Thomas Murrils. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Murrils
-/
module
prelude
public import Lean.Expr
public section
namespace Lean.Expr
/--
Tests if any of the binders of `(x₀ : A₀) → (x₁ : A₁) → ⋯ → X` which satisfy `p Aᵢ bi` (with `bi`
the `binderInfo`) are unused in the renainder of the type (i.e. in `(xᵢ₊₁ : Aᵢ₊₁) → ⋯ → X`).
Note that the argument to `p` may have loose bvars. This is a performance optimization.
This function runs `cleanupAnnotations` on each type suffix `(xᵢ₊₁ : Aᵢ₊₁) → ⋯ → X` before
examining it.
We see through `let`s, and do not report if any of them are unused.
-/
@[specialize p]
partial def hasUnusedForallBindersWhere (p : BinderInfo → Expr → Bool) (e : Expr) : Bool :=
match e.cleanupAnnotations with
| .forallE _ type body bi =>
p bi type && !(body.hasLooseBVar 0) || body.hasUnusedForallBindersWhere p
/- See through `letE` -/
| .letE _ _ _ body _ => body.hasUnusedForallBindersWhere p
| _ => false
end Lean.Expr