@@ -47,6 +47,22 @@ impl<'tcx> SearchGraph<'tcx> {
47
47
self . mode
48
48
}
49
49
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
+
50
66
pub ( super ) fn is_empty ( & self ) -> bool {
51
67
self . stack . is_empty ( ) && self . provisional_cache . is_empty ( )
52
68
}
@@ -191,8 +207,10 @@ impl<'tcx> SearchGraph<'tcx> {
191
207
canonical_goal : CanonicalGoal < ' tcx > ,
192
208
mut loop_body : impl FnMut ( & mut Self ) -> QueryResult < ' tcx > ,
193
209
) -> 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
+ }
196
214
}
197
215
198
216
match self . try_push_stack ( tcx, canonical_goal) {
@@ -252,9 +270,8 @@ impl<'tcx> SearchGraph<'tcx> {
252
270
// dependencies, our non-root goal may no longer appear as child of the root goal.
253
271
//
254
272
// 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 {
258
275
tcx. new_solver_evaluation_cache . insert (
259
276
current_goal. goal ,
260
277
dep_node,
0 commit comments