@@ -19,7 +19,7 @@ use rustc_query_system::ich::StableHashingContext;
19
19
use rustc_query_system:: query:: {
20
20
force_query, QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects , QueryStackFrame ,
21
21
} ;
22
- use rustc_query_system:: { LayoutOfDepth , QueryOverflow , Value } ;
22
+ use rustc_query_system:: { LayoutOfDepth , QueryOverflow } ;
23
23
use rustc_serialize:: Decodable ;
24
24
use rustc_session:: Limit ;
25
25
use rustc_span:: def_id:: LOCAL_CRATE ;
@@ -350,18 +350,17 @@ pub(crate) fn create_query_frame<
350
350
QueryStackFrame :: new ( description, span, def_id, def_kind, kind, ty_adt_id, hash)
351
351
}
352
352
353
- fn try_load_from_on_disk_cache < ' tcx , Q > ( tcx : TyCtxt < ' tcx > , dep_node : DepNode )
353
+ fn try_load_from_on_disk_cache < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode )
354
354
where
355
355
Q : QueryConfig < QueryCtxt < ' tcx > > ,
356
- Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
357
356
{
358
357
debug_assert ! ( tcx. dep_graph. is_green( & dep_node) ) ;
359
358
360
359
let key = Q :: Key :: recover ( tcx, & dep_node) . unwrap_or_else ( || {
361
360
panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
362
361
} ) ;
363
- if Q :: cache_on_disk ( tcx, & key) {
364
- let _ = Q :: execute_query ( tcx, key) ;
362
+ if query . cache_on_disk ( tcx, & key) {
363
+ let _ = query . execute_query ( tcx, key) ;
365
364
}
366
365
}
367
366
@@ -375,11 +374,9 @@ where
375
374
tcx. on_disk_cache ( ) . as_ref ( ) ?. try_load_query_result ( * tcx, id)
376
375
}
377
376
378
- fn force_from_dep_node < ' tcx , Q > ( tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
377
+ fn force_from_dep_node < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
379
378
where
380
379
Q : QueryConfig < QueryCtxt < ' tcx > > ,
381
- Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
382
- Q :: Value : Value < TyCtxt < ' tcx > , DepKind > ,
383
380
{
384
381
// We must avoid ever having to call `force_from_dep_node()` for a
385
382
// `DepNode::codegen_unit`:
@@ -403,7 +400,7 @@ where
403
400
#[ cfg( debug_assertions) ]
404
401
let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered ( ) ;
405
402
let tcx = QueryCtxt :: from_tcx ( tcx) ;
406
- force_query :: < Q , _ , DepKind > ( tcx, key, dep_node) ;
403
+ force_query ( query , tcx, key, dep_node) ;
407
404
true
408
405
} else {
409
406
false
@@ -412,7 +409,7 @@ where
412
409
413
410
pub ( crate ) fn query_callback < ' tcx , Q > ( is_anon : bool , is_eval_always : bool ) -> DepKindStruct < ' tcx >
414
411
where
415
- Q : QueryConfig < QueryCtxt < ' tcx > > ,
412
+ Q : QueryConfig < QueryCtxt < ' tcx > > + Default ,
416
413
Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
417
414
{
418
415
let fingerprint_style = Q :: Key :: fingerprint_style ( ) ;
@@ -431,8 +428,10 @@ where
431
428
is_anon,
432
429
is_eval_always,
433
430
fingerprint_style,
434
- force_from_dep_node : Some ( force_from_dep_node :: < Q > ) ,
435
- try_load_from_on_disk_cache : Some ( try_load_from_on_disk_cache :: < Q > ) ,
431
+ force_from_dep_node : Some ( |tcx, dep_node| force_from_dep_node ( Q :: default ( ) , tcx, dep_node) ) ,
432
+ try_load_from_on_disk_cache : Some ( |tcx, dep_node| {
433
+ try_load_from_on_disk_cache ( Q :: default ( ) , tcx, dep_node)
434
+ } ) ,
436
435
}
437
436
}
438
437
@@ -462,54 +461,65 @@ macro_rules! define_queries {
462
461
mod queries {
463
462
use std:: marker:: PhantomData ;
464
463
465
- $( pub struct $name<' tcx> {
466
- data: PhantomData <& ' tcx ( ) >
467
- } ) *
464
+ $(
465
+ #[ derive( Copy , Clone , Default ) ]
466
+ pub struct $name<' tcx> {
467
+ data: PhantomData <& ' tcx ( ) >
468
+ }
469
+ ) *
468
470
}
469
471
470
472
$( impl <' tcx> QueryConfig <QueryCtxt <' tcx>> for queries:: $name<' tcx> {
471
473
type Key = query_keys:: $name<' tcx>;
472
474
type Value = query_values:: $name<' tcx>;
473
- const NAME : & ' static str = stringify!( $name) ;
475
+
476
+ #[ inline( always) ]
477
+ fn name( self ) -> & ' static str {
478
+ stringify!( $name)
479
+ }
474
480
475
481
#[ inline]
476
- fn cache_on_disk( tcx: TyCtxt <' tcx>, key: & Self :: Key ) -> bool {
482
+ fn cache_on_disk( self , tcx: TyCtxt <' tcx>, key: & Self :: Key ) -> bool {
477
483
:: rustc_middle:: query:: cached:: $name( tcx, key)
478
484
}
479
485
480
486
type Cache = query_storage:: $name<' tcx>;
481
487
482
488
#[ inline( always) ]
483
- fn query_state<' a>( tcx: QueryCtxt <' tcx>) -> & ' a QueryState <Self :: Key , crate :: dep_graph:: DepKind >
489
+ fn query_state<' a>( self , tcx: QueryCtxt <' tcx>) -> & ' a QueryState <Self :: Key , crate :: dep_graph:: DepKind >
484
490
where QueryCtxt <' tcx>: ' a
485
491
{
486
492
& tcx. queries. $name
487
493
}
488
494
489
495
#[ inline( always) ]
490
- fn query_cache<' a>( tcx: QueryCtxt <' tcx>) -> & ' a Self :: Cache
496
+ fn query_cache<' a>( self , tcx: QueryCtxt <' tcx>) -> & ' a Self :: Cache
491
497
where ' tcx: ' a
492
498
{
493
499
& tcx. query_system. caches. $name
494
500
}
495
501
496
- fn execute_query( tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
502
+ fn execute_query( self , tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
497
503
tcx. $name( key)
498
504
}
499
505
500
506
#[ inline]
501
507
#[ allow( unused_variables) ]
502
- fn compute( qcx: QueryCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
508
+ fn compute( self , qcx: QueryCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
503
509
query_provided_to_value:: $name(
504
510
qcx. tcx,
505
511
get_provider!( [ $( $modifiers) * ] [ qcx, $name, key] ) ( qcx. tcx, key)
506
512
)
507
513
}
508
514
509
515
#[ inline]
510
- fn try_load_from_disk( _qcx: QueryCtxt <' tcx>, _key: & Self :: Key ) -> rustc_query_system:: query:: TryLoadFromDisk <QueryCtxt <' tcx>, Self > {
516
+ fn try_load_from_disk(
517
+ self ,
518
+ _qcx: QueryCtxt <' tcx>,
519
+ _key: & Self :: Key
520
+ ) -> rustc_query_system:: query:: TryLoadFromDisk <QueryCtxt <' tcx>, Self :: Value > {
511
521
should_ever_cache_on_disk!( [ $( $modifiers) * ] {
512
- if Self :: cache_on_disk ( _qcx. tcx, _key) {
522
+ if :: rustc_middle :: query :: cached :: $name ( _qcx. tcx, _key) {
513
523
Some ( |qcx: QueryCtxt <' tcx>, dep_node| {
514
524
let value = $crate:: plumbing:: try_load_from_disk:: <query_provided:: $name<' tcx>>(
515
525
qcx,
@@ -525,15 +535,40 @@ macro_rules! define_queries {
525
535
} )
526
536
}
527
537
528
- const ANON : bool = is_anon!( [ $( $modifiers) * ] ) ;
529
- const EVAL_ALWAYS : bool = is_eval_always!( [ $( $modifiers) * ] ) ;
530
- const DEPTH_LIMIT : bool = depth_limit!( [ $( $modifiers) * ] ) ;
531
- const FEEDABLE : bool = feedable!( [ $( $modifiers) * ] ) ;
538
+ #[ inline( always) ]
539
+ fn anon( self ) -> bool {
540
+ is_anon!( [ $( $modifiers) * ] )
541
+ }
542
+
543
+ #[ inline( always) ]
544
+ fn eval_always( self ) -> bool {
545
+ is_eval_always!( [ $( $modifiers) * ] )
546
+ }
547
+
548
+ #[ inline( always) ]
549
+ fn depth_limit( self ) -> bool {
550
+ depth_limit!( [ $( $modifiers) * ] )
551
+ }
552
+
553
+ #[ inline( always) ]
554
+ fn feedable( self ) -> bool {
555
+ feedable!( [ $( $modifiers) * ] )
556
+ }
532
557
533
- const DEP_KIND : rustc_middle:: dep_graph:: DepKind = dep_graph:: DepKind :: $name;
534
- const HANDLE_CYCLE_ERROR : rustc_query_system:: HandleCycleError = handle_cycle_error!( [ $( $modifiers) * ] ) ;
558
+ #[ inline( always) ]
559
+ fn dep_kind( self ) -> rustc_middle:: dep_graph:: DepKind {
560
+ dep_graph:: DepKind :: $name
561
+ }
535
562
536
- const HASH_RESULT : rustc_query_system:: query:: HashResult <QueryCtxt <' tcx>, Self > = hash_result!( [ $( $modifiers) * ] ) ;
563
+ #[ inline( always) ]
564
+ fn handle_cycle_error( self ) -> rustc_query_system:: HandleCycleError {
565
+ handle_cycle_error!( [ $( $modifiers) * ] )
566
+ }
567
+
568
+ #[ inline( always) ]
569
+ fn hash_result( self ) -> rustc_query_system:: query:: HashResult <Self :: Value > {
570
+ hash_result!( [ $( $modifiers) * ] )
571
+ }
537
572
} ) *
538
573
539
574
#[ allow( nonstandard_style) ]
@@ -649,8 +684,13 @@ macro_rules! define_queries {
649
684
string_cache,
650
685
)
651
686
} ,
652
- encode_query_results: expand_if_cached!( [ $( $modifiers) * ] , |tcx, encoder, query_result_index|
653
- $crate:: on_disk_cache:: encode_query_results:: <_, super :: queries:: $name<' _>>( tcx, encoder, query_result_index)
687
+ encode_query_results: expand_if_cached!( [ $( $modifiers) * ] , |qcx, encoder, query_result_index|
688
+ $crate:: on_disk_cache:: encode_query_results(
689
+ super :: queries:: $name:: default ( ) ,
690
+ qcx,
691
+ encoder,
692
+ query_result_index,
693
+ )
654
694
) ,
655
695
} } ) *
656
696
}
@@ -739,7 +779,13 @@ macro_rules! define_queries_struct {
739
779
mode: QueryMode ,
740
780
) -> Option <query_values:: $name<' tcx>> {
741
781
let qcx = QueryCtxt { tcx, queries: self } ;
742
- get_query:: <queries:: $name<' tcx>, _, rustc_middle:: dep_graph:: DepKind >( qcx, span, key, mode)
782
+ get_query(
783
+ queries:: $name:: default ( ) ,
784
+ qcx,
785
+ span,
786
+ key,
787
+ mode
788
+ )
743
789
} ) *
744
790
}
745
791
} ;
0 commit comments