-
Notifications
You must be signed in to change notification settings - Fork 13.6k
uniquify root goals during HIR typeck #144405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
This PR changes a file inside |
/// When canonicalizing the `param_env`, we keep `'static` as merging | ||
/// trait candidates relies on it when deciding whether a where-bound | ||
/// is trivial. | ||
ParamEnv, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new solver special cases 'static
? I thought we weren't supposed to do this 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yh that makes sense
if let CanonicalizeMode::Input(CanonicalizeInputKind::Predicate { | ||
is_hir_typeck_root_goal: true, | ||
}) = self.canonicalize_mode | ||
{ | ||
self.cached_fold_ty(t) | ||
} else if let Some(&ty) = self.cache.get(&(self.binder_index, t)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this somewhat confusing, it reads like "if its a root goal use the cache" which seems wrong, and then we follow it up with "otherwise use the cache" which I thought we just did :>
but cached_fold_ty
is about "caching" in the sense that we want to map multiple occurrences of ?x
to the same canonical var? whereas self.cache
is a proper ty -> canonical ty
cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cached_fold_ty
is the part of fn fold_ty
which was cached :3
renamed it to inner_fold_ty
and added a comment
/// | ||
/// See the tests in trait-system-refactor-initiative#27 for concrete examples. | ||
/// | ||
/// FIXME(-Znext-solver): This is insufficient in theory as a goal `T: Trait<?x, ?x>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not do this at the same time :3 uniquifying regions seems somewhat meh if we aren't handling T: Trait<?x, ?x>
correctly, and if it turns out that we cant "just" handle it correctly then we'd probably want to revert this (again again xd)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because it's annoying :3
r? BoxyUwU |
53a905a
to
0cb0427
Compare
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
5df011f
to
5082eab
Compare
expect this to result in a minor perf hit @bors2 try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
uniquify root goals during HIR typeck
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5082eab
to
c55b6af
Compare
Finished benchmarking commit (b91de35): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 2.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.2%, secondary 3.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 469.891s -> 470.268s (0.08%) |
We need to rely on region identity to deal with hangs such as rust-lang/trait-system-refactor-initiative#210 and to keep the current behavior of
fn try_merge_responses
.This is a problem as borrowck starts by replacing each occurrence of a region with a unique inference variable. This frequently splits a single region during HIR typeck into multiple distinct regions. As we assume goals to always succeed during borrowck, relying on two occurances of a region being identical during HIR typeck causes ICE. See the now fixed examples in rust-lang/trait-system-refactor-initiative#27 and #139409.
We've previously tried to avoid this issue by always uniquifying regions when canonicalizing goals. This prevents caching subtrees during canonicalization which resulted in hangs for very large types. People rely on such types in practice, which caused us to revert our attempt to reinstate
#[type_length_limit]
in #127670. The complete list of changes here:After more consideration, all occurrences of such large types need to happen outside of typeck/borrowck. We know this as we already walk over all types in the MIR body when replacing their regions with nll vars.
This PR therefore enables us to rely on region identity inside of the trait solver by exclusively uniquifying root goals during HIR typeck. These are the only goals we assume to hold during borrowck. This is insufficient as type inference variables may "hide" regions we later uniquify. Because of this, we now stash proven goals which depend on inference variables in HIR typeck and reprove them after writeback. This closes rust-lang/trait-system-refactor-initiative#127.
This was originally part of #144258 but I've moved it into a separate PR. While I believe we need to rely on region identity to fix the performance issues in some way, I don't know whether #144258 is the best approach to actually do so. Regardless of how we deal with the hangs however, this change is necessary and desirable regardless.
r? @compiler-errors or @BoxyUwU