@@ -3,14 +3,11 @@ use std::mem;
33use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
44use rustc_index:: Idx ;
55use rustc_index:: IndexVec ;
6- use rustc_infer:: infer:: InferCtxt ;
7- use rustc_middle:: dep_graph:: dep_kinds;
8- use rustc_middle:: traits:: solve:: CacheData ;
9- use rustc_middle:: traits:: solve:: EvaluationCache ;
10- use rustc_middle:: ty:: TyCtxt ;
6+ use rustc_next_trait_solver:: solve:: CacheData ;
117use rustc_next_trait_solver:: solve:: { CanonicalInput , Certainty , QueryResult } ;
128use rustc_session:: Limit ;
139use rustc_type_ir:: inherent:: * ;
10+ use rustc_type_ir:: InferCtxtLike ;
1411use rustc_type_ir:: Interner ;
1512
1613use super :: inspect;
@@ -240,34 +237,26 @@ impl<I: Interner> SearchGraph<I> {
240237 !entry. is_empty ( )
241238 } ) ;
242239 }
243- }
244240
245- impl < ' tcx > SearchGraph < TyCtxt < ' tcx > > {
246241 /// The trait solver behavior is different for coherence
247242 /// so we use a separate cache. Alternatively we could use
248243 /// a single cache and share it between coherence and ordinary
249244 /// trait solving.
250- pub ( super ) fn global_cache ( & self , tcx : TyCtxt < ' tcx > ) -> & ' tcx EvaluationCache < ' tcx > {
251- match self . mode {
252- SolverMode :: Normal => & tcx. new_solver_evaluation_cache ,
253- SolverMode :: Coherence => & tcx. new_solver_coherence_evaluation_cache ,
254- }
245+ pub ( super ) fn global_cache ( & self , tcx : I ) -> I :: EvaluationCache {
246+ tcx. evaluation_cache ( self . mode )
255247 }
256248
257249 /// Probably the most involved method of the whole solver.
258250 ///
259251 /// Given some goal which is proven via the `prove_goal` closure, this
260252 /// handles caching, overflow, and coinductive cycles.
261- pub ( super ) fn with_new_goal (
253+ pub ( super ) fn with_new_goal < Infcx : InferCtxtLike < Interner = I > > (
262254 & mut self ,
263- tcx : TyCtxt < ' tcx > ,
264- input : CanonicalInput < TyCtxt < ' tcx > > ,
265- inspect : & mut ProofTreeBuilder < InferCtxt < ' tcx > > ,
266- mut prove_goal : impl FnMut (
267- & mut Self ,
268- & mut ProofTreeBuilder < InferCtxt < ' tcx > > ,
269- ) -> QueryResult < TyCtxt < ' tcx > > ,
270- ) -> QueryResult < TyCtxt < ' tcx > > {
255+ tcx : I ,
256+ input : CanonicalInput < I > ,
257+ inspect : & mut ProofTreeBuilder < Infcx > ,
258+ mut prove_goal : impl FnMut ( & mut Self , & mut ProofTreeBuilder < Infcx > ) -> QueryResult < I > ,
259+ ) -> QueryResult < I > {
271260 self . check_invariants ( ) ;
272261 // Check for overflow.
273262 let Some ( available_depth) = Self :: allowed_depth_for_nested ( tcx, & self . stack ) else {
@@ -361,21 +350,20 @@ impl<'tcx> SearchGraph<TyCtxt<'tcx>> {
361350 // not tracked by the cache key and from outside of this anon task, it
362351 // must not be added to the global cache. Notably, this is the case for
363352 // trait solver cycles participants.
364- let ( ( final_entry, result) , dep_node) =
365- tcx. dep_graph . with_anon_task ( tcx, dep_kinds:: TraitSelect , || {
366- for _ in 0 ..FIXPOINT_STEP_LIMIT {
367- match self . fixpoint_step_in_task ( tcx, input, inspect, & mut prove_goal) {
368- StepResult :: Done ( final_entry, result) => return ( final_entry, result) ,
369- StepResult :: HasChanged => debug ! ( "fixpoint changed provisional results" ) ,
370- }
353+ let ( ( final_entry, result) , dep_node) = tcx. with_cached_task ( || {
354+ for _ in 0 ..FIXPOINT_STEP_LIMIT {
355+ match self . fixpoint_step_in_task ( tcx, input, inspect, & mut prove_goal) {
356+ StepResult :: Done ( final_entry, result) => return ( final_entry, result) ,
357+ StepResult :: HasChanged => debug ! ( "fixpoint changed provisional results" ) ,
371358 }
359+ }
372360
373- debug ! ( "canonical cycle overflow" ) ;
374- let current_entry = self . pop_stack ( ) ;
375- debug_assert ! ( current_entry. has_been_used. is_empty( ) ) ;
376- let result = Self :: response_no_constraints ( tcx, input, Certainty :: overflow ( false ) ) ;
377- ( current_entry, result)
378- } ) ;
361+ debug ! ( "canonical cycle overflow" ) ;
362+ let current_entry = self . pop_stack ( ) ;
363+ debug_assert ! ( current_entry. has_been_used. is_empty( ) ) ;
364+ let result = Self :: response_no_constraints ( tcx, input, Certainty :: overflow ( false ) ) ;
365+ ( current_entry, result)
366+ } ) ;
379367
380368 let proof_tree = inspect. finalize_canonical_goal_evaluation ( tcx) ;
381369
@@ -423,16 +411,17 @@ impl<'tcx> SearchGraph<TyCtxt<'tcx>> {
423411 /// Try to fetch a previously computed result from the global cache,
424412 /// making sure to only do so if it would match the result of reevaluating
425413 /// this goal.
426- fn lookup_global_cache (
414+ fn lookup_global_cache < Infcx : InferCtxtLike < Interner = I > > (
427415 & mut self ,
428- tcx : TyCtxt < ' tcx > ,
429- input : CanonicalInput < TyCtxt < ' tcx > > ,
416+ tcx : I ,
417+ input : CanonicalInput < I > ,
430418 available_depth : Limit ,
431- inspect : & mut ProofTreeBuilder < InferCtxt < ' tcx > > ,
432- ) -> Option < QueryResult < TyCtxt < ' tcx > > > {
419+ inspect : & mut ProofTreeBuilder < Infcx > ,
420+ ) -> Option < QueryResult < I > > {
433421 let CacheData { result, proof_tree, additional_depth, encountered_overflow } = self
434422 . global_cache ( tcx)
435- . get ( tcx, input, self . stack . iter ( ) . map ( |e| e. input ) , available_depth) ?;
423+ // TODO: Awkward `Limit -> usize -> Limit`.
424+ . get ( tcx, input, self . stack . iter ( ) . map ( |e| e. input ) , available_depth. 0 ) ?;
436425
437426 // If we're building a proof tree and the current cache entry does not
438427 // contain a proof tree, we do not use the entry but instead recompute
@@ -465,21 +454,22 @@ enum StepResult<I: Interner> {
465454 HasChanged ,
466455}
467456
468- impl < ' tcx > SearchGraph < TyCtxt < ' tcx > > {
457+ impl < I : Interner > SearchGraph < I > {
469458 /// When we encounter a coinductive cycle, we have to fetch the
470459 /// result of that cycle while we are still computing it. Because
471460 /// of this we continuously recompute the cycle until the result
472461 /// of the previous iteration is equal to the final result, at which
473462 /// point we are done.
474- fn fixpoint_step_in_task < F > (
463+ fn fixpoint_step_in_task < Infcx , F > (
475464 & mut self ,
476- tcx : TyCtxt < ' tcx > ,
477- input : CanonicalInput < TyCtxt < ' tcx > > ,
478- inspect : & mut ProofTreeBuilder < InferCtxt < ' tcx > > ,
465+ tcx : I ,
466+ input : CanonicalInput < I > ,
467+ inspect : & mut ProofTreeBuilder < Infcx > ,
479468 prove_goal : & mut F ,
480- ) -> StepResult < TyCtxt < ' tcx > >
469+ ) -> StepResult < I >
481470 where
482- F : FnMut ( & mut Self , & mut ProofTreeBuilder < InferCtxt < ' tcx > > ) -> QueryResult < TyCtxt < ' tcx > > ,
471+ Infcx : InferCtxtLike < Interner = I > ,
472+ F : FnMut ( & mut Self , & mut ProofTreeBuilder < Infcx > ) -> QueryResult < I > ,
483473 {
484474 let result = prove_goal ( self , inspect) ;
485475 let stack_entry = self . pop_stack ( ) ;
@@ -533,15 +523,13 @@ impl<'tcx> SearchGraph<TyCtxt<'tcx>> {
533523 }
534524
535525 fn response_no_constraints (
536- tcx : TyCtxt < ' tcx > ,
537- goal : CanonicalInput < TyCtxt < ' tcx > > ,
526+ tcx : I ,
527+ goal : CanonicalInput < I > ,
538528 certainty : Certainty ,
539- ) -> QueryResult < TyCtxt < ' tcx > > {
529+ ) -> QueryResult < I > {
540530 Ok ( super :: response_no_constraints_raw ( tcx, goal. max_universe , goal. variables , certainty) )
541531 }
542- }
543532
544- impl < I : Interner > SearchGraph < I > {
545533 #[ allow( rustc:: potential_query_instability) ]
546534 fn check_invariants ( & self ) {
547535 if !cfg ! ( debug_assertions) {
0 commit comments