@@ -9,7 +9,9 @@ use cache::ProvisionalCache;
9
9
use overflow:: OverflowData ;
10
10
use rustc_index:: IndexVec ;
11
11
use rustc_middle:: dep_graph:: DepKind ;
12
- use rustc_middle:: traits:: solve:: { CanonicalInput , Certainty , MaybeCause , QueryResult } ;
12
+ use rustc_middle:: traits:: solve:: {
13
+ CanonicalInput , Certainty , EvaluationCache , MaybeCause , QueryResult ,
14
+ } ;
13
15
use rustc_middle:: ty:: TyCtxt ;
14
16
use std:: { collections:: hash_map:: Entry , mem} ;
15
17
@@ -58,10 +60,10 @@ impl<'tcx> SearchGraph<'tcx> {
58
60
///
59
61
/// We could add another global cache for coherence instead,
60
62
/// but that's effort so let's only do it if necessary.
61
- pub ( super ) fn should_use_global_cache ( & self ) -> bool {
63
+ pub ( super ) fn global_cache ( & self , tcx : TyCtxt < ' tcx > ) -> & ' tcx EvaluationCache < ' tcx > {
62
64
match self . mode {
63
- SolverMode :: Normal => true ,
64
- SolverMode :: Coherence => false ,
65
+ SolverMode :: Normal => & tcx . new_solver_evaluation_cache ,
66
+ SolverMode :: Coherence => & tcx . new_solver_coherence_evaluation_cache ,
65
67
}
66
68
}
67
69
@@ -213,8 +215,8 @@ impl<'tcx> SearchGraph<'tcx> {
213
215
inspect : & mut ProofTreeBuilder < ' tcx > ,
214
216
mut loop_body : impl FnMut ( & mut Self , & mut ProofTreeBuilder < ' tcx > ) -> QueryResult < ' tcx > ,
215
217
) -> QueryResult < ' tcx > {
216
- if self . should_use_global_cache ( ) && inspect. use_global_cache ( ) {
217
- if let Some ( result) = tcx . new_solver_evaluation_cache . get ( & canonical_input, tcx) {
218
+ if inspect. use_global_cache ( ) {
219
+ if let Some ( result) = self . global_cache ( tcx ) . get ( & canonical_input, tcx) {
218
220
debug ! ( ?canonical_input, ?result, "cache hit" ) ;
219
221
inspect. cache_hit ( CacheHit :: Global ) ;
220
222
return result;
@@ -278,13 +280,10 @@ impl<'tcx> SearchGraph<'tcx> {
278
280
// dependencies, our non-root goal may no longer appear as child of the root goal.
279
281
//
280
282
// See https://github.com/rust-lang/rust/pull/108071 for some additional context.
281
- let can_cache = !self . overflow_data . did_overflow ( ) || self . stack . is_empty ( ) ;
282
- if self . should_use_global_cache ( ) && can_cache {
283
- tcx. new_solver_evaluation_cache . insert (
284
- current_goal. input ,
285
- dep_node,
286
- current_goal. response ,
287
- ) ;
283
+ let can_cache = inspect. use_global_cache ( )
284
+ && ( !self . overflow_data . did_overflow ( ) || self . stack . is_empty ( ) ) ;
285
+ if can_cache {
286
+ self . global_cache ( tcx) . insert ( current_goal. input , dep_node, current_goal. response )
288
287
}
289
288
}
290
289
0 commit comments