2
2
//! generate the actual methods on tcx which find and execute the provider,
3
3
//! manage the caches, and so forth.
4
4
5
- use super :: { queries, Query } ;
5
+ use super :: queries;
6
6
use rustc_middle:: dep_graph:: { DepKind , DepNode , DepNodeExt , DepNodeIndex , SerializedDepNodeIndex } ;
7
7
use rustc_middle:: ty:: query:: on_disk_cache;
8
8
use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
9
9
use rustc_middle:: ty:: { self , TyCtxt } ;
10
10
use 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 } ;
13
13
14
- use rustc_data_structures:: fx:: FxHashMap ;
15
14
use rustc_data_structures:: sync:: Lock ;
16
15
use rustc_data_structures:: thin_vec:: ThinVec ;
17
16
use rustc_errors:: { struct_span_err, Diagnostic , DiagnosticBuilder } ;
@@ -45,8 +44,6 @@ impl HasDepContext for QueryCtxt<'tcx> {
45
44
}
46
45
47
46
impl QueryContext for QueryCtxt < ' tcx > {
48
- type Query = Query ;
49
-
50
47
fn def_path_str ( & self , def_id : DefId ) -> String {
51
48
self . tcx . def_path_str ( def_id)
52
49
}
@@ -55,10 +52,7 @@ impl QueryContext for QueryCtxt<'tcx> {
55
52
tls:: with_related_context ( * * self , |icx| icx. query )
56
53
}
57
54
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 > > {
62
56
self . queries . try_collect_active_jobs ( * * self )
63
57
}
64
58
@@ -185,11 +179,11 @@ impl<'tcx> QueryCtxt<'tcx> {
185
179
#[ cold]
186
180
pub ( super ) fn report_cycle (
187
181
self ,
188
- CycleError { usage, cycle : stack } : CycleError < Query > ,
182
+ CycleError { usage, cycle : stack } : CycleError ,
189
183
) -> DiagnosticBuilder < ' tcx > {
190
184
assert ! ( !stack. is_empty( ) ) ;
191
185
192
- let fix_span = |span : Span , query : & Query | {
186
+ let fix_span = |span : Span , query : & QueryStackFrame | {
193
187
self . sess . source_map ( ) . guess_head_span ( query. default_span ( span) )
194
188
} ;
195
189
@@ -371,17 +365,12 @@ macro_rules! define_queries {
371
365
input: ( $( ( [ $( $modifiers) * ] [ $( $attr) * ] [ $name] ) ) * )
372
366
}
373
367
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 :: * ;
381
370
382
- impl Query {
371
+ // Create an eponymous constructor for each query.
383
372
$( #[ 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 {
385
374
let kind = dep_graph:: DepKind :: $name;
386
375
let name = stringify!( $name) ;
387
376
let description = ty:: print:: with_forced_impl_filename_line(
@@ -408,22 +397,8 @@ macro_rules! define_queries {
408
397
hasher. finish( )
409
398
} ;
410
399
411
- Self { name, description, span, hash }
400
+ QueryStackFrame :: new ( name, description, span, hash)
412
401
} ) *
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
- }
427
402
}
428
403
429
404
#[ allow( nonstandard_style) ]
@@ -450,7 +425,7 @@ macro_rules! define_queries {
450
425
type Cache = query_storage:: $name<$tcx>;
451
426
452
427
#[ 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 >
454
429
where QueryCtxt <$tcx>: ' a
455
430
{
456
431
& tcx. queries. $name
@@ -484,7 +459,7 @@ macro_rules! define_queries {
484
459
485
460
fn handle_cycle_error(
486
461
tcx: QueryCtxt <' tcx>,
487
- error: CycleError < Query >
462
+ error: CycleError ,
488
463
) -> Self :: Value {
489
464
handle_cycle_error!( [ $( $modifiers) * ] [ tcx, error] )
490
465
}
@@ -587,7 +562,6 @@ macro_rules! define_queries_struct {
587
562
588
563
$( $( #[ $attr] ) * $name: QueryState <
589
564
crate :: dep_graph:: DepKind ,
590
- Query ,
591
565
query_keys:: $name<$tcx>,
592
566
>, ) *
593
567
}
@@ -607,15 +581,15 @@ macro_rules! define_queries_struct {
607
581
pub ( crate ) fn try_collect_active_jobs(
608
582
& $tcx self ,
609
583
tcx: TyCtxt <$tcx>,
610
- ) -> Option <FxHashMap < QueryJobId < crate :: dep_graph:: DepKind > , QueryJobInfo < crate :: dep_graph :: DepKind , Query > >> {
584
+ ) -> Option <QueryMap < crate :: dep_graph:: DepKind >> {
611
585
let tcx = QueryCtxt { tcx, queries: self } ;
612
- let mut jobs = FxHashMap :: default ( ) ;
586
+ let mut jobs = QueryMap :: default ( ) ;
613
587
614
588
$(
615
589
self . $name. try_collect_active_jobs(
616
590
tcx,
617
591
dep_graph:: DepKind :: $name,
618
- Query :: $name,
592
+ make_query :: $name,
619
593
& mut jobs,
620
594
) ?;
621
595
) *
0 commit comments