55use std:: num:: NonZero ;
66
77use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
8+ use rustc_data_structures:: sync:: { DynSend , DynSync } ;
89use rustc_data_structures:: unord:: UnordMap ;
910use rustc_hashes:: Hash64 ;
1011use rustc_index:: Idx ;
@@ -24,8 +25,8 @@ use rustc_middle::ty::{self, TyCtxt};
2425use rustc_query_system:: dep_graph:: { DepNodeParams , HasDepContext } ;
2526use rustc_query_system:: ich:: StableHashingContext ;
2627use rustc_query_system:: query:: {
27- QueryCache , QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffect , QueryStackFrame ,
28- force_query,
28+ QueryCache , QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffect ,
29+ QueryStackDeferred , QueryStackFrame , QueryStackFrameExtra , force_query,
2930} ;
3031use rustc_query_system:: { QueryOverflow , QueryOverflowNote } ;
3132use rustc_serialize:: { Decodable , Encodable } ;
@@ -65,7 +66,9 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
6566 }
6667}
6768
68- impl QueryContext for QueryCtxt < ' _ > {
69+ impl < ' tcx > QueryContext for QueryCtxt < ' tcx > {
70+ type QueryInfo = QueryStackDeferred < ' tcx > ;
71+
6972 #[ inline]
7073 fn next_job_id ( self ) -> QueryJobId {
7174 QueryJobId (
@@ -82,7 +85,9 @@ impl QueryContext for QueryCtxt<'_> {
8285 /// Returns a query map representing active query jobs.
8386 /// It returns an incomplete map as an error if it fails
8487 /// to take locks.
85- fn collect_active_jobs ( self ) -> Result < QueryMap , QueryMap > {
88+ fn collect_active_jobs (
89+ self ,
90+ ) -> Result < QueryMap < QueryStackDeferred < ' tcx > > , QueryMap < QueryStackDeferred < ' tcx > > > {
8691 let mut jobs = QueryMap :: default ( ) ;
8792 let mut complete = true ;
8893
@@ -95,6 +100,13 @@ impl QueryContext for QueryCtxt<'_> {
95100 if complete { Ok ( jobs) } else { Err ( jobs) }
96101 }
97102
103+ fn lift_query_info (
104+ self ,
105+ info : & QueryStackDeferred < ' tcx > ,
106+ ) -> rustc_query_system:: query:: QueryStackFrameExtra {
107+ info. extract ( )
108+ }
109+
98110 // Interactions with on_disk_cache
99111 fn load_side_effect (
100112 self ,
@@ -159,7 +171,10 @@ impl QueryContext for QueryCtxt<'_> {
159171
160172 self . sess . dcx ( ) . emit_fatal ( QueryOverflow {
161173 span : info. job . span ,
162- note : QueryOverflowNote { desc : info. query . description , depth } ,
174+ note : QueryOverflowNote {
175+ desc : self . lift_query_info ( & info. query . info ) . description ,
176+ depth,
177+ } ,
163178 suggested_limit,
164179 crate_name : self . crate_name ( LOCAL_CRATE ) ,
165180 } ) ;
@@ -296,16 +311,17 @@ macro_rules! should_ever_cache_on_disk {
296311 } ;
297312}
298313
299- pub ( crate ) fn create_query_frame <
300- ' tcx ,
301- K : Copy + Key + for < ' a > HashStable < StableHashingContext < ' a > > ,
302- > (
303- tcx : TyCtxt < ' tcx > ,
304- do_describe : fn ( TyCtxt < ' tcx > , K ) -> String ,
305- key : K ,
306- kind : DepKind ,
307- name : & ' static str ,
308- ) -> QueryStackFrame {
314+ fn create_query_frame_extra < ' tcx , K : Key + Copy + ' tcx > (
315+ ( tcx, key, kind, name, do_describe) : (
316+ TyCtxt < ' tcx > ,
317+ K ,
318+ DepKind ,
319+ & ' static str ,
320+ fn ( TyCtxt < ' tcx > , K ) -> String ,
321+ ) ,
322+ ) -> QueryStackFrameExtra {
323+ let def_id = key. key_as_def_id ( ) ;
324+
309325 // If reduced queries are requested, we may be printing a query stack due
310326 // to a panic. Avoid using `default_span` and `def_kind` in that case.
311327 let reduce_queries = with_reduced_queries ( ) ;
@@ -324,13 +340,28 @@ pub(crate) fn create_query_frame<
324340 } else {
325341 Some ( key. default_span ( tcx) )
326342 } ;
327- let def_id = key . key_as_def_id ( ) ;
343+
328344 let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
329345 // Try to avoid infinite recursion.
330346 None
331347 } else {
332348 def_id. and_then ( |def_id| def_id. as_local ( ) ) . map ( |def_id| tcx. def_kind ( def_id) )
333349 } ;
350+ QueryStackFrameExtra :: new ( description, span, def_kind)
351+ }
352+
353+ pub ( crate ) fn create_query_frame <
354+ ' tcx ,
355+ K : Copy + DynSend + DynSync + Key + for < ' a > HashStable < StableHashingContext < ' a > > + ' tcx ,
356+ > (
357+ tcx : TyCtxt < ' tcx > ,
358+ do_describe : fn ( TyCtxt < ' tcx > , K ) -> String ,
359+ key : K ,
360+ kind : DepKind ,
361+ name : & ' static str ,
362+ ) -> QueryStackFrame < QueryStackDeferred < ' tcx > > {
363+ let def_id = key. key_as_def_id ( ) ;
364+
334365 let hash = || {
335366 tcx. with_stable_hashing_context ( |mut hcx| {
336367 let mut hasher = StableHasher :: new ( ) ;
@@ -341,7 +372,10 @@ pub(crate) fn create_query_frame<
341372 } ;
342373 let def_id_for_ty_in_cycle = key. def_id_for_ty_in_cycle ( ) ;
343374
344- QueryStackFrame :: new ( description, span, def_id, def_kind, kind, def_id_for_ty_in_cycle, hash)
375+ let info =
376+ QueryStackDeferred :: new ( ( tcx, key, kind, name, do_describe) , create_query_frame_extra) ;
377+
378+ QueryStackFrame :: new ( info, kind, hash, def_id, def_id_for_ty_in_cycle)
345379}
346380
347381pub ( crate ) fn encode_query_results < ' a , ' tcx , Q > (
@@ -688,7 +722,10 @@ macro_rules! define_queries {
688722 }
689723 }
690724
691- pub ( crate ) fn try_collect_active_jobs<' tcx>( tcx: TyCtxt <' tcx>, qmap: & mut QueryMap ) -> Option <( ) > {
725+ pub ( crate ) fn try_collect_active_jobs<' tcx>(
726+ tcx: TyCtxt <' tcx>,
727+ qmap: & mut QueryMap <QueryStackDeferred <' tcx>>,
728+ ) -> Option <( ) > {
692729 let make_query = |tcx, key| {
693730 let kind = rustc_middle:: dep_graph:: dep_kinds:: $name;
694731 let name = stringify!( $name) ;
@@ -768,7 +805,9 @@ macro_rules! define_queries {
768805
769806 // These arrays are used for iteration and can't be indexed by `DepKind`.
770807
771- const TRY_COLLECT_ACTIVE_JOBS : & [ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap ) -> Option <( ) >] =
808+ const TRY_COLLECT_ACTIVE_JOBS : & [
809+ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap <QueryStackDeferred <' tcx>>) -> Option <( ) >
810+ ] =
772811 & [ $( query_impl:: $name:: try_collect_active_jobs) ,* ] ;
773812
774813 const ALLOC_SELF_PROFILE_QUERY_STRINGS : & [
0 commit comments