3
3
//! manage the caches, and so forth.
4
4
5
5
use std:: num:: NonZero ;
6
- use std:: sync:: Arc ;
7
6
8
7
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
9
8
use rustc_data_structures:: sync:: { DynSend , DynSync } ;
@@ -312,6 +311,45 @@ macro_rules! should_ever_cache_on_disk {
312
311
} ;
313
312
}
314
313
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
+
325
+ // If reduced queries are requested, we may be printing a query stack due
326
+ // to a panic. Avoid using `default_span` and `def_kind` in that case.
327
+ let reduce_queries = with_reduced_queries ( ) ;
328
+
329
+ // Avoid calling queries while formatting the description
330
+ let description = ty:: print:: with_no_queries!( do_describe( tcx, key) ) ;
331
+ let description = if tcx. sess . verbose_internals ( ) {
332
+ format ! ( "{description} [{name:?}]" )
333
+ } else {
334
+ description
335
+ } ;
336
+ let span = if kind == dep_graph:: dep_kinds:: def_span || reduce_queries {
337
+ // The `def_span` query is used to calculate `default_span`,
338
+ // so exit to avoid infinite recursion.
339
+ None
340
+ } else {
341
+ Some ( key. default_span ( tcx) )
342
+ } ;
343
+
344
+ let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
345
+ // Try to avoid infinite recursion.
346
+ None
347
+ } else {
348
+ def_id. and_then ( |def_id| def_id. as_local ( ) ) . map ( |def_id| tcx. def_kind ( def_id) )
349
+ } ;
350
+ QueryStackFrameExtra :: new ( description, span, def_kind)
351
+ }
352
+
315
353
pub ( crate ) fn create_query_frame <
316
354
' tcx ,
317
355
K : Copy + DynSend + DynSync + Key + for < ' a > HashStable < StableHashingContext < ' a > > + ' tcx ,
@@ -324,35 +362,6 @@ pub(crate) fn create_query_frame<
324
362
) -> QueryStackFrame < QueryStackDeferred < ' tcx > > {
325
363
let def_id = key. key_as_def_id ( ) ;
326
364
327
- let extra = move || {
328
- // If reduced queries are requested, we may be printing a query stack due
329
- // to a panic. Avoid using `default_span` and `def_kind` in that case.
330
- let reduce_queries = with_reduced_queries ( ) ;
331
-
332
- // Avoid calling queries while formatting the description
333
- let description = ty:: print:: with_no_queries!( do_describe( tcx, key) ) ;
334
- let description = if tcx. sess . verbose_internals ( ) {
335
- format ! ( "{description} [{name:?}]" )
336
- } else {
337
- description
338
- } ;
339
- let span = if kind == dep_graph:: dep_kinds:: def_span || reduce_queries {
340
- // The `def_span` query is used to calculate `default_span`,
341
- // so exit to avoid infinite recursion.
342
- None
343
- } else {
344
- Some ( key. default_span ( tcx) )
345
- } ;
346
-
347
- let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
348
- // Try to avoid infinite recursion.
349
- None
350
- } else {
351
- def_id. and_then ( |def_id| def_id. as_local ( ) ) . map ( |def_id| tcx. def_kind ( def_id) )
352
- } ;
353
- QueryStackFrameExtra :: new ( description, span, def_kind)
354
- } ;
355
-
356
365
let hash = || {
357
366
tcx. with_stable_hashing_context ( |mut hcx| {
358
367
let mut hasher = StableHasher :: new ( ) ;
@@ -363,9 +372,8 @@ pub(crate) fn create_query_frame<
363
372
} ;
364
373
let def_id_for_ty_in_cycle = key. def_id_for_ty_in_cycle ( ) ;
365
374
366
- // SAFETY: None of the captures in `extra` have destructors that access 'tcx
367
- // as they don't have destructors.
368
- let info = unsafe { QueryStackDeferred :: new ( Arc :: new ( extra) ) } ;
375
+ let info =
376
+ QueryStackDeferred :: new ( ( tcx, key, kind, name, do_describe) , create_query_frame_extra) ;
369
377
370
378
QueryStackFrame :: new ( info, kind, hash, def_id, def_id_for_ty_in_cycle)
371
379
}
0 commit comments