@@ -3,14 +3,11 @@ use std::mem;
3
3
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
4
4
use rustc_index:: Idx ;
5
5
use 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 ;
11
7
use rustc_next_trait_solver:: solve:: { CanonicalInput , Certainty , QueryResult } ;
12
8
use rustc_session:: Limit ;
13
9
use rustc_type_ir:: inherent:: * ;
10
+ use rustc_type_ir:: InferCtxtLike ;
14
11
use rustc_type_ir:: Interner ;
15
12
16
13
use super :: inspect;
@@ -240,34 +237,26 @@ impl<I: Interner> SearchGraph<I> {
240
237
!entry. is_empty ( )
241
238
} ) ;
242
239
}
243
- }
244
240
245
- impl < ' tcx > SearchGraph < TyCtxt < ' tcx > > {
246
241
/// The trait solver behavior is different for coherence
247
242
/// so we use a separate cache. Alternatively we could use
248
243
/// a single cache and share it between coherence and ordinary
249
244
/// 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 )
255
247
}
256
248
257
249
/// Probably the most involved method of the whole solver.
258
250
///
259
251
/// Given some goal which is proven via the `prove_goal` closure, this
260
252
/// handles caching, overflow, and coinductive cycles.
261
- pub ( super ) fn with_new_goal (
253
+ pub ( super ) fn with_new_goal < Infcx : InferCtxtLike < Interner = I > > (
262
254
& 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 > {
271
260
self . check_invariants ( ) ;
272
261
// Check for overflow.
273
262
let Some ( available_depth) = Self :: allowed_depth_for_nested ( tcx, & self . stack ) else {
@@ -361,21 +350,20 @@ impl<'tcx> SearchGraph<TyCtxt<'tcx>> {
361
350
// not tracked by the cache key and from outside of this anon task, it
362
351
// must not be added to the global cache. Notably, this is the case for
363
352
// 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" ) ,
371
358
}
359
+ }
372
360
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
+ } ) ;
379
367
380
368
let proof_tree = inspect. finalize_canonical_goal_evaluation ( tcx) ;
381
369
@@ -423,16 +411,17 @@ impl<'tcx> SearchGraph<TyCtxt<'tcx>> {
423
411
/// Try to fetch a previously computed result from the global cache,
424
412
/// making sure to only do so if it would match the result of reevaluating
425
413
/// this goal.
426
- fn lookup_global_cache (
414
+ fn lookup_global_cache < Infcx : InferCtxtLike < Interner = I > > (
427
415
& mut self ,
428
- tcx : TyCtxt < ' tcx > ,
429
- input : CanonicalInput < TyCtxt < ' tcx > > ,
416
+ tcx : I ,
417
+ input : CanonicalInput < I > ,
430
418
available_depth : Limit ,
431
- inspect : & mut ProofTreeBuilder < InferCtxt < ' tcx > > ,
432
- ) -> Option < QueryResult < TyCtxt < ' tcx > > > {
419
+ inspect : & mut ProofTreeBuilder < Infcx > ,
420
+ ) -> Option < QueryResult < I > > {
433
421
let CacheData { result, proof_tree, additional_depth, encountered_overflow } = self
434
422
. 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 ) ?;
436
425
437
426
// If we're building a proof tree and the current cache entry does not
438
427
// contain a proof tree, we do not use the entry but instead recompute
@@ -465,21 +454,22 @@ enum StepResult<I: Interner> {
465
454
HasChanged ,
466
455
}
467
456
468
- impl < ' tcx > SearchGraph < TyCtxt < ' tcx > > {
457
+ impl < I : Interner > SearchGraph < I > {
469
458
/// When we encounter a coinductive cycle, we have to fetch the
470
459
/// result of that cycle while we are still computing it. Because
471
460
/// of this we continuously recompute the cycle until the result
472
461
/// of the previous iteration is equal to the final result, at which
473
462
/// point we are done.
474
- fn fixpoint_step_in_task < F > (
463
+ fn fixpoint_step_in_task < Infcx , F > (
475
464
& 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 > ,
479
468
prove_goal : & mut F ,
480
- ) -> StepResult < TyCtxt < ' tcx > >
469
+ ) -> StepResult < I >
481
470
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 > ,
483
473
{
484
474
let result = prove_goal ( self , inspect) ;
485
475
let stack_entry = self . pop_stack ( ) ;
@@ -533,15 +523,13 @@ impl<'tcx> SearchGraph<TyCtxt<'tcx>> {
533
523
}
534
524
535
525
fn response_no_constraints (
536
- tcx : TyCtxt < ' tcx > ,
537
- goal : CanonicalInput < TyCtxt < ' tcx > > ,
526
+ tcx : I ,
527
+ goal : CanonicalInput < I > ,
538
528
certainty : Certainty ,
539
- ) -> QueryResult < TyCtxt < ' tcx > > {
529
+ ) -> QueryResult < I > {
540
530
Ok ( super :: response_no_constraints_raw ( tcx, goal. max_universe , goal. variables , certainty) )
541
531
}
542
- }
543
532
544
- impl < I : Interner > SearchGraph < I > {
545
533
#[ allow( rustc:: potential_query_instability) ]
546
534
fn check_invariants ( & self ) {
547
535
if !cfg ! ( debug_assertions) {
0 commit comments