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: bound type class cache entry reuse by relative synthPending depth
Instead of a single depth-invariant class, each shared type class resolution cache entry now records the maximal `synthPendingDepth` (relative to the query) at which a `synthPending` decision was reached during synthesis, and is reused at any depth at which no such decision can reach the `maxSynthPendingDepth` give-up threshold. Only results whose synthesis actually hit the threshold remain keyed to their exact depth.
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."
467
483
}
468
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
+
469
496
/--
470
497
Contextual information for the `MetaM` monad.
471
498
-/
@@ -507,13 +534,14 @@ structure Context where
507
534
-/
508
535
synthPendingDepth : Nat := 0
509
536
/--
510
-
When set, the reference is set to `true` as soon as a `synthPending` decision is reached,
511
-
i.e. behavior that may depend on `synthPendingDepth`. The type class resolution cache uses
512
-
this to decide whether a result is depth-invariant; see `SynthInstanceCacheKey.synthPendingDepth`.
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`.
513
541
The reference is intentionally not part of the backtrackable state: a `synthPending`
514
542
invocation in a discarded search branch still influenced the search outcome.
0 commit comments