3
3
//! manage the caches, and so forth.
4
4
5
5
use std:: num:: NonZero ;
6
+ use std:: sync:: Arc ;
6
7
7
8
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
8
- use rustc_data_structures:: sync:: Lock ;
9
+ use rustc_data_structures:: sync:: { DynSend , DynSync , Lock } ;
9
10
use rustc_data_structures:: unord:: UnordMap ;
10
11
use rustc_errors:: DiagInner ;
11
12
use rustc_hashes:: Hash64 ;
@@ -26,8 +27,8 @@ use rustc_middle::ty::{self, TyCtxt};
26
27
use rustc_query_system:: dep_graph:: { DepNodeParams , HasDepContext } ;
27
28
use rustc_query_system:: ich:: StableHashingContext ;
28
29
use rustc_query_system:: query:: {
29
- QueryCache , QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects , QueryStackFrame ,
30
- force_query,
30
+ QueryCache , QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects ,
31
+ QueryStackDeferred , QueryStackFrame , QueryStackFrameExtra , force_query,
31
32
} ;
32
33
use rustc_query_system:: { QueryOverflow , QueryOverflowNote } ;
33
34
use rustc_serialize:: { Decodable , Encodable } ;
@@ -68,7 +69,9 @@ impl<'tcx> HasDepContext for QueryCtxt<'tcx> {
68
69
}
69
70
}
70
71
71
- impl QueryContext for QueryCtxt < ' _ > {
72
+ impl < ' tcx > QueryContext for QueryCtxt < ' tcx > {
73
+ type QueryInfo = QueryStackDeferred < ' tcx > ;
74
+
72
75
#[ inline]
73
76
fn next_job_id ( self ) -> QueryJobId {
74
77
QueryJobId (
@@ -84,7 +87,7 @@ impl QueryContext for QueryCtxt<'_> {
84
87
85
88
/// Returns a query map representing active query jobs and a bool being false
86
89
/// if there was an error constructing the map.
87
- fn collect_active_jobs ( self ) -> ( QueryMap , bool ) {
90
+ fn collect_active_jobs ( self ) -> ( QueryMap < QueryStackDeferred < ' tcx > > , bool ) {
88
91
let mut jobs = QueryMap :: default ( ) ;
89
92
let mut complete = true ;
90
93
@@ -95,6 +98,13 @@ impl QueryContext for QueryCtxt<'_> {
95
98
( jobs, complete)
96
99
}
97
100
101
+ fn lift_query_info (
102
+ self ,
103
+ info : & QueryStackDeferred < ' tcx > ,
104
+ ) -> rustc_query_system:: query:: QueryStackFrameExtra {
105
+ info. extract ( )
106
+ }
107
+
98
108
// Interactions with on_disk_cache
99
109
fn load_side_effects ( self , prev_dep_node_index : SerializedDepNodeIndex ) -> QuerySideEffects {
100
110
self . query_system
@@ -168,7 +178,10 @@ impl QueryContext for QueryCtxt<'_> {
168
178
169
179
self . sess . dcx ( ) . emit_fatal ( QueryOverflow {
170
180
span : info. job . span ,
171
- note : QueryOverflowNote { desc : info. query . description , depth } ,
181
+ note : QueryOverflowNote {
182
+ desc : self . lift_query_info ( & info. query . info ) . description ,
183
+ depth,
184
+ } ,
172
185
suggested_limit,
173
186
crate_name : self . crate_name ( LOCAL_CRATE ) ,
174
187
} ) ;
@@ -307,39 +320,45 @@ macro_rules! should_ever_cache_on_disk {
307
320
308
321
pub ( crate ) fn create_query_frame <
309
322
' tcx ,
310
- K : Copy + Key + for < ' a > HashStable < StableHashingContext < ' a > > ,
323
+ K : Copy + DynSend + DynSync + Key + for < ' a > HashStable < StableHashingContext < ' a > > + ' tcx ,
311
324
> (
312
325
tcx : TyCtxt < ' tcx > ,
313
326
do_describe : fn ( TyCtxt < ' tcx > , K ) -> String ,
314
327
key : K ,
315
328
kind : DepKind ,
316
329
name : & ' static str ,
317
- ) -> QueryStackFrame {
318
- // If reduced queries are requested, we may be printing a query stack due
319
- // to a panic. Avoid using `default_span` and `def_kind` in that case.
320
- let reduce_queries = with_reduced_queries ( ) ;
321
-
322
- // Avoid calling queries while formatting the description
323
- let description = ty:: print:: with_no_queries!( do_describe( tcx, key) ) ;
324
- let description = if tcx. sess . verbose_internals ( ) {
325
- format ! ( "{description} [{name:?}]" )
326
- } else {
327
- description
328
- } ;
329
- let span = if kind == dep_graph:: dep_kinds:: def_span || reduce_queries {
330
- // The `def_span` query is used to calculate `default_span`,
331
- // so exit to avoid infinite recursion.
332
- None
333
- } else {
334
- Some ( key. default_span ( tcx) )
335
- } ;
330
+ ) -> QueryStackFrame < QueryStackDeferred < ' tcx > > {
336
331
let def_id = key. key_as_def_id ( ) ;
337
- let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
338
- // Try to avoid infinite recursion.
339
- None
340
- } else {
341
- def_id. and_then ( |def_id| def_id. as_local ( ) ) . map ( |def_id| tcx. def_kind ( def_id) )
332
+
333
+ let extra = move || {
334
+ // If reduced queries are requested, we may be printing a query stack due
335
+ // to a panic. Avoid using `default_span` and `def_kind` in that case.
336
+ let reduce_queries = with_reduced_queries ( ) ;
337
+
338
+ // Avoid calling queries while formatting the description
339
+ let description = ty:: print:: with_no_queries!( do_describe( tcx, key) ) ;
340
+ let description = if tcx. sess . verbose_internals ( ) {
341
+ format ! ( "{description} [{name:?}]" )
342
+ } else {
343
+ description
344
+ } ;
345
+ let span = if kind == dep_graph:: dep_kinds:: def_span || reduce_queries {
346
+ // The `def_span` query is used to calculate `default_span`,
347
+ // so exit to avoid infinite recursion.
348
+ None
349
+ } else {
350
+ Some ( key. default_span ( tcx) )
351
+ } ;
352
+
353
+ let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
354
+ // Try to avoid infinite recursion.
355
+ None
356
+ } else {
357
+ def_id. and_then ( |def_id| def_id. as_local ( ) ) . map ( |def_id| tcx. def_kind ( def_id) )
358
+ } ;
359
+ QueryStackFrameExtra :: new ( description, span, def_kind)
342
360
} ;
361
+
343
362
let hash = || {
344
363
tcx. with_stable_hashing_context ( |mut hcx| {
345
364
let mut hasher = StableHasher :: new ( ) ;
@@ -350,7 +369,11 @@ pub(crate) fn create_query_frame<
350
369
} ;
351
370
let def_id_for_ty_in_cycle = key. def_id_for_ty_in_cycle ( ) ;
352
371
353
- QueryStackFrame :: new ( description, span, def_id, def_kind, kind, def_id_for_ty_in_cycle, hash)
372
+ // SAFETY: None of the captures in `extra` have destructors that access 'tcx
373
+ // as they don't have destructors.
374
+ let info = unsafe { QueryStackDeferred :: new ( Arc :: new ( extra) ) } ;
375
+
376
+ QueryStackFrame :: new ( info, kind, hash, def_id, def_id_for_ty_in_cycle)
354
377
}
355
378
356
379
pub ( crate ) fn encode_query_results < ' a , ' tcx , Q > (
@@ -697,7 +720,11 @@ macro_rules! define_queries {
697
720
}
698
721
}
699
722
700
- pub ( crate ) fn try_collect_active_jobs<' tcx>( tcx: TyCtxt <' tcx>, qmap: & mut QueryMap , complete: & mut bool ) {
723
+ pub ( crate ) fn try_collect_active_jobs<' tcx>(
724
+ tcx: TyCtxt <' tcx>,
725
+ qmap: & mut QueryMap <QueryStackDeferred <' tcx>>,
726
+ complete: & mut bool
727
+ ) {
701
728
let make_query = |tcx, key| {
702
729
let kind = rustc_middle:: dep_graph:: dep_kinds:: $name;
703
730
let name = stringify!( $name) ;
@@ -777,7 +804,9 @@ macro_rules! define_queries {
777
804
778
805
// These arrays are used for iteration and can't be indexed by `DepKind`.
779
806
780
- const TRY_COLLECT_ACTIVE_JOBS : & [ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap , & mut bool ) ] =
807
+ const TRY_COLLECT_ACTIVE_JOBS : & [
808
+ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap <QueryStackDeferred <' tcx>>, & mut bool )
809
+ ] =
781
810
& [ $( query_impl:: $name:: try_collect_active_jobs) ,* ] ;
782
811
783
812
const ALLOC_SELF_PROFILE_QUERY_STRINGS : & [
0 commit comments