diff options
| author | lcnr <rust@lcnr.de> | 2023-03-28 21:45:35 +0200 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2023-03-28 21:45:35 +0200 |
| commit | 27a3b10ed25b5e10491b39aba626ecd8d7f828f2 (patch) | |
| tree | 4851bfb2bc0b3eb0d2bab2ee52952dc498251e35 | |
| parent | 60660371efe59dfc99644e9d709a1b71e25ae2ac (diff) | |
| download | rust-27a3b10ed25b5e10491b39aba626ecd8d7f828f2.tar.gz rust-27a3b10ed25b5e10491b39aba626ecd8d7f828f2.zip | |
check for intercrate mode when accessing the cache
| -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, |
