@@ -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,73 @@ 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 , Debug ) ]
466
+ pub struct $name<' tcx> {
467
+ data: PhantomData <& ' tcx ( ) >
468
+ }
469
+
470
+ impl Default for $name<' _> {
471
+ fn default ( ) -> Self {
472
+ Self {
473
+ data: PhantomData ,
474
+ }
475
+ }
476
+ }
477
+ ) *
468
478
}
469
479
470
480
$( impl <' tcx> QueryConfig <QueryCtxt <' tcx>> for queries:: $name<' tcx> {
471
481
type Key = query_keys:: $name<' tcx>;
472
482
type Value = query_values:: $name<' tcx>;
473
- const NAME : & ' static str = stringify!( $name) ;
483
+
484
+ #[ inline( always) ]
485
+ fn name( self ) -> & ' static str {
486
+ stringify!( $name)
487
+ }
474
488
475
489
#[ inline]
476
- fn cache_on_disk( tcx: TyCtxt <' tcx>, key: & Self :: Key ) -> bool {
490
+ fn cache_on_disk( self , tcx: TyCtxt <' tcx>, key: & Self :: Key ) -> bool {
477
491
:: rustc_middle:: query:: cached:: $name( tcx, key)
478
492
}
479
493
480
494
type Cache = query_storage:: $name<' tcx>;
481
495
482
496
#[ inline( always) ]
483
- fn query_state<' a>( tcx: QueryCtxt <' tcx>) -> & ' a QueryState <Self :: Key , crate :: dep_graph:: DepKind >
497
+ fn query_state<' a>( self , tcx: QueryCtxt <' tcx>) -> & ' a QueryState <Self :: Key , crate :: dep_graph:: DepKind >
484
498
where QueryCtxt <' tcx>: ' a
485
499
{
486
500
& tcx. queries. $name
487
501
}
488
502
489
503
#[ inline( always) ]
490
- fn query_cache<' a>( tcx: QueryCtxt <' tcx>) -> & ' a Self :: Cache
504
+ fn query_cache<' a>( self , tcx: QueryCtxt <' tcx>) -> & ' a Self :: Cache
491
505
where ' tcx: ' a
492
506
{
493
507
& tcx. query_system. caches. $name
494
508
}
495
509
496
- fn execute_query( tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
510
+ fn execute_query( self , tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
497
511
tcx. $name( key)
498
512
}
499
513
500
514
#[ inline]
501
515
#[ allow( unused_variables) ]
502
- fn compute( qcx: QueryCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
516
+ fn compute( self , qcx: QueryCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
503
517
query_provided_to_value:: $name(
504
518
qcx. tcx,
505
519
get_provider!( [ $( $modifiers) * ] [ qcx, $name, key] ) ( qcx. tcx, key)
506
520
)
507
521
}
508
522
509
523
#[ inline]
510
- fn try_load_from_disk( _qcx: QueryCtxt <' tcx>, _key: & Self :: Key ) -> rustc_query_system:: query:: TryLoadFromDisk <QueryCtxt <' tcx>, Self > {
524
+ fn try_load_from_disk(
525
+ self ,
526
+ _qcx: QueryCtxt <' tcx>,
527
+ _key: & Self :: Key
528
+ ) -> rustc_query_system:: query:: TryLoadFromDisk <QueryCtxt <' tcx>, Self :: Value > {
511
529
should_ever_cache_on_disk!( [ $( $modifiers) * ] {
512
- if Self :: cache_on_disk ( _qcx. tcx, _key) {
530
+ if :: rustc_middle :: query :: cached :: $name ( _qcx. tcx, _key) {
513
531
Some ( |qcx: QueryCtxt <' tcx>, dep_node| {
514
532
let value = $crate:: plumbing:: try_load_from_disk:: <query_provided:: $name<' tcx>>(
515
533
qcx,
@@ -525,15 +543,40 @@ macro_rules! define_queries {
525
543
} )
526
544
}
527
545
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 ) * ] ) ;
546
+ # [ inline ( always ) ]
547
+ fn anon ( self ) -> bool {
548
+ is_anon !( [ $( $modifiers) * ] )
549
+ }
532
550
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) * ] ) ;
551
+ #[ inline( always) ]
552
+ fn eval_always( self ) -> bool {
553
+ is_eval_always!( [ $( $modifiers) * ] )
554
+ }
535
555
536
- const HASH_RESULT : rustc_query_system:: query:: HashResult <QueryCtxt <' tcx>, Self > = hash_result!( [ $( $modifiers) * ] ) ;
556
+ #[ inline( always) ]
557
+ fn depth_limit( self ) -> bool {
558
+ depth_limit!( [ $( $modifiers) * ] )
559
+ }
560
+
561
+ #[ inline( always) ]
562
+ fn feedable( self ) -> bool {
563
+ feedable!( [ $( $modifiers) * ] )
564
+ }
565
+
566
+ #[ inline( always) ]
567
+ fn dep_kind( self ) -> rustc_middle:: dep_graph:: DepKind {
568
+ dep_graph:: DepKind :: $name
569
+ }
570
+
571
+ #[ inline( always) ]
572
+ fn handle_cycle_error( self ) -> rustc_query_system:: HandleCycleError {
573
+ handle_cycle_error!( [ $( $modifiers) * ] )
574
+ }
575
+
576
+ #[ inline( always) ]
577
+ fn hash_result( self ) -> rustc_query_system:: query:: HashResult <Self :: Value > {
578
+ hash_result!( [ $( $modifiers) * ] )
579
+ }
537
580
} ) *
538
581
539
582
#[ allow( nonstandard_style) ]
@@ -649,8 +692,13 @@ macro_rules! define_queries {
649
692
string_cache,
650
693
)
651
694
} ,
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)
695
+ encode_query_results: expand_if_cached!( [ $( $modifiers) * ] , |qcx, encoder, query_result_index|
696
+ $crate:: on_disk_cache:: encode_query_results(
697
+ super :: queries:: $name:: default ( ) ,
698
+ qcx,
699
+ encoder,
700
+ query_result_index,
701
+ )
654
702
) ,
655
703
} } ) *
656
704
}
@@ -739,7 +787,13 @@ macro_rules! define_queries_struct {
739
787
mode: QueryMode ,
740
788
) -> Option <query_values:: $name<' tcx>> {
741
789
let qcx = QueryCtxt { tcx, queries: self } ;
742
- get_query:: <queries:: $name<' tcx>, _, rustc_middle:: dep_graph:: DepKind >( qcx, span, key, mode)
790
+ get_query(
791
+ queries:: $name:: default ( ) ,
792
+ qcx,
793
+ span,
794
+ key,
795
+ mode
796
+ )
743
797
} ) *
744
798
}
745
799
} ;
0 commit comments