55use crate :: ty:: query:: Query ;
66use crate :: ty:: tls:: { self , ImplicitCtxt } ;
77use crate :: ty:: { self , TyCtxt } ;
8+ use rustc_query_system:: dep_graph:: HasDepContext ;
89use rustc_query_system:: query:: QueryContext ;
910use rustc_query_system:: query:: { CycleError , QueryJobId , QueryJobInfo } ;
1011
@@ -15,7 +16,29 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Leve
1516use rustc_span:: def_id:: DefId ;
1617use rustc_span:: Span ;
1718
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 > {
1942 type Query = Query < ' tcx > ;
2043
2144 fn incremental_verify_ich ( & self ) -> bool {
@@ -26,11 +49,11 @@ impl QueryContext for TyCtxt<'tcx> {
2649 }
2750
2851 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)
3053 }
3154
3255 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 )
3457 }
3558
3659 fn try_collect_active_jobs (
@@ -53,10 +76,10 @@ impl QueryContext for TyCtxt<'tcx> {
5376 // The `TyCtxt` stored in TLS has the same global interner lifetime
5477 // as `self`, so we use `with_related_context` to relate the 'tcx lifetimes
5578 // when accessing the `ImplicitCtxt`.
56- tls:: with_related_context ( * self , move |current_icx| {
79+ tls:: with_related_context ( * * self , move |current_icx| {
5780 // Update the `ImplicitCtxt` to point to our new query job.
5881 let new_icx = ImplicitCtxt {
59- tcx : * self ,
82+ tcx : * * self ,
6083 query : Some ( token) ,
6184 diagnostics,
6285 layout_depth : current_icx. layout_depth ,
@@ -71,7 +94,7 @@ impl QueryContext for TyCtxt<'tcx> {
7194 }
7295}
7396
74- impl < ' tcx > TyCtxt < ' tcx > {
97+ impl < ' tcx > QueryCtxt < ' tcx > {
7598 #[ inline( never) ]
7699 #[ cold]
77100 pub ( super ) fn report_cycle (
@@ -81,7 +104,7 @@ impl<'tcx> TyCtxt<'tcx> {
81104 assert ! ( !stack. is_empty( ) ) ;
82105
83106 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) )
85108 } ;
86109
87110 // Disable naming impls with types in this path, since that
@@ -119,7 +142,9 @@ impl<'tcx> TyCtxt<'tcx> {
119142 err
120143 } )
121144 }
145+ }
122146
147+ impl < ' tcx > TyCtxt < ' tcx > {
123148 pub fn try_print_query_stack ( handler : & Handler , num_frames : Option < usize > ) {
124149 eprintln ! ( "query stack during panic:" ) ;
125150
@@ -149,7 +174,7 @@ impl<'tcx> TyCtxt<'tcx> {
149174 "#{} [{}] {}" ,
150175 i,
151176 query_info. info. query. name( ) ,
152- query_info. info. query. describe( icx. tcx)
177+ query_info. info. query. describe( QueryCtxt ( icx. tcx) )
153178 ) ,
154179 ) ;
155180 diag. span =
@@ -272,7 +297,7 @@ macro_rules! define_queries {
272297 }
273298 }
274299
275- pub fn describe( & self , tcx: TyCtxt <$tcx>) -> String {
300+ pub ( crate ) fn describe( & self , tcx: QueryCtxt <$tcx>) -> String {
276301 let ( r, name) = match * self {
277302 $( Query :: $name( key) => {
278303 ( queries:: $name:: describe( tcx, key) , stringify!( $name) )
@@ -362,35 +387,35 @@ macro_rules! define_queries {
362387 const NAME : & ' static str = stringify!( $name) ;
363388 }
364389
365- impl <$tcx> QueryAccessors <TyCtxt <$tcx>> for queries:: $name<$tcx> {
390+ impl <$tcx> QueryAccessors <QueryCtxt <$tcx>> for queries:: $name<$tcx> {
366391 const ANON : bool = is_anon!( [ $( $modifiers) * ] ) ;
367392 const EVAL_ALWAYS : bool = is_eval_always!( [ $( $modifiers) * ] ) ;
368393 const DEP_KIND : dep_graph:: DepKind = dep_graph:: DepKind :: $name;
369394
370395 type Cache = query_storage:: $name<$tcx>;
371396
372397 #[ 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 > {
374399 & tcx. queries. $name
375400 }
376401
377402 #[ 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 >
379404 where ' tcx: ' a
380405 {
381406 & tcx. query_caches. $name
382407 }
383408
384409 #[ inline]
385- fn compute( tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
410+ fn compute( tcx: QueryCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
386411 let provider = tcx. queries. providers. get( key. query_crate( ) )
387412 // HACK(eddyb) it's possible crates may be loaded after
388413 // the query engine is created, and because crate loading
389414 // is not yet integrated with the query engine, such crates
390415 // would be missing appropriate entries in `providers`.
391416 . unwrap_or( & tcx. queries. fallback_extern_providers)
392417 . $name;
393- provider( tcx, key)
418+ provider( * tcx, key)
394419 }
395420
396421 fn hash_result(
@@ -401,7 +426,7 @@ macro_rules! define_queries {
401426 }
402427
403428 fn handle_cycle_error(
404- tcx: TyCtxt <' tcx>,
429+ tcx: QueryCtxt <' tcx>,
405430 error: CycleError <Query <' tcx>>
406431 ) -> Self :: Value {
407432 handle_cycle_error!( [ $( $modifiers) * ] [ tcx, error] )
@@ -425,7 +450,8 @@ macro_rules! define_queries {
425450 Err ( lookup) => lookup,
426451 } ;
427452
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 ) ;
429455 } ) *
430456 }
431457
@@ -516,7 +542,8 @@ macro_rules! define_queries {
516542 Err ( lookup) => lookup,
517543 } ;
518544
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( )
520547 } ) *
521548 }
522549
@@ -558,12 +585,12 @@ macro_rules! define_queries_struct {
558585
559586 pub ( crate ) fn try_collect_active_jobs(
560587 & 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>>>> {
562589 let mut jobs = FxHashMap :: default ( ) ;
563590
564591 $(
565592 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 ,
567594 Query :: $name,
568595 & mut jobs,
569596 ) ?;
0 commit comments