33//! manage the caches, and so forth.
44
55use std:: num:: NonZero ;
6- use std:: sync:: Arc ;
76
87use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
98use rustc_data_structures:: sync:: { DynSend , DynSync } ;
@@ -312,6 +311,45 @@ macro_rules! should_ever_cache_on_disk {
312311 } ;
313312}
314313
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+
315353pub ( crate ) fn create_query_frame <
316354 ' tcx ,
317355 K : Copy + DynSend + DynSync + Key + for < ' a > HashStable < StableHashingContext < ' a > > + ' tcx ,
@@ -324,35 +362,6 @@ pub(crate) fn create_query_frame<
324362) -> QueryStackFrame < QueryStackDeferred < ' tcx > > {
325363 let def_id = key. key_as_def_id ( ) ;
326364
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-
356365 let hash = || {
357366 tcx. with_stable_hashing_context ( |mut hcx| {
358367 let mut hasher = StableHasher :: new ( ) ;
@@ -363,9 +372,8 @@ pub(crate) fn create_query_frame<
363372 } ;
364373 let def_id_for_ty_in_cycle = key. def_id_for_ty_in_cycle ( ) ;
365374
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) ;
369377
370378 QueryStackFrame :: new ( info, kind, hash, def_id, def_id_for_ty_in_cycle)
371379}
0 commit comments