Compare commits

...

2 Commits

Author SHA1 Message Date
Leonardo de Moura
585036db1e chore: add seal performance workaround 2025-05-24 17:31:12 -07:00
Leonardo de Moura
479a999144 feat: add profileitM at canon 2025-05-24 16:34:17 -07:00
2 changed files with 15 additions and 2 deletions

View File

@@ -77,7 +77,15 @@ def canonElemCore (parent : Expr) (f : Expr) (i : Nat) (e : Expr) (useIsDefEqBou
let eType inferType e
let cs := s.argMap.find? key |>.getD []
for (c, cType) in cs do
-- We first check the typesr
/-
We first check the types
The following checks are a performance bottleneck.
For example, in the test `grind_ite.lean`, there are many checks of the form:
```
w_4 ∈ assign.insert v true → Prop =?= w_1 ∈ assign.insert v false → Prop
```
where `grind` unfolds the definition of `DHashMap.insert` and `TreeMap.insert`.
-/
if ( withDefault <| isDefEq eType cType) then
if ( isDefEq e c) then
-- We used to check `c.fvarsSubset e` because it is not
@@ -196,7 +204,7 @@ where
end Canon
/-- Canonicalizes nested types, type formers, and instances in `e`. -/
def canon (e : Expr) : GoalM Expr := do
def canon (e : Expr) : GoalM Expr := do profileitM Exception "grind canon" ( getOptions) do
trace_goal[grind.debug.canon] "{e}"
unsafe Canon.canonImpl e

View File

@@ -126,6 +126,11 @@ we are allowed to increase the size of the branches by one, and still be smaller
| var _ => 1
| .ite i t e => 2 * normSize i + max (normSize t) (normSize e) + 1
-- TODO: `grind` canonicalizer is spending a lot of time unfolding the following function.
-- TODO: remove after the new module system will hide this declaration.
seal Std.DHashMap.insert
seal Std.TreeMap.insert
def normalize (assign : Std.HashMap Nat Bool) : IfExpr IfExpr
| lit b => lit b
| var v =>