perf: fast paths for forEachWhere Expr.isFVar (#11973)

Add a fast path for the pattern `forEachWhere Expr.isFVar` to avoid
setting up the expression
traversal etc.

Pattern initially noticed by @Rob23oba
This commit is contained in:
Henrik Böving 2026-01-11 23:38:16 +01:00 committed by GitHub
parent d7cbdebf0b
commit c91a2c63c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -156,7 +156,8 @@ mutual
/-- Collect dependencies of the given expression. -/
partial def collectType (type : Expr) : ClosureM Unit := do
type.forEachWhere Expr.isFVar fun e => collectFVar e.fvarId!
if type.hasFVar then
type.forEachWhere Expr.isFVar fun e => collectFVar e.fvarId!
end

View file

@ -99,7 +99,8 @@ def _root_.Lean.MVarId.getNondepPropHyps (mvarId : MVarId) : MetaM (Array FVarId
let removeDeps (e : Expr) (candidates : FVarIdHashSet) : MetaM FVarIdHashSet := do
let e ← instantiateMVars e
let visit : StateRefT FVarIdHashSet MetaM FVarIdHashSet := do
e.forEachWhere Expr.isFVar fun e => modify fun s => s.erase e.fvarId!
if e.hasFVar then
e.forEachWhere Expr.isFVar fun e => modify fun s => s.erase e.fvarId!
get
visit |>.run' candidates
mvarId.withContext do