Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - refactor(Tactic/ToAdditive): avoid FindM, got removed in lean4 #14970

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Mathlib/Tactic/ToAdditive/Frontend.lean
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,8 @@ structure Config : Type where
existing : Option Bool := none
deriving Repr

open Lean.Expr.FindImpl in
/-- Implementation function for `additiveTest`.
We cache previous applications of the function, using the same method that `Expr.find?` uses,
We cache previous applications of the function, using an expression cache using ptr equality
to avoid visiting the same subexpression many times. Note that we only need to cache the
expressions without taking the value of `inApp` into account, since `inApp` only matters when
the expression is a constant. However, for this reason we have to make sure that we never
Expand All @@ -486,13 +485,15 @@ open Lean.Expr.FindImpl in
and we're not remembering the cache between these calls. -/
unsafe def additiveTestUnsafe (findTranslation? : Name → Option Name)
(ignore : Name → Option (List ℕ)) (e : Expr) : Option Name :=
let rec visit (e : Expr) (inApp := false) : OptionT FindM Name := do
let rec visit (e : Expr) (inApp := false) : OptionT (StateM (PtrSet Expr)) Name := do
if e.isConst then
if inApp || (findTranslation? e.constName).isSome then
failure
else
return e.constName
checkVisited e
if (← get).contains e then
failure
modify fun s => s.insert e
match e with
| x@(.app e a) =>
visit e true <|> do
Expand Down
Loading