SIGN IN SIGN UP

Auto merge of #161274 - sjwang05:fast-visit, r=lcnr

add a cache to the `WfPredicates` visitor





Part of speeding up compiling `ReShell` with `-Znext-solver`, see https://github.com/rust-lang/trait-system-refactor-initiative/issues/272 and [#t-types/trait-system-refactor > more `reshell` slowness](https://rust-lang.zulipchat.com/#narrow/channel/364551-t-types.2Ftrait-system-refactor/topic/more.20.60reshell.60.20slowness/with/616484452).

The PR changes the `WfPredicates` visitor to only collect new bounds for unique types. That is, if we have a type like:

```
type T0 = Map<Then<Whitespace, Whitespace>>
type T1 = Map<Then<T0, T0>>
type T2 = Map<Then<T1, T1>>
...
type T_N = Map<Then<T_N-1, T_N-1>>
```

etc., the visitor used to end up collecting one WF obligation for each path from `T_N` to its `Whitespace` leaves, even though WF of a type (I believe) doesn't depend on the path the visitor took to get there, which allows us to deduplicate by Ty. Not deduplicating caused us to go O(2^N) here.

next-solver is still about ~5x slower than the old solver on the third reproducer due to some other hidden quadratics, and fixing that seems to be more involved, but I think this PR will still be ✨ An Improvement.

r? lcnr
B
bors committed
def3ee9e4f0fe1429574f402bb624439bbd13fc6