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
Auto merge of #143054 - lcnr:search_graph-3, r=<try>
search graph: improve rebasing and add forced ambiguity support
This slightly strengthens rebasing and actually checks for the property we want to maintain. Consider the following very minor changes in benchmarks:
| | dropped entries old | new | compute_goal old | new |
|---|----|----|---|----|
| diesel | 20412 | 4533 | 5144336 | 5128470 |
| nalgebra | 2570 | 112 | 779257 | 778571 |
| `./x.py b --stage 2`¹ | 17234 | 7680 |14242763 | 142375634 |
¹ with the alias-relate fast-path to avoid the hang in rayon 😅
There are two additional optimizations we can and should do here:
- we should be able to just always rebase if cycle heads already have a provisional result from a previous iteration
- we currently only apply provisional cache entries if the `path_to_entry` matches exactly. We should be able to extend this e.g. if you have an entry for `B` in `ABA` where the path `BA` is coinductive, then we can use this entry even if the current path from `A` to `B` is inductive.
---
Finally, I've added support for `PathKind::ForcedAmbiguity` which always forced the initial provisional result to be ambiguous. A am using this for cycles involving negative reasons, which is currently only used by the fuzzer in https://github.com/lcnr/search_graph_fuzz. Consider the following setup: A goal `A` which only holds if `B` does not hold, and `B` which only holds if `A` does not hold.
- A only holds if B does not hold, results in X
- B only holds if A does not hold, results in !X
- A cycle, provisional result X
- B only holds if A does not hold, results in X
- A only holds if B does not hold, results in !X
- B cycle, provisional result X
With negative reasoning, the result of cycle participants depends on their position in the cycle. This means using cache entries while other entries are on the stack/have been popped is wrong. It's also generally just kinda iffy. By always forcing the initial provisional result of such cycles to be ambiguity, we can avoid this, as "not maybe" is just "maybe" again.
Rust kind of has negative reasoning due to incompleteness, consider the following setup:
- `T::Foo eq u32`
- normalize `T::Foo`
- via impl -> `u32`
- via param_env -> `T`
- nested goals...
`T::Foo eq u32` holds exactly if the nested goals of the `param_env` candidate do not hold, as preferring that candidate over the impl causes the alias-relate to fail. This means the current provisional cache may cause us to ignore `param_env` preference in rare cases. This is not unsound and I don't care about it, as we already have this behavior when rerunning on changed fixpoint results:
- `T: Trait`
- via impl ok
- via env
- `T: Trait` non-productive cycle
- result OK, rerun changed provisional result
- `T: Trait`
- via impl ok
- via env
- `T: Trait` using the provisional result, can be thought of as recursively expanding the proof tree
- via impl ok
- via env <don't care>
- prefer the env candidate, reached fixpoint
---
One could imaging changing `ParamEnv` candidates or the impl shadowing check to use `PathKind::ForcedAmbiguity` to make the search graph less observable instead of only using it for fuzzing. However, incomplete candidate preference isn't really negative reasoning and doing this is a breaking change rust-lang/trait-system-refactor-initiative#114
r? `@compiler-errors`
0 commit comments