lean4-htt/tests/lean/run/tc_cache.lean
Leonardo de Moura 0d2a511bde
fix: type class resolution cache (#12286)
This PR ensures the type resolution cache properly caches results for
type classe containing output parameters.

It ensures the cache key for a query like
```
HAppend.{0, 0, ?u} (BitVec 8) (BitVec 8) ?m
```
should be independent of the specific metavariable IDs in output
parameter positions. To achieve this, output parameter arguments are
erased from the cache key. Universe levels that only appear in output
parameter types (e.g., ?u corresponding to the result type's universe)
must also be erased to avoid cache misses when the same query is issued
with different universe metavariable IDs.

---------

Co-authored-by: Kim Morrison <kim@tqft.net>
2026-02-15 03:07:15 +00:00

31 lines
1.1 KiB
Text

/-
Type class resolution cache.
Recall that we normalize keys for type class with output parameters only when the input type
contains metavariables. This is why in the following example we sold
```
new: HAppend (List Nat) (List Nat) ?_
```
and
```
new: HAppend (List Nat) (List Nat) (List Nat)
```
-/
set_option pp.mvars.anonymous false
set_option trace.Meta.synthInstance.cache true
/--
trace: [Meta.synthInstance.cache] cached: HAppend (List Nat) (List Nat) (List Nat)
[Meta.synthInstance.cache] cached: HAppend (List Nat) (List Nat) ?_
---
trace: [Meta.synthInstance.cache] cached: HAppend (List Nat) (List Nat) (List Nat)
[Meta.synthInstance.cache] cached: HAppend (List Nat) (List Nat) ?_
---
trace: [Meta.synthInstance.cache] cached: HAppend (List Nat) (List Nat) (List Nat)
[Meta.synthInstance.cache] new: HAppend (List Nat) (List Nat) ?_
---
trace: [Meta.synthInstance.cache] new: HAppend (List Nat) (List Nat) (List Nat)
[Meta.synthInstance.cache] cached: HAppend (List Nat) (List Nat) ?_
-/
#guard_msgs (ordering := sorted) in
def ex (a : List Nat) : List Nat :=
a ++ a ++ a ++ a ++ a