Skip to content

Commit 27a3b10

Browse files
committed
check for intercrate mode when accessing the cache
1 parent 6066037 commit 27a3b10

File tree

1 file changed

+22
-5
lines changed
  • compiler/rustc_trait_selection/src/solve/search_graph

1 file changed

+22
-5
lines changed

Diff for: compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ impl<'tcx> SearchGraph<'tcx> {
4747
self.mode
4848
}
4949

50+
/// We do not use the global cache during coherence.
51+
///
52+
/// The trait solver behavior is different for coherence
53+
/// so we would have to add the solver mode to the cache key.
54+
/// This is probably not worth it as trait solving during
55+
/// coherence tends to already be incredibly fast.
56+
///
57+
/// We could add another global cache for coherence instead,
58+
/// but that's effort so let's only do it if necessary.
59+
pub(super) fn should_use_global_cache(&self) -> bool {
60+
match self.mode {
61+
SolverMode::Normal => true,
62+
SolverMode::Coherence => false,
63+
}
64+
}
65+
5066
pub(super) fn is_empty(&self) -> bool {
5167
self.stack.is_empty() && self.provisional_cache.is_empty()
5268
}
@@ -191,8 +207,10 @@ impl<'tcx> SearchGraph<'tcx> {
191207
canonical_goal: CanonicalGoal<'tcx>,
192208
mut loop_body: impl FnMut(&mut Self) -> QueryResult<'tcx>,
193209
) -> QueryResult<'tcx> {
194-
if let Some(result) = tcx.new_solver_evaluation_cache.get(&canonical_goal, tcx) {
195-
return result;
210+
if self.should_use_global_cache() {
211+
if let Some(result) = tcx.new_solver_evaluation_cache.get(&canonical_goal, tcx) {
212+
return result;
213+
}
196214
}
197215

198216
match self.try_push_stack(tcx, canonical_goal) {
@@ -252,9 +270,8 @@ impl<'tcx> SearchGraph<'tcx> {
252270
// dependencies, our non-root goal may no longer appear as child of the root goal.
253271
//
254272
// See https://github.com/rust-lang/rust/pull/108071 for some additional context.
255-
let should_cache_globally = matches!(self.solver_mode(), SolverMode::Normal)
256-
&& (!self.overflow_data.did_overflow() || self.stack.is_empty());
257-
if should_cache_globally {
273+
let can_cache = !self.overflow_data.did_overflow() || self.stack.is_empty();
274+
if self.should_use_global_cache() && can_cache {
258275
tcx.new_solver_evaluation_cache.insert(
259276
current_goal.goal,
260277
dep_node,

0 commit comments

Comments
 (0)