@kha @dselsam
Suppose we are trying to retrieve the global instances for
`(Monad (StateM Nat))`.
During retrieval, we reducde `StateM Nat` into `fun x => StateT Nat Id x`
However, the `DiscrTree` contains an entry for `Monad (StateT * *)`.
Thus, we fail to retrieve any instance.
I fixed the particular issue by using eta reduction.
Not sure we will encounter other definitional-equality related problems .
@kha @dselsam FYI
The original motivation for saving/restoring the cache was not
correctness, but cache size management. When we go inside a binder
using the telescope methods, we extend the local context with new fresh
free variables, execute the action `k` using the new extended local
context, and then restore it. Any cached result containing these
fresh variables is dead after executing `k`. So, `savingCache` here
could be viewed as a "checkpoint". However, it also removes any
cached entry that does not contain the new fresh variables.
I found this inconvenient in practice, and it is the wrong choice
in a few cases. Example: we have a `forall` expr (aka arrow), and use a
telescope to go inside, and then invoke TC. If the telescope uses
`savingCache`, we lose the cached TC instance witness. This is
wasteful since the witness often doesn't even depend on the new fresh
free variables created by the telescope.
Thus, this commit removes the `savingCache` occurrences from
the "telescope" methods. Users may still manually use it if
they think it is appropriate. That is, they can write
```lean
savingCache $ forallTelescope e $ fun xs body => <code>
```
if they really want to discard any new cache entry created while
executing `<code>`.