@@ -13,7 +13,7 @@ use crate::dep_graph::{DepKind, DepNodeIndex, QuerySideEffect, SerializedDepNode
1313use crate :: ich:: StableHashingContext ;
1414use crate :: queries:: { ExternProviders , Providers , QueryArenas , QueryVTables , TaggedQueryKey } ;
1515use crate :: query:: on_disk_cache:: OnDiskCache ;
16- use crate :: query:: { QueryCache , QueryJob , QueryStackFrame } ;
16+ use crate :: query:: { QueryCache , QueryCallContext , QueryJob , QueryStackFrame } ;
1717use crate :: ty:: TyCtxt ;
1818
1919/// For a particular query, keeps track of "active" keys, i.e. keys whose
@@ -130,7 +130,7 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
130130 /// and putting the obtained value into the in-memory cache.
131131 ///
132132 /// [^1]: [`TyCtxt`], [`TyCtxtAt`], [`TyCtxtEnsureOk`], [`TyCtxtEnsureDone`]
133- pub execute_query_fn : fn ( TyCtxt < ' tcx > , Span , C :: Key , QueryMode ) -> Option < C :: Value > ,
133+ pub execute_query_fn : fn ( TyCtxt < ' tcx > , QueryCallContext , C :: Key , QueryMode ) -> Option < C :: Value > ,
134134}
135135
136136impl < ' tcx , C : QueryCache > fmt:: Debug for QueryVTable < ' tcx , C > {
@@ -166,6 +166,8 @@ pub struct QuerySystem<'tcx> {
166166 pub extern_providers : ExternProviders ,
167167
168168 pub jobs : AtomicU64 ,
169+
170+ pub cycle_handler_nesting : Lock < u8 > ,
169171}
170172
171173#[ derive( Copy , Clone ) ]
@@ -204,6 +206,7 @@ impl<'tcx> TyCtxt<'tcx> {
204206 /// Returns a transparent wrapper for `TyCtxt` which uses
205207 /// `span` as the location of queries performed through it.
206208 #[ inline( always) ]
209+ #[ track_caller]
207210 pub fn at ( self , span : Span ) -> TyCtxtAt < ' tcx > {
208211 TyCtxtAt { tcx : self , span }
209212 }
@@ -231,6 +234,7 @@ impl<'tcx> TyCtxt<'tcx> {
231234 /// Therefore, this call mode is not appropriate for callers that want to
232235 /// ensure that the query is _never_ executed in the future.
233236 #[ inline( always) ]
237+ #[ track_caller]
234238 pub fn ensure_ok ( self ) -> TyCtxtEnsureOk < ' tcx > {
235239 TyCtxtEnsureOk { tcx : self }
236240 }
@@ -241,6 +245,7 @@ impl<'tcx> TyCtxt<'tcx> {
241245 /// but nothing else. As with `ensure_ok`, this can be more efficient than
242246 /// a normal query call.
243247 #[ inline( always) ]
248+ #[ track_caller]
244249 pub fn ensure_result ( self ) -> TyCtxtEnsureResult < ' tcx > {
245250 TyCtxtEnsureResult { tcx : self }
246251 }
@@ -262,6 +267,7 @@ impl<'tcx> TyCtxt<'tcx> {
262267 ///
263268 /// [`Steal`]: rustc_data_structures::steal::Steal
264269 #[ inline( always) ]
270+ #[ track_caller]
265271 pub fn ensure_done ( self ) -> TyCtxtEnsureDone < ' tcx > {
266272 TyCtxtEnsureDone { tcx : self }
267273 }
@@ -431,6 +437,11 @@ macro_rules! define_callbacks {
431437 }
432438 }
433439
440+ /// Calls `self.description` or returns a fallback if there was a fatal error
441+ pub fn catch_description( & self , tcx: TyCtxt <' tcx>) -> String {
442+ catch_fatal_errors( || self . description( tcx) ) . unwrap_or_else( |_| format!( "<error describing {}>" , self . query_name( ) ) )
443+ }
444+
434445 /// Returns the default span for this query if `span` is a dummy span.
435446 pub fn default_span( & self , tcx: TyCtxt <' tcx>, span: Span ) -> Span {
436447 if !span. is_dummy( ) {
@@ -449,28 +460,9 @@ macro_rules! define_callbacks {
449460 }
450461 }
451462
452- pub fn def_kind( & self , tcx: TyCtxt <' tcx>) -> Option <DefKind > {
453- // This is used to reduce code generation as it
454- // can be reused for queries with the same key type.
455- fn inner<' tcx>( key: & impl $crate:: query:: QueryKey , tcx: TyCtxt <' tcx>)
456- -> Option <DefKind >
457- {
458- key
459- . key_as_def_id( )
460- . and_then( |def_id| def_id. as_local( ) )
461- . map( |def_id| tcx. def_kind( def_id) )
462- }
463-
464- if let TaggedQueryKey :: def_kind( ..) = self {
465- // Try to avoid infinite recursion.
466- return None
467- }
468-
469- match self {
470- $(
471- TaggedQueryKey :: $name( key) => inner( key, tcx) ,
472- ) *
473- }
463+ /// Calls `self.default_span` or returns `DUMMY_SP` if there was a fatal error
464+ pub fn catch_default_span( & self , tcx: TyCtxt <' tcx>, span: Span ) -> Span {
465+ catch_fatal_errors( || self . default_span( tcx, span) ) . unwrap_or( DUMMY_SP )
474466 }
475467 }
476468
@@ -554,6 +546,7 @@ macro_rules! define_callbacks {
554546 $(
555547 $( #[ $attr] ) *
556548 #[ inline( always) ]
549+ #[ track_caller]
557550 #[ must_use]
558551 pub fn $name( self , key: maybe_into_query_key!( $( $K) * ) ) -> $V {
559552 self . at( DUMMY_SP ) . $name( key)
@@ -565,6 +558,7 @@ macro_rules! define_callbacks {
565558 $(
566559 $( #[ $attr] ) *
567560 #[ inline( always) ]
561+ #[ track_caller]
568562 pub fn $name( self , key: maybe_into_query_key!( $( $K) * ) ) -> $V {
569563 use $crate:: query:: { erase, inner} ;
570564
@@ -582,6 +576,7 @@ macro_rules! define_callbacks {
582576 $(
583577 $( #[ $attr] ) *
584578 #[ inline( always) ]
579+ #[ track_caller]
585580 pub fn $name( self , key: maybe_into_query_key!( $( $K) * ) ) {
586581 $crate:: query:: inner:: query_ensure_ok_or_done(
587582 self . tcx,
@@ -599,6 +594,7 @@ macro_rules! define_callbacks {
599594 #[ cfg( $returns_error_guaranteed) ]
600595 $( #[ $attr] ) *
601596 #[ inline( always) ]
597+ #[ track_caller]
602598 pub fn $name(
603599 self ,
604600 key: maybe_into_query_key!( $( $K) * ) ,
@@ -616,6 +612,7 @@ macro_rules! define_callbacks {
616612 $(
617613 $( #[ $attr] ) *
618614 #[ inline( always) ]
615+ #[ track_caller]
619616 pub fn $name( self , key: maybe_into_query_key!( $( $K) * ) ) {
620617 $crate:: query:: inner:: query_ensure_ok_or_done(
621618 self . tcx,
0 commit comments