You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: share depth-invariant type class cache entries across synthPendingDepth
The type class resolution cache is keyed by `synthPendingDepth` (issue #2522), which partitions the whole cache by depth even though the depth can only influence a query through the `synthPending` give-up check. Track whether a query ever reached a `synthPending` decision (via a non-backtrackable `IO.Ref` in `Meta.Context`, so discarded search branches still count); results of queries that never did are now cached with `synthPendingDepth := none` and shared across all depths. Depth-sensitive results remain keyed by their exact depth as before. The `Meta.synthInstance.cache` trace now includes the depth when it is nonzero.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
descr := "maximum number of nested `synthPending` invocations. When resolving unification constraints, pending type class problems may need to be synthesized. These type class problems may create new unification constraints that again require solving new type class problems. This option puts a threshold on how many nested problems are created."
461
483
}
462
484
485
+
/--
486
+
Accumulated `synthPending` decisions of a type class query, used by the type class
487
+
resolution cache to bound the `synthPendingDepth` values at which the result may be reused.
488
+
See `SynthInstanceCacheEntry.relSynthPendingDepth`.
489
+
-/
490
+
structureSynthPendingActivitywhere
491
+
/-- Maximum `synthPendingDepth` at which a `synthPending` decision was reached. -/
492
+
maxDepth : Option Nat := none
493
+
/-- Whether some `synthPending` invocation gave up because of `maxSynthPendingDepth`. -/
494
+
guardHit : Bool := false
495
+
463
496
/--
464
497
Contextual information for the `MetaM` monad.
465
498
-/
@@ -500,6 +533,15 @@ structure Context where
500
533
Remark: `synthPending` fails if `synthPendingDepth > maxSynthPendingDepth`.
501
534
-/
502
535
synthPendingDepth : Nat := 0
536
+
/--
537
+
When set, the reference accumulates the `synthPending` decisions reached during the
538
+
current type class query, i.e. behavior that may depend on `synthPendingDepth`. The type
539
+
class resolution cache uses this to decide at which depths a result may be reused; see
540
+
`SynthInstanceCacheKey.synthPendingDepth` and `SynthInstanceCacheEntry.relSynthPendingDepth`.
541
+
The reference is intentionally not part of the backtrackable state: a `synthPending`
542
+
invocation in a discarded search branch still influenced the search outcome.
0 commit comments