5
5
use std:: num:: NonZero ;
6
6
7
7
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
8
+ use rustc_data_structures:: sync:: { DynSend , DynSync } ;
8
9
use rustc_data_structures:: unord:: UnordMap ;
9
10
use rustc_hashes:: Hash64 ;
10
11
use rustc_index:: Idx ;
@@ -24,8 +25,8 @@ use rustc_middle::ty::{self, TyCtxt};
24
25
use rustc_query_system:: dep_graph:: { DepNodeParams , HasDepContext } ;
25
26
use rustc_query_system:: ich:: StableHashingContext ;
26
27
use 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,
29
30
} ;
30
31
use rustc_query_system:: { QueryOverflow , QueryOverflowNote } ;
31
32
use rustc_serialize:: { Decodable , Encodable } ;
@@ -65,7 +66,9 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
65
66
}
66
67
}
67
68
68
- impl QueryContext for QueryCtxt < ' _ > {
69
+ impl < ' tcx > QueryContext for QueryCtxt < ' tcx > {
70
+ type QueryInfo = QueryStackDeferred < ' tcx > ;
71
+
69
72
#[ inline]
70
73
fn next_job_id ( self ) -> QueryJobId {
71
74
QueryJobId (
@@ -82,7 +85,9 @@ impl QueryContext for QueryCtxt<'_> {
82
85
/// Returns a query map representing active query jobs.
83
86
/// It returns an incomplete map as an error if it fails
84
87
/// 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 > > > {
86
91
let mut jobs = QueryMap :: default ( ) ;
87
92
let mut complete = true ;
88
93
@@ -95,6 +100,13 @@ impl QueryContext for QueryCtxt<'_> {
95
100
if complete { Ok ( jobs) } else { Err ( jobs) }
96
101
}
97
102
103
+ fn lift_query_info (
104
+ self ,
105
+ info : & QueryStackDeferred < ' tcx > ,
106
+ ) -> rustc_query_system:: query:: QueryStackFrameExtra {
107
+ info. extract ( )
108
+ }
109
+
98
110
// Interactions with on_disk_cache
99
111
fn load_side_effect (
100
112
self ,
@@ -159,7 +171,10 @@ impl QueryContext for QueryCtxt<'_> {
159
171
160
172
self . sess . dcx ( ) . emit_fatal ( QueryOverflow {
161
173
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
+ } ,
163
178
suggested_limit,
164
179
crate_name : self . crate_name ( LOCAL_CRATE ) ,
165
180
} ) ;
@@ -296,16 +311,17 @@ macro_rules! should_ever_cache_on_disk {
296
311
} ;
297
312
}
298
313
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
+
309
325
// If reduced queries are requested, we may be printing a query stack due
310
326
// to a panic. Avoid using `default_span` and `def_kind` in that case.
311
327
let reduce_queries = with_reduced_queries ( ) ;
@@ -324,13 +340,28 @@ pub(crate) fn create_query_frame<
324
340
} else {
325
341
Some ( key. default_span ( tcx) )
326
342
} ;
327
- let def_id = key . key_as_def_id ( ) ;
343
+
328
344
let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
329
345
// Try to avoid infinite recursion.
330
346
None
331
347
} else {
332
348
def_id. and_then ( |def_id| def_id. as_local ( ) ) . map ( |def_id| tcx. def_kind ( def_id) )
333
349
} ;
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
+
334
365
let hash = || {
335
366
tcx. with_stable_hashing_context ( |mut hcx| {
336
367
let mut hasher = StableHasher :: new ( ) ;
@@ -341,7 +372,10 @@ pub(crate) fn create_query_frame<
341
372
} ;
342
373
let def_id_for_ty_in_cycle = key. def_id_for_ty_in_cycle ( ) ;
343
374
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)
345
379
}
346
380
347
381
pub ( crate ) fn encode_query_results < ' a , ' tcx , Q > (
@@ -688,7 +722,10 @@ macro_rules! define_queries {
688
722
}
689
723
}
690
724
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 <( ) > {
692
729
let make_query = |tcx, key| {
693
730
let kind = rustc_middle:: dep_graph:: dep_kinds:: $name;
694
731
let name = stringify!( $name) ;
@@ -768,7 +805,9 @@ macro_rules! define_queries {
768
805
769
806
// These arrays are used for iteration and can't be indexed by `DepKind`.
770
807
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
+ ] =
772
811
& [ $( query_impl:: $name:: try_collect_active_jobs) ,* ] ;
773
812
774
813
const ALLOC_SELF_PROFILE_QUERY_STRINGS : & [
0 commit comments