@@ -9,17 +9,18 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99use rustc_data_structures:: sync:: { DynSend , DynSync } ;
1010use rustc_data_structures:: unord:: UnordMap ;
1111use rustc_hashes:: Hash64 ;
12+ use rustc_hir:: def_id:: DefId ;
1213use rustc_hir:: limit:: Limit ;
1314use rustc_index:: Idx ;
1415use rustc_middle:: bug;
1516use rustc_middle:: dep_graph:: {
16- self , DepContext , DepKind , DepKindVTable , DepNode , DepNodeIndex , SerializedDepNodeIndex ,
17- dep_kinds,
17+ self , DepContext , DepKindVTable , DepNode , DepNodeIndex , SerializedDepNodeIndex , dep_kinds,
1818} ;
1919use rustc_middle:: query:: Key ;
2020use rustc_middle:: query:: on_disk_cache:: {
2121 AbsoluteBytePos , CacheDecoder , CacheEncoder , EncodedDepNodeIndex ,
2222} ;
23+ use rustc_middle:: query:: plumbing:: QueryVTable ;
2324use rustc_middle:: ty:: codec:: TyEncoder ;
2425use rustc_middle:: ty:: print:: with_reduced_queries;
2526use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
@@ -312,37 +313,36 @@ macro_rules! should_ever_cache_on_disk {
312313 } ;
313314}
314315
315- fn mk_query_stack_frame_extra < ' tcx , K : Key + Copy + ' tcx > (
316- ( tcx, key, kind, name, do_describe) : (
317- TyCtxt < ' tcx > ,
318- K ,
319- DepKind ,
320- & ' static str ,
321- fn ( TyCtxt < ' tcx > , K ) -> String ,
322- ) ,
323- ) -> QueryStackFrameExtra {
316+ /// The deferred part of a deferred query stack frame.
317+ fn mk_query_stack_frame_extra < ' tcx , Cache > (
318+ ( tcx, vtable, key) : ( TyCtxt < ' tcx > , & ' tcx QueryVTable < ' tcx , Cache > , Cache :: Key ) ,
319+ ) -> QueryStackFrameExtra
320+ where
321+ Cache : QueryCache ,
322+ Cache :: Key : Key ,
323+ {
324324 let def_id = key. key_as_def_id ( ) ;
325325
326326 // If reduced queries are requested, we may be printing a query stack due
327327 // to a panic. Avoid using `default_span` and `def_kind` in that case.
328328 let reduce_queries = with_reduced_queries ( ) ;
329329
330330 // Avoid calling queries while formatting the description
331- let description = ty:: print:: with_no_queries!( do_describe ( tcx, key) ) ;
331+ let description = ty:: print:: with_no_queries!( ( vtable . description_fn ) ( tcx, key) ) ;
332332 let description = if tcx. sess . verbose_internals ( ) {
333- format ! ( "{description} [{name:?}]" )
333+ format ! ( "{description} [{name:?}]" , name = vtable . name )
334334 } else {
335335 description
336336 } ;
337- let span = if kind == dep_graph:: dep_kinds:: def_span || reduce_queries {
337+ let span = if vtable . dep_kind == dep_graph:: dep_kinds:: def_span || reduce_queries {
338338 // The `def_span` query is used to calculate `default_span`,
339339 // so exit to avoid infinite recursion.
340340 None
341341 } else {
342342 Some ( key. default_span ( tcx) )
343343 } ;
344344
345- let def_kind = if kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
345+ let def_kind = if vtable . dep_kind == dep_graph:: dep_kinds:: def_kind || reduce_queries {
346346 // Try to avoid infinite recursion.
347347 None
348348 } else {
@@ -351,29 +351,28 @@ fn mk_query_stack_frame_extra<'tcx, K: Key + Copy + 'tcx>(
351351 QueryStackFrameExtra :: new ( description, span, def_kind)
352352}
353353
354- pub ( crate ) fn create_query_frame <
355- ' tcx ,
356- K : Copy + DynSend + DynSync + Key + for < ' a > HashStable < StableHashingContext < ' a > > + ' tcx ,
357- > (
354+ pub ( crate ) fn create_deferred_query_stack_frame < ' tcx , Cache > (
358355 tcx : TyCtxt < ' tcx > ,
359- do_describe : fn ( TyCtxt < ' tcx > , K ) -> String ,
360- key : K ,
361- kind : DepKind ,
362- name : & ' static str ,
363- ) -> QueryStackFrame < QueryStackDeferred < ' tcx > > {
364- let def_id = key. key_as_def_id ( ) ;
356+ vtable : & ' tcx QueryVTable < ' tcx , Cache > ,
357+ key : Cache :: Key ,
358+ ) -> QueryStackFrame < QueryStackDeferred < ' tcx > >
359+ where
360+ Cache : QueryCache ,
361+ Cache :: Key : Key + DynSend + DynSync + for < ' a > HashStable < StableHashingContext < ' a > > + ' tcx ,
362+ {
363+ let kind = vtable. dep_kind ;
365364
366365 let hash = tcx. with_stable_hashing_context ( |mut hcx| {
367366 let mut hasher = StableHasher :: new ( ) ;
368367 kind. as_usize ( ) . hash_stable ( & mut hcx, & mut hasher) ;
369368 key. hash_stable ( & mut hcx, & mut hasher) ;
370369 hasher. finish :: < Hash64 > ( )
371370 } ) ;
372- let def_id_for_ty_in_cycle = key. def_id_for_ty_in_cycle ( ) ;
373371
374- let info =
375- QueryStackDeferred :: new ( ( tcx , key , kind , name , do_describe ) , mk_query_stack_frame_extra ) ;
372+ let def_id : Option < DefId > = key . key_as_def_id ( ) ;
373+ let def_id_for_ty_in_cycle : Option < DefId > = key . def_id_for_ty_in_cycle ( ) ;
376374
375+ let info = QueryStackDeferred :: new ( ( tcx, vtable, key) , mk_query_stack_frame_extra) ;
377376 QueryStackFrame :: new ( info, kind, hash, def_id, def_id_for_ty_in_cycle)
378377}
379378
@@ -697,6 +696,7 @@ macro_rules! define_queries {
697696 } ,
698697 hash_result: hash_result!( [ $( $modifiers) * ] [ queries:: $name:: Value <' tcx>] ) ,
699698 format_value: |value| format!( "{:?}" , erase:: restore_val:: <queries:: $name:: Value <' tcx>>( * value) ) ,
699+ description_fn: $crate:: queries:: _description_fns:: $name,
700700 }
701701 }
702702
@@ -742,10 +742,9 @@ macro_rules! define_queries {
742742 qmap: & mut QueryMap <' tcx>,
743743 require_complete: bool ,
744744 ) -> Option <( ) > {
745- let make_frame = |tcx, key| {
746- let kind = rustc_middle:: dep_graph:: dep_kinds:: $name;
747- let name = stringify!( $name) ;
748- $crate:: plumbing:: create_query_frame( tcx, queries:: descs:: $name, key, kind, name)
745+ let make_frame = |tcx: TyCtxt <' tcx>, key| {
746+ let vtable = & tcx. query_system. query_vtables. $name;
747+ $crate:: plumbing:: create_deferred_query_stack_frame( tcx, vtable, key)
749748 } ;
750749
751750 // Call `gather_active_jobs_inner` to do the actual work.
0 commit comments