@@ -19,7 +19,7 @@ use rustc_query_system::ich::StableHashingContext;
1919use rustc_query_system:: query:: {
2020 force_query, QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects , QueryStackFrame ,
2121} ;
22- use rustc_query_system:: { LayoutOfDepth , QueryOverflow , Value } ;
22+ use rustc_query_system:: { LayoutOfDepth , QueryOverflow } ;
2323use rustc_serialize:: Decodable ;
2424use rustc_session:: Limit ;
2525use rustc_span:: def_id:: LOCAL_CRATE ;
@@ -350,18 +350,17 @@ pub(crate) fn create_query_frame<
350350 QueryStackFrame :: new ( description, span, def_id, def_kind, kind, ty_adt_id, hash)
351351}
352352
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 )
354354where
355355 Q : QueryConfig < QueryCtxt < ' tcx > > ,
356- Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
357356{
358357 debug_assert ! ( tcx. dep_graph. is_green( & dep_node) ) ;
359358
360359 let key = Q :: Key :: recover ( tcx, & dep_node) . unwrap_or_else ( || {
361360 panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
362361 } ) ;
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) ;
365364 }
366365}
367366
@@ -375,11 +374,9 @@ where
375374 tcx. on_disk_cache ( ) . as_ref ( ) ?. try_load_query_result ( * tcx, id)
376375}
377376
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
379378where
380379 Q : QueryConfig < QueryCtxt < ' tcx > > ,
381- Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
382- Q :: Value : Value < TyCtxt < ' tcx > , DepKind > ,
383380{
384381 // We must avoid ever having to call `force_from_dep_node()` for a
385382 // `DepNode::codegen_unit`:
@@ -403,7 +400,7 @@ where
403400 #[ cfg( debug_assertions) ]
404401 let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered ( ) ;
405402 let tcx = QueryCtxt :: from_tcx ( tcx) ;
406- force_query :: < Q , _ , DepKind > ( tcx, key, dep_node) ;
403+ force_query ( query , tcx, key, dep_node) ;
407404 true
408405 } else {
409406 false
@@ -412,7 +409,7 @@ where
412409
413410pub ( crate ) fn query_callback < ' tcx , Q > ( is_anon : bool , is_eval_always : bool ) -> DepKindStruct < ' tcx >
414411where
415- Q : QueryConfig < QueryCtxt < ' tcx > > ,
412+ Q : QueryConfig < QueryCtxt < ' tcx > > + Default ,
416413 Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
417414{
418415 let fingerprint_style = Q :: Key :: fingerprint_style ( ) ;
@@ -431,8 +428,10 @@ where
431428 is_anon,
432429 is_eval_always,
433430 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+ } ) ,
436435 }
437436}
438437
@@ -462,54 +461,73 @@ macro_rules! define_queries {
462461 mod queries {
463462 use std:: marker:: PhantomData ;
464463
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+ ) *
468478 }
469479
470480 $( impl <' tcx> QueryConfig <QueryCtxt <' tcx>> for queries:: $name<' tcx> {
471481 type Key = query_keys:: $name<' tcx>;
472482 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+ }
474488
475489 #[ 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 {
477491 :: rustc_middle:: query:: cached:: $name( tcx, key)
478492 }
479493
480494 type Cache = query_storage:: $name<' tcx>;
481495
482496 #[ 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 >
484498 where QueryCtxt <' tcx>: ' a
485499 {
486500 & tcx. queries. $name
487501 }
488502
489503 #[ 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
491505 where ' tcx: ' a
492506 {
493507 & tcx. query_system. caches. $name
494508 }
495509
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 {
497511 tcx. $name( key)
498512 }
499513
500514 #[ inline]
501515 #[ 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 {
503517 query_provided_to_value:: $name(
504518 qcx. tcx,
505519 get_provider!( [ $( $modifiers) * ] [ qcx, $name, key] ) ( qcx. tcx, key)
506520 )
507521 }
508522
509523 #[ 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 > {
511529 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) {
513531 Some ( |qcx: QueryCtxt <' tcx>, dep_node| {
514532 let value = $crate:: plumbing:: try_load_from_disk:: <query_provided:: $name<' tcx>>(
515533 qcx,
@@ -525,15 +543,40 @@ macro_rules! define_queries {
525543 } )
526544 }
527545
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+ }
532550
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+ }
535555
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+ }
537580 } ) *
538581
539582 #[ allow( nonstandard_style) ]
@@ -649,8 +692,13 @@ macro_rules! define_queries {
649692 string_cache,
650693 )
651694 } ,
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+ )
654702 ) ,
655703 } } ) *
656704 }
@@ -739,7 +787,13 @@ macro_rules! define_queries_struct {
739787 mode: QueryMode ,
740788 ) -> Option <query_values:: $name<' tcx>> {
741789 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+ )
743797 } ) *
744798 }
745799 } ;
0 commit comments