5
5
use crate :: ty:: query:: Query ;
6
6
use crate :: ty:: tls:: { self , ImplicitCtxt } ;
7
7
use crate :: ty:: { self , TyCtxt } ;
8
+ use rustc_query_system:: dep_graph:: HasDepContext ;
8
9
use rustc_query_system:: query:: QueryContext ;
9
10
use rustc_query_system:: query:: { CycleError , QueryJobId , QueryJobInfo } ;
10
11
@@ -15,7 +16,29 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Leve
15
16
use rustc_span:: def_id:: DefId ;
16
17
use rustc_span:: Span ;
17
18
18
- impl QueryContext for TyCtxt < ' tcx > {
19
+ #[ derive( Copy , Clone ) ]
20
+ pub struct QueryCtxt < ' tcx > ( pub TyCtxt < ' tcx > ) ;
21
+
22
+ impl < ' tcx > std:: ops:: Deref for QueryCtxt < ' tcx > {
23
+ type Target = TyCtxt < ' tcx > ;
24
+
25
+ fn deref ( & self ) -> & Self :: Target {
26
+ & self . 0
27
+ }
28
+ }
29
+
30
+ impl HasDepContext for QueryCtxt < ' tcx > {
31
+ type DepKind = crate :: dep_graph:: DepKind ;
32
+ type StableHashingContext = crate :: ich:: StableHashingContext < ' tcx > ;
33
+ type DepContext = TyCtxt < ' tcx > ;
34
+
35
+ #[ inline]
36
+ fn dep_context ( & self ) -> & Self :: DepContext {
37
+ & self . 0
38
+ }
39
+ }
40
+
41
+ impl QueryContext for QueryCtxt < ' tcx > {
19
42
type Query = Query < ' tcx > ;
20
43
21
44
fn incremental_verify_ich ( & self ) -> bool {
@@ -26,11 +49,11 @@ impl QueryContext for TyCtxt<'tcx> {
26
49
}
27
50
28
51
fn def_path_str ( & self , def_id : DefId ) -> String {
29
- TyCtxt :: def_path_str ( * self , def_id)
52
+ self . 0 . def_path_str ( def_id)
30
53
}
31
54
32
55
fn current_query_job ( & self ) -> Option < QueryJobId < Self :: DepKind > > {
33
- tls:: with_related_context ( * self , |icx| icx. query )
56
+ tls:: with_related_context ( * * self , |icx| icx. query )
34
57
}
35
58
36
59
fn try_collect_active_jobs (
@@ -53,10 +76,10 @@ impl QueryContext for TyCtxt<'tcx> {
53
76
// The `TyCtxt` stored in TLS has the same global interner lifetime
54
77
// as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
55
78
// when accessing the `ImplicitCtxt`.
56
- tls:: with_related_context ( * self , move |current_icx| {
79
+ tls:: with_related_context ( * * self , move |current_icx| {
57
80
// Update the `ImplicitCtxt` to point to our new query job.
58
81
let new_icx = ImplicitCtxt {
59
- tcx : * self ,
82
+ tcx : * * self ,
60
83
query : Some ( token) ,
61
84
diagnostics,
62
85
layout_depth : current_icx. layout_depth ,
@@ -71,7 +94,7 @@ impl QueryContext for TyCtxt<'tcx> {
71
94
}
72
95
}
73
96
74
- impl < ' tcx > TyCtxt < ' tcx > {
97
+ impl < ' tcx > QueryCtxt < ' tcx > {
75
98
#[ inline( never) ]
76
99
#[ cold]
77
100
pub ( super ) fn report_cycle (
@@ -81,7 +104,7 @@ impl<'tcx> TyCtxt<'tcx> {
81
104
assert ! ( !stack. is_empty( ) ) ;
82
105
83
106
let fix_span = |span : Span , query : & Query < ' tcx > | {
84
- self . sess . source_map ( ) . guess_head_span ( query. default_span ( self , span) )
107
+ self . sess . source_map ( ) . guess_head_span ( query. default_span ( * self , span) )
85
108
} ;
86
109
87
110
// Disable naming impls with types in this path, since that
@@ -119,7 +142,9 @@ impl<'tcx> TyCtxt<'tcx> {
119
142
err
120
143
} )
121
144
}
145
+ }
122
146
147
+ impl < ' tcx > TyCtxt < ' tcx > {
123
148
pub fn try_print_query_stack ( handler : & Handler , num_frames : Option < usize > ) {
124
149
eprintln ! ( "query stack during panic:" ) ;
125
150
@@ -149,7 +174,7 @@ impl<'tcx> TyCtxt<'tcx> {
149
174
"#{} [{}] {}" ,
150
175
i,
151
176
query_info. info. query. name( ) ,
152
- query_info. info. query. describe( icx. tcx)
177
+ query_info. info. query. describe( QueryCtxt ( icx. tcx) )
153
178
) ,
154
179
) ;
155
180
diag. span =
@@ -272,7 +297,7 @@ macro_rules! define_queries {
272
297
}
273
298
}
274
299
275
- pub fn describe( & self , tcx: TyCtxt <$tcx>) -> String {
300
+ pub ( crate ) fn describe( & self , tcx: QueryCtxt <$tcx>) -> String {
276
301
let ( r, name) = match * self {
277
302
$( Query :: $name( key) => {
278
303
( queries:: $name:: describe( tcx, key) , stringify!( $name) )
@@ -362,35 +387,35 @@ macro_rules! define_queries {
362
387
const NAME : & ' static str = stringify!( $name) ;
363
388
}
364
389
365
- impl <$tcx> QueryAccessors <TyCtxt <$tcx>> for queries:: $name<$tcx> {
390
+ impl <$tcx> QueryAccessors <QueryCtxt <$tcx>> for queries:: $name<$tcx> {
366
391
const ANON : bool = is_anon!( [ $( $modifiers) * ] ) ;
367
392
const EVAL_ALWAYS : bool = is_eval_always!( [ $( $modifiers) * ] ) ;
368
393
const DEP_KIND : dep_graph:: DepKind = dep_graph:: DepKind :: $name;
369
394
370
395
type Cache = query_storage:: $name<$tcx>;
371
396
372
397
#[ inline( always) ]
373
- fn query_state<' a>( tcx: TyCtxt <$tcx>) -> & ' a QueryState <crate :: dep_graph:: DepKind , Query <$tcx>, Self :: Key > {
398
+ fn query_state<' a>( tcx: QueryCtxt <$tcx>) -> & ' a QueryState <crate :: dep_graph:: DepKind , Query <$tcx>, Self :: Key > {
374
399
& tcx. queries. $name
375
400
}
376
401
377
402
#[ inline( always) ]
378
- fn query_cache<' a>( tcx: TyCtxt <$tcx>) -> & ' a QueryCacheStore <Self :: Cache >
403
+ fn query_cache<' a>( tcx: QueryCtxt <$tcx>) -> & ' a QueryCacheStore <Self :: Cache >
379
404
where ' tcx: ' a
380
405
{
381
406
& tcx. query_caches. $name
382
407
}
383
408
384
409
#[ inline]
385
- fn compute( tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
410
+ fn compute( tcx: QueryCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
386
411
let provider = tcx. queries. providers. get( key. query_crate( ) )
387
412
// HACK(eddyb) it's possible crates may be loaded after
388
413
// the query engine is created, and because crate loading
389
414
// is not yet integrated with the query engine, such crates
390
415
// would be missing appropriate entries in `providers`.
391
416
. unwrap_or( & tcx. queries. fallback_extern_providers)
392
417
. $name;
393
- provider( tcx, key)
418
+ provider( * tcx, key)
394
419
}
395
420
396
421
fn hash_result(
@@ -401,7 +426,7 @@ macro_rules! define_queries {
401
426
}
402
427
403
428
fn handle_cycle_error(
404
- tcx: TyCtxt <' tcx>,
429
+ tcx: QueryCtxt <' tcx>,
405
430
error: CycleError <Query <' tcx>>
406
431
) -> Self :: Value {
407
432
handle_cycle_error!( [ $( $modifiers) * ] [ tcx, error] )
@@ -425,7 +450,8 @@ macro_rules! define_queries {
425
450
Err ( lookup) => lookup,
426
451
} ;
427
452
428
- get_query:: <queries:: $name<' _>, _>( self . tcx, DUMMY_SP , key, lookup, QueryMode :: Ensure ) ;
453
+ let qcx = QueryCtxt ( self . tcx) ;
454
+ get_query:: <queries:: $name<' _>, _>( qcx, DUMMY_SP , key, lookup, QueryMode :: Ensure ) ;
429
455
} ) *
430
456
}
431
457
@@ -516,7 +542,8 @@ macro_rules! define_queries {
516
542
Err ( lookup) => lookup,
517
543
} ;
518
544
519
- get_query:: <queries:: $name<' _>, _>( self . tcx, self . span, key, lookup, QueryMode :: Get ) . unwrap( )
545
+ let qcx = QueryCtxt ( self . tcx) ;
546
+ get_query:: <queries:: $name<' _>, _>( qcx, self . span, key, lookup, QueryMode :: Get ) . unwrap( )
520
547
} ) *
521
548
}
522
549
@@ -558,12 +585,12 @@ macro_rules! define_queries_struct {
558
585
559
586
pub ( crate ) fn try_collect_active_jobs(
560
587
& self
561
- ) -> Option <FxHashMap <QueryJobId <crate :: dep_graph:: DepKind >, QueryJobInfo <crate :: dep_graph:: DepKind , < TyCtxt < $tcx> as QueryContext > :: Query >>> {
588
+ ) -> Option <FxHashMap <QueryJobId <crate :: dep_graph:: DepKind >, QueryJobInfo <crate :: dep_graph:: DepKind , Query < $tcx>>>> {
562
589
let mut jobs = FxHashMap :: default ( ) ;
563
590
564
591
$(
565
592
self . $name. try_collect_active_jobs(
566
- <queries:: $name<' tcx> as QueryAccessors <TyCtxt <' tcx>>>:: DEP_KIND ,
593
+ <queries:: $name<' tcx> as QueryAccessors <QueryCtxt <' tcx>>>:: DEP_KIND ,
567
594
Query :: $name,
568
595
& mut jobs,
569
596
) ?;
0 commit comments