22//! generate the actual methods on tcx which find and execute the provider,
33//! manage the caches, and so forth.
44
5- use crate :: rustc_middle:: dep_graph:: DepContext ;
6- use crate :: rustc_middle:: ty:: TyEncoder ;
75use crate :: QueryConfigRestored ;
86use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
97use rustc_data_structures:: sync:: Lock ;
108use rustc_errors:: Diagnostic ;
119
12- use rustc_index:: Idx ;
1310use rustc_middle:: dep_graph:: dep_kinds;
1411use rustc_middle:: dep_graph:: {
1512 self , DepKind , DepKindStruct , DepNode , DepNodeIndex , SerializedDepNodeIndex ,
1613} ;
17- use rustc_middle:: query:: on_disk_cache:: AbsoluteBytePos ;
18- use rustc_middle:: query:: on_disk_cache:: { CacheDecoder , CacheEncoder , EncodedDepNodeIndex } ;
1914use rustc_middle:: query:: Key ;
2015use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
2116use rustc_middle:: ty:: { self , print:: with_no_queries, TyCtxt } ;
2217use rustc_query_system:: dep_graph:: { DepNodeParams , HasDepContext } ;
2318use rustc_query_system:: ich:: StableHashingContext ;
2419use rustc_query_system:: query:: {
25- force_query, QueryCache , QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects ,
26- QueryStackFrame ,
20+ force_query, QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects , QueryStackFrame ,
2721} ;
2822use rustc_query_system:: { LayoutOfDepth , QueryOverflow } ;
29- use rustc_serialize:: Decodable ;
30- use rustc_serialize:: Encodable ;
3123use rustc_session:: Limit ;
3224use rustc_span:: def_id:: LOCAL_CRATE ;
3325use std:: num:: NonZeroU64 ;
@@ -180,16 +172,6 @@ pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepN
180172 tcx. dep_graph . try_mark_green ( QueryCtxt :: new ( tcx) , dep_node) . is_some ( )
181173}
182174
183- pub ( super ) fn encode_all_query_results < ' tcx > (
184- tcx : TyCtxt < ' tcx > ,
185- encoder : & mut CacheEncoder < ' _ , ' tcx > ,
186- query_result_index : & mut EncodedDepNodeIndex ,
187- ) {
188- for encode in super :: ENCODE_QUERY_RESULTS . iter ( ) . copied ( ) . flatten ( ) {
189- encode ( tcx, encoder, query_result_index) ;
190- }
191- }
192-
193175macro_rules! handle_cycle_error {
194176 ( [ ] ) => { {
195177 rustc_query_system:: HandleCycleError :: Error
@@ -254,10 +236,10 @@ macro_rules! feedable {
254236}
255237
256238macro_rules! hash_result {
257- ( [ ] [ $V : ty ] ) => { {
258- Some ( |hcx , result| dep_graph :: hash_result ( hcx , & restore :: <$V> ( * result ) ) )
239+ ( [ ] [ $f : path ] ) => { {
240+ Some ( $f )
259241 } } ;
260- ( [ ( no_hash) $( $rest: tt) * ] [ $V : ty ] ) => { {
242+ ( [ ( no_hash) $( $rest: tt) * ] $args : tt ) => { {
261243 None
262244 } } ;
263245 ( [ $other: tt $( $modifiers: tt) * ] [ $( $args: tt) * ] ) => {
@@ -341,33 +323,6 @@ pub(crate) fn create_query_frame<
341323 QueryStackFrame :: new ( description, span, def_id, def_kind, kind, ty_adt_id, hash)
342324}
343325
344- pub ( crate ) fn encode_query_results < ' a , ' tcx , Q > (
345- query : Q :: Config ,
346- qcx : QueryCtxt < ' tcx > ,
347- encoder : & mut CacheEncoder < ' a , ' tcx > ,
348- query_result_index : & mut EncodedDepNodeIndex ,
349- ) where
350- Q : super :: QueryConfigRestored < ' tcx > ,
351- Q :: RestoredValue : Encodable < CacheEncoder < ' a , ' tcx > > ,
352- {
353- let _timer = qcx. profiler ( ) . generic_activity_with_arg ( "encode_query_results_for" , query. name ( ) ) ;
354-
355- assert ! ( query. query_state( qcx) . all_inactive( ) ) ;
356- let cache = query. query_cache ( qcx) ;
357- cache. iter ( & mut |key, value, dep_node| {
358- if query. cache_on_disk ( qcx. tcx , & key) {
359- let dep_node = SerializedDepNodeIndex :: new ( dep_node. index ( ) ) ;
360-
361- // Record position of the cache entry.
362- query_result_index. push ( ( dep_node, AbsoluteBytePos :: new ( encoder. position ( ) ) ) ) ;
363-
364- // Encode the type check tables with the `SerializedDepNodeIndex`
365- // as tag.
366- encoder. encode_tagged ( dep_node, & Q :: restore ( * value) ) ;
367- }
368- } ) ;
369- }
370-
371326fn try_load_from_on_disk_cache < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode )
372327where
373328 Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -382,38 +337,6 @@ where
382337 }
383338}
384339
385- pub ( crate ) fn loadable_from_disk < ' tcx > ( tcx : TyCtxt < ' tcx > , id : SerializedDepNodeIndex ) -> bool {
386- if let Some ( cache) = tcx. query_system . on_disk_cache . as_ref ( ) {
387- cache. loadable_from_disk ( id)
388- } else {
389- false
390- }
391- }
392-
393- pub ( crate ) fn try_load_from_disk < ' tcx , V > (
394- tcx : TyCtxt < ' tcx > ,
395- prev_index : SerializedDepNodeIndex ,
396- index : DepNodeIndex ,
397- ) -> Option < V >
398- where
399- V : for < ' a > Decodable < CacheDecoder < ' a , ' tcx > > ,
400- {
401- let on_disk_cache = tcx. query_system . on_disk_cache . as_ref ( ) ?;
402-
403- let prof_timer = tcx. prof . incr_cache_loading ( ) ;
404-
405- // The call to `with_query_deserialization` enforces that no new `DepNodes`
406- // are created during deserialization. See the docs of that method for more
407- // details.
408- let value = tcx
409- . dep_graph
410- . with_query_deserialization ( || on_disk_cache. try_load_query_result ( tcx, prev_index) ) ;
411-
412- prof_timer. finish_with_query_invocation_id ( index. into ( ) ) ;
413-
414- value
415- }
416-
417340fn force_from_dep_node < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
418341where
419342 Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -477,28 +400,6 @@ where
477400 }
478401}
479402
480- macro_rules! item_if_cached {
481- ( [ ] $tokens: tt) => { } ;
482- ( [ ( cache) $( $rest: tt) * ] { $( $tokens: tt) * } ) => {
483- $( $tokens) *
484- } ;
485- ( [ $other: tt $( $modifiers: tt) * ] $tokens: tt) => {
486- item_if_cached! { [ $( $modifiers) * ] $tokens }
487- } ;
488- }
489-
490- macro_rules! expand_if_cached {
491- ( [ ] , $tokens: expr) => { {
492- None
493- } } ;
494- ( [ ( cache) $( $rest: tt) * ] , $tokens: expr) => { {
495- Some ( $tokens)
496- } } ;
497- ( [ $other: tt $( $modifiers: tt) * ] , $tokens: expr) => {
498- expand_if_cached!( [ $( $modifiers) * ] , $tokens)
499- } ;
500- }
501-
502403/// Don't show the backtrace for query system by default
503404/// use `RUST_BACKTRACE=full` to show all the backtraces
504405#[ inline( never) ]
@@ -590,38 +491,11 @@ macro_rules! define_queries {
590491 )
591492 } ,
592493 can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
593- try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
594- |tcx, key, prev_index, index| {
595- if :: rustc_middle:: query:: cached:: $name( tcx, key) {
596- let value = $crate:: plumbing:: try_load_from_disk:: <
597- queries:: $name:: ProvidedValue <' tcx>
598- >(
599- tcx,
600- prev_index,
601- index,
602- ) ;
603- value. map( |value| queries:: $name:: provided_to_erased( tcx, value) )
604- } else {
605- None
606- }
607- }
608- } {
609- |_tcx, _key, _prev_index, _index| None
610- } ) ,
611- value_from_cycle_error: |tcx, cycle, guar| {
612- let result: queries:: $name:: Value <' tcx> = Value :: from_cycle_error( tcx, cycle, guar) ;
613- erase( result)
614- } ,
615- loadable_from_disk: |_tcx, _key, _index| {
616- should_ever_cache_on_disk!( [ $( $modifiers) * ] {
617- :: rustc_middle:: query:: cached:: $name( _tcx, _key) &&
618- $crate:: plumbing:: loadable_from_disk( _tcx, _index)
619- } {
620- false
621- } )
622- } ,
623- hash_result: hash_result!( [ $( $modifiers) * ] [ queries:: $name:: Value <' tcx>] ) ,
624- format_value: |value| format!( "{:?}" , restore:: <queries:: $name:: Value <' tcx>>( * value) ) ,
494+ try_load_from_disk: query_utils:: $name:: try_load_from_disk,
495+ loadable_from_disk: query_utils:: $name:: loadable_from_disk,
496+ value_from_cycle_error: query_utils:: $name:: value_from_cycle_error,
497+ hash_result: hash_result!( [ $( $modifiers) * ] [ query_utils:: $name:: hash_result] ) ,
498+ format_value: query_utils:: $name:: format_value,
625499 }
626500 }
627501
@@ -667,30 +541,6 @@ macro_rules! define_queries {
667541 qmap,
668542 ) . unwrap( ) ;
669543 }
670-
671- pub fn alloc_self_profile_query_strings<' tcx>( tcx: TyCtxt <' tcx>, string_cache: & mut QueryKeyStringCache ) {
672- $crate:: profiling_support:: alloc_self_profile_query_strings_for_query_cache(
673- tcx,
674- stringify!( $name) ,
675- & tcx. query_system. caches. $name,
676- string_cache,
677- )
678- }
679-
680- item_if_cached! { [ $( $modifiers) * ] {
681- pub fn encode_query_results<' tcx>(
682- tcx: TyCtxt <' tcx>,
683- encoder: & mut CacheEncoder <' _, ' tcx>,
684- query_result_index: & mut EncodedDepNodeIndex
685- ) {
686- $crate:: plumbing:: encode_query_results:: <query_impl:: $name:: QueryType <' tcx>>(
687- query_impl:: $name:: QueryType :: config( tcx) ,
688- QueryCtxt :: new( tcx) ,
689- encoder,
690- query_result_index,
691- )
692- }
693- } }
694544 } ) * }
695545
696546 pub ( crate ) fn engine( incremental: bool ) -> QueryEngine {
@@ -713,23 +563,11 @@ macro_rules! define_queries {
713563 }
714564 }
715565
716- // These arrays are used for iteration and can't be indexed by `DepKind`.
566+ // This array is used for iteration and can't be indexed by `DepKind`.
717567
718568 const TRY_COLLECT_ACTIVE_JOBS : & [ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap ) ] =
719569 & [ $( query_impl:: $name:: try_collect_active_jobs) ,* ] ;
720570
721- const ALLOC_SELF_PROFILE_QUERY_STRINGS : & [
722- for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryKeyStringCache )
723- ] = & [ $( query_impl:: $name:: alloc_self_profile_query_strings) ,* ] ;
724-
725- const ENCODE_QUERY_RESULTS : & [
726- Option <for <' tcx> fn (
727- TyCtxt <' tcx>,
728- & mut CacheEncoder <' _, ' tcx>,
729- & mut EncodedDepNodeIndex )
730- >
731- ] = & [ $( expand_if_cached!( [ $( $modifiers) * ] , query_impl:: $name:: encode_query_results) ) ,* ] ;
732-
733571 #[ allow( nonstandard_style) ]
734572 mod query_callbacks {
735573 use super :: * ;
0 commit comments