@@ -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,65 @@ 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 , Default ) ]
466+ pub struct $name<' tcx> {
467+ data: PhantomData <& ' tcx ( ) >
468+ }
469+ ) *
468470 }
469471
470472 $( impl <' tcx> QueryConfig <QueryCtxt <' tcx>> for queries:: $name<' tcx> {
471473 type Key = query_keys:: $name<' tcx>;
472474 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+ }
474480
475481 #[ 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 {
477483 :: rustc_middle:: query:: cached:: $name( tcx, key)
478484 }
479485
480486 type Cache = query_storage:: $name<' tcx>;
481487
482488 #[ 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 >
484490 where QueryCtxt <' tcx>: ' a
485491 {
486492 & tcx. queries. $name
487493 }
488494
489495 #[ 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
491497 where ' tcx: ' a
492498 {
493499 & tcx. query_system. caches. $name
494500 }
495501
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 {
497503 tcx. $name( key)
498504 }
499505
500506 #[ inline]
501507 #[ 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 {
503509 query_provided_to_value:: $name(
504510 qcx. tcx,
505511 get_provider!( [ $( $modifiers) * ] [ qcx, $name, key] ) ( qcx. tcx, key)
506512 )
507513 }
508514
509515 #[ 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 > {
511521 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) {
513523 Some ( |qcx: QueryCtxt <' tcx>, dep_node| {
514524 let value = $crate:: plumbing:: try_load_from_disk:: <query_provided:: $name<' tcx>>(
515525 qcx,
@@ -525,15 +535,40 @@ macro_rules! define_queries {
525535 } )
526536 }
527537
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+ }
532557
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+ }
535562
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+ }
537572 } ) *
538573
539574 #[ allow( nonstandard_style) ]
@@ -649,8 +684,13 @@ macro_rules! define_queries {
649684 string_cache,
650685 )
651686 } ,
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+ )
654694 ) ,
655695 } } ) *
656696 }
@@ -739,7 +779,13 @@ macro_rules! define_queries_struct {
739779 mode: QueryMode ,
740780 ) -> Option <query_values:: $name<' tcx>> {
741781 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+ )
743789 } ) *
744790 }
745791 } ;
0 commit comments