Compare commits

...

1 Commits

Author SHA1 Message Date
Leonardo de Moura
941d2fbb0f fix: take synthPendingDepth into account when caching TC results
closes #2522
2024-05-08 15:14:37 -07:00
2 changed files with 14 additions and 3 deletions

View File

@@ -212,7 +212,17 @@ instance : Hashable InfoCacheKey :=
fun transparency, expr, nargs => mixHash (hash transparency) <| mixHash (hash expr) (hash nargs)
end InfoCacheKey
abbrev SynthInstanceCache := PersistentHashMap (LocalInstances × Expr) (Option Expr)
structure SynthInstanceCacheKey where
localInsts : LocalInstances
type : Expr
/--
Value of `synthPendingDepth` when instance was synthesized or failed to be synthesized.
See issue #2522.
-/
synthPendingDepth : Nat
deriving Hashable, BEq
abbrev SynthInstanceCache := PersistentHashMap SynthInstanceCacheKey (Option Expr)
abbrev InferTypeCache := PersistentExprStructMap Expr
abbrev FunInfoCache := PersistentHashMap InfoCacheKey FunInfo

View File

@@ -735,7 +735,8 @@ def synthInstance? (type : Expr) (maxResultSize? : Option Nat := none) : MetaM (
unless defEq do
trace[Meta.synthInstance] "{crossEmoji} result type{indentExpr resultType}\nis not definitionally equal to{indentExpr type}"
return defEq
match s.cache.synthInstance.find? (localInsts, type) with
let cacheKey := { localInsts, type, synthPendingDepth := ( read).synthPendingDepth }
match s.cache.synthInstance.find? cacheKey with
| some result =>
trace[Meta.synthInstance] "result {result} (cached)"
if let some inst := result then
@@ -782,7 +783,7 @@ def synthInstance? (type : Expr) (maxResultSize? : Option Nat := none) : MetaM (
pure (some result)
else
pure none
modify fun s => { s with cache.synthInstance := s.cache.synthInstance.insert (localInsts, type) result? }
modify fun s => { s with cache.synthInstance := s.cache.synthInstance.insert cacheKey result? }
pure result?
/--