@@ -9,7 +9,9 @@ use cache::ProvisionalCache;
99use overflow:: OverflowData ;
1010use rustc_index:: IndexVec ;
1111use 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+ } ;
1315use rustc_middle:: ty:: TyCtxt ;
1416use std:: { collections:: hash_map:: Entry , mem} ;
1517
@@ -58,10 +60,10 @@ impl<'tcx> SearchGraph<'tcx> {
5860 ///
5961 /// We could add another global cache for coherence instead,
6062 /// 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 > {
6264 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 ,
6567 }
6668 }
6769
@@ -213,8 +215,8 @@ impl<'tcx> SearchGraph<'tcx> {
213215 inspect : & mut ProofTreeBuilder < ' tcx > ,
214216 mut loop_body : impl FnMut ( & mut Self , & mut ProofTreeBuilder < ' tcx > ) -> QueryResult < ' tcx > ,
215217 ) -> 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) {
218220 debug ! ( ?canonical_input, ?result, "cache hit" ) ;
219221 inspect. cache_hit ( CacheHit :: Global ) ;
220222 return result;
@@ -278,13 +280,10 @@ impl<'tcx> SearchGraph<'tcx> {
278280 // dependencies, our non-root goal may no longer appear as child of the root goal.
279281 //
280282 // 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 )
288287 }
289288 }
290289
0 commit comments