diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-29 06:02:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-29 06:02:43 +0200 |
| commit | 9d6c36e70bb75fc72b105327768062c1c8ada7be (patch) | |
| tree | a3acc70e2a165ef41efcb7eb145f7e9229bba465 | |
| parent | 09c139846b5456cf5c09af9ddd3013ab7171334c (diff) | |
| parent | 27a3b10ed25b5e10491b39aba626ecd8d7f828f2 (diff) | |
| download | rust-9d6c36e70bb75fc72b105327768062c1c8ada7be.tar.gz rust-9d6c36e70bb75fc72b105327768062c1c8ada7be.zip | |
Rollup merge of #109705 - lcnr:coherence-caching, r=compiler-errors
new solver: check for intercrate mode when accessing the cache r? ``@compiler-errors``
| -rw-r--r-- | compiler/rustc_trait_selection/src/solve/search_graph/mod.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs b/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs index 9773a3eacd6..d7ad730b4a3 100644 --- a/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs @@ -47,6 +47,22 @@ impl<'tcx> SearchGraph<'tcx> { self.mode } + /// We do not use the global cache during coherence. + /// + /// The trait solver behavior is different for coherence + /// so we would have to add the solver mode to the cache key. + /// This is probably not worth it as trait solving during + /// coherence tends to already be incredibly fast. + /// + /// We could add another global cache for coherence instead, + /// but that's effort so let's only do it if necessary. + pub(super) fn should_use_global_cache(&self) -> bool { + match self.mode { + SolverMode::Normal => true, + SolverMode::Coherence => false, + } + } + pub(super) fn is_empty(&self) -> bool { self.stack.is_empty() && self.provisional_cache.is_empty() } @@ -191,8 +207,10 @@ impl<'tcx> SearchGraph<'tcx> { canonical_goal: CanonicalGoal<'tcx>, mut loop_body: impl FnMut(&mut Self) -> QueryResult<'tcx>, ) -> QueryResult<'tcx> { - if let Some(result) = tcx.new_solver_evaluation_cache.get(&canonical_goal, tcx) { - return result; + if self.should_use_global_cache() { + if let Some(result) = tcx.new_solver_evaluation_cache.get(&canonical_goal, tcx) { + return result; + } } match self.try_push_stack(tcx, canonical_goal) { @@ -252,9 +270,8 @@ impl<'tcx> SearchGraph<'tcx> { // dependencies, our non-root goal may no longer appear as child of the root goal. // // See https://github.com/rust-lang/rust/pull/108071 for some additional context. - let should_cache_globally = matches!(self.solver_mode(), SolverMode::Normal) - && (!self.overflow_data.did_overflow() || self.stack.is_empty()); - if should_cache_globally { + let can_cache = !self.overflow_data.did_overflow() || self.stack.is_empty(); + if self.should_use_global_cache() && can_cache { tcx.new_solver_evaluation_cache.insert( current_goal.goal, dep_node, |
