22//! generate the actual methods on tcx which find and execute the provider,
33//! manage the caches, and so forth.
44
5- use super :: { queries, Query } ;
5+ use super :: queries;
66use rustc_middle:: dep_graph:: { DepKind , DepNode , DepNodeExt , DepNodeIndex , SerializedDepNodeIndex } ;
77use rustc_middle:: ty:: query:: on_disk_cache;
88use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
99use rustc_middle:: ty:: { self , TyCtxt } ;
1010use rustc_query_system:: dep_graph:: HasDepContext ;
11- use rustc_query_system:: query:: { CycleError , QueryJobId , QueryJobInfo } ;
12- use rustc_query_system:: query:: { QueryContext , QueryDescription } ;
11+ use rustc_query_system:: query:: { CycleError , QueryJobId } ;
12+ use rustc_query_system:: query:: { QueryContext , QueryDescription , QueryMap , QueryStackFrame } ;
1313
14- use rustc_data_structures:: fx:: FxHashMap ;
1514use rustc_data_structures:: sync:: Lock ;
1615use rustc_data_structures:: thin_vec:: ThinVec ;
1716use rustc_errors:: { struct_span_err, Diagnostic , DiagnosticBuilder } ;
@@ -45,8 +44,6 @@ impl HasDepContext for QueryCtxt<'tcx> {
4544}
4645
4746impl QueryContext for QueryCtxt < ' tcx > {
48- type Query = Query ;
49-
5047 fn def_path_str ( & self , def_id : DefId ) -> String {
5148 self . tcx . def_path_str ( def_id)
5249 }
@@ -55,10 +52,7 @@ impl QueryContext for QueryCtxt<'tcx> {
5552 tls:: with_related_context ( * * self , |icx| icx. query )
5653 }
5754
58- fn try_collect_active_jobs (
59- & self ,
60- ) -> Option < FxHashMap < QueryJobId < Self :: DepKind > , QueryJobInfo < Self :: DepKind , Self :: Query > > >
61- {
55+ fn try_collect_active_jobs ( & self ) -> Option < QueryMap < Self :: DepKind > > {
6256 self . queries . try_collect_active_jobs ( * * self )
6357 }
6458
@@ -185,11 +179,11 @@ impl<'tcx> QueryCtxt<'tcx> {
185179 #[ cold]
186180 pub ( super ) fn report_cycle (
187181 self ,
188- CycleError { usage, cycle : stack } : CycleError < Query > ,
182+ CycleError { usage, cycle : stack } : CycleError ,
189183 ) -> DiagnosticBuilder < ' tcx > {
190184 assert ! ( !stack. is_empty( ) ) ;
191185
192- let fix_span = |span : Span , query : & Query | {
186+ let fix_span = |span : Span , query : & QueryStackFrame | {
193187 self . sess . source_map ( ) . guess_head_span ( query. default_span ( span) )
194188 } ;
195189
@@ -371,17 +365,12 @@ macro_rules! define_queries {
371365 input: ( $( ( [ $( $modifiers) * ] [ $( $attr) * ] [ $name] ) ) * )
372366 }
373367
374- #[ derive( Clone , Debug ) ]
375- pub struct Query {
376- pub name: & ' static str ,
377- hash: Fingerprint ,
378- description: String ,
379- span: Option <Span >,
380- }
368+ mod make_query {
369+ use super :: * ;
381370
382- impl Query {
371+ // Create an eponymous constructor for each query.
383372 $( #[ allow( nonstandard_style) ] $( #[ $attr] ) *
384- pub fn $name<$tcx>( tcx: QueryCtxt <$tcx>, key: query_keys:: $name<$tcx>) -> Self {
373+ pub fn $name<$tcx>( tcx: QueryCtxt <$tcx>, key: query_keys:: $name<$tcx>) -> QueryStackFrame {
385374 let kind = dep_graph:: DepKind :: $name;
386375 let name = stringify!( $name) ;
387376 let description = ty:: print:: with_forced_impl_filename_line(
@@ -408,22 +397,8 @@ macro_rules! define_queries {
408397 hasher. finish( )
409398 } ;
410399
411- Self { name, description, span, hash }
400+ QueryStackFrame :: new ( name, description, span, hash)
412401 } ) *
413-
414- // FIXME(eddyb) Get more valid `Span`s on queries.
415- pub fn default_span( & self , span: Span ) -> Span {
416- if !span. is_dummy( ) {
417- return span;
418- }
419- self . span. unwrap_or( span)
420- }
421- }
422-
423- impl <' a> HashStable <StableHashingContext <' a>> for Query {
424- fn hash_stable( & self , hcx: & mut StableHashingContext <' a>, hasher: & mut StableHasher ) {
425- self . hash. hash_stable( hcx, hasher)
426- }
427402 }
428403
429404 #[ allow( nonstandard_style) ]
@@ -450,7 +425,7 @@ macro_rules! define_queries {
450425 type Cache = query_storage:: $name<$tcx>;
451426
452427 #[ inline( always) ]
453- fn query_state<' a>( tcx: QueryCtxt <$tcx>) -> & ' a QueryState <crate :: dep_graph:: DepKind , Query , Self :: Key >
428+ fn query_state<' a>( tcx: QueryCtxt <$tcx>) -> & ' a QueryState <crate :: dep_graph:: DepKind , Self :: Key >
454429 where QueryCtxt <$tcx>: ' a
455430 {
456431 & tcx. queries. $name
@@ -484,7 +459,7 @@ macro_rules! define_queries {
484459
485460 fn handle_cycle_error(
486461 tcx: QueryCtxt <' tcx>,
487- error: CycleError < Query >
462+ error: CycleError ,
488463 ) -> Self :: Value {
489464 handle_cycle_error!( [ $( $modifiers) * ] [ tcx, error] )
490465 }
@@ -587,7 +562,6 @@ macro_rules! define_queries_struct {
587562
588563 $( $( #[ $attr] ) * $name: QueryState <
589564 crate :: dep_graph:: DepKind ,
590- Query ,
591565 query_keys:: $name<$tcx>,
592566 >, ) *
593567 }
@@ -607,15 +581,15 @@ macro_rules! define_queries_struct {
607581 pub ( crate ) fn try_collect_active_jobs(
608582 & $tcx self ,
609583 tcx: TyCtxt <$tcx>,
610- ) -> Option <FxHashMap < QueryJobId < crate :: dep_graph:: DepKind > , QueryJobInfo < crate :: dep_graph :: DepKind , Query > >> {
584+ ) -> Option <QueryMap < crate :: dep_graph:: DepKind >> {
611585 let tcx = QueryCtxt { tcx, queries: self } ;
612- let mut jobs = FxHashMap :: default ( ) ;
586+ let mut jobs = QueryMap :: default ( ) ;
613587
614588 $(
615589 self . $name. try_collect_active_jobs(
616590 tcx,
617591 dep_graph:: DepKind :: $name,
618- Query :: $name,
592+ make_query :: $name,
619593 & mut jobs,
620594 ) ?;
621595 ) *
0 commit comments