@@ -17,12 +17,13 @@ use rustc_middle::dep_graph::DepKindVTable;
1717use rustc_middle:: dep_graph:: {
1818 self , DepNode , DepNodeIndex , DepNodeKey , SerializedDepNodeIndex , dep_kinds,
1919} ;
20+ use rustc_middle:: query:: erase:: { Erasable , Erased } ;
2021use rustc_middle:: query:: on_disk_cache:: {
2122 AbsoluteBytePos , CacheDecoder , CacheEncoder , EncodedDepNodeIndex ,
2223} ;
2324use rustc_middle:: query:: plumbing:: QueryVTable ;
2425use rustc_middle:: query:: {
25- Key , QueryCache , QueryJobId , QueryStackDeferred , QueryStackFrame , QueryStackFrameExtra ,
26+ Key , QueryCache , QueryJobId , QueryStackDeferred , QueryStackFrame , QueryStackFrameExtra , erase ,
2627} ;
2728use rustc_middle:: ty:: codec:: TyEncoder ;
2829use rustc_middle:: ty:: print:: with_reduced_queries;
@@ -34,7 +35,7 @@ use rustc_span::def_id::LOCAL_CRATE;
3435use crate :: error:: { QueryOverflow , QueryOverflowNote } ;
3536use crate :: execution:: { all_inactive, force_query} ;
3637use crate :: job:: { QueryJobMap , find_dep_kind_root} ;
37- use crate :: { QueryDispatcherUnerased , QueryFlags , SemiDynamicQueryDispatcher } ;
38+ use crate :: { GetQueryVTable , QueryFlags , SemiDynamicQueryDispatcher } ;
3839
3940fn depth_limit_error < ' tcx > ( tcx : TyCtxt < ' tcx > , job : QueryJobId ) {
4041 let job_map =
@@ -335,15 +336,16 @@ where
335336 QueryStackFrame :: new ( info, kind, hash, def_id, def_id_for_ty_in_cycle)
336337}
337338
338- pub ( crate ) fn encode_query_results < ' a , ' tcx , Q , C : QueryCache , const FLAGS : QueryFlags > (
339- query : SemiDynamicQueryDispatcher < ' tcx , C , FLAGS > ,
339+ pub ( crate ) fn encode_query_results_inner < ' a , ' tcx , Q , const FLAGS : QueryFlags , Value > (
340340 tcx : TyCtxt < ' tcx > ,
341341 encoder : & mut CacheEncoder < ' a , ' tcx > ,
342342 query_result_index : & mut EncodedDepNodeIndex ,
343343) where
344- Q : QueryDispatcherUnerased < ' tcx , C , FLAGS > ,
345- Q :: UnerasedValue : Encodable < CacheEncoder < ' a , ' tcx > > ,
344+ Q : GetQueryVTable < ' tcx , FLAGS > ,
345+ Q :: Cache : QueryCache < Value = Erased < Value > > ,
346+ Value : Erasable + Encodable < CacheEncoder < ' a , ' tcx > > ,
346347{
348+ let query = Q :: query_dispatcher ( tcx) ;
347349 let _timer = tcx. prof . generic_activity_with_arg ( "encode_query_results_for" , query. name ( ) ) ;
348350
349351 assert ! ( all_inactive( query. query_state( tcx) ) ) ;
@@ -357,7 +359,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q, C: QueryCache, const FLAGS: Quer
357359
358360 // Encode the type check tables with the `SerializedDepNodeIndex`
359361 // as tag.
360- encoder. encode_tagged ( dep_node, & Q :: restore_val ( * value) ) ;
362+ encoder. encode_tagged ( dep_node, & erase :: restore_val ( * value) ) ;
361363 }
362364 } ) ;
363365}
@@ -485,7 +487,6 @@ macro_rules! define_queries {
485487
486488 pub ( crate ) mod query_impl { $( pub ( crate ) mod $name {
487489 use super :: super :: * ;
488- use std:: marker:: PhantomData ;
489490 use :: rustc_middle:: query:: erase:: { self , Erased } ;
490491
491492 pub ( crate ) mod get_query_incr {
@@ -503,7 +504,7 @@ macro_rules! define_queries {
503504 #[ cfg( debug_assertions) ]
504505 let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered( ) ;
505506 execution:: get_query_incr(
506- QueryType :: query_dispatcher( tcx) ,
507+ VTableGetter :: query_dispatcher( tcx) ,
507508 tcx,
508509 span,
509510 key,
@@ -523,7 +524,7 @@ macro_rules! define_queries {
523524 __mode: QueryMode ,
524525 ) -> Option <Erased <queries:: $name:: Value <' tcx>>> {
525526 Some ( execution:: get_query_non_incr(
526- QueryType :: query_dispatcher( tcx) ,
527+ VTableGetter :: query_dispatcher( tcx) ,
527528 tcx,
528529 span,
529530 key,
@@ -616,39 +617,28 @@ macro_rules! define_queries {
616617 }
617618 }
618619
619- #[ derive( Copy , Clone , Default ) ]
620- pub ( crate ) struct QueryType <' tcx> {
621- data: PhantomData <& ' tcx ( ) >
622- }
623-
624620 const FLAGS : QueryFlags = QueryFlags {
625621 is_anon: is_anon!( [ $( $modifiers) * ] ) ,
626622 is_depth_limit: depth_limit!( [ $( $modifiers) * ] ) ,
627623 is_feedable: feedable!( [ $( $modifiers) * ] ) ,
628624 } ;
629625
630- impl <' tcx> QueryDispatcherUnerased <' tcx, queries:: $name:: Storage <' tcx>, FLAGS >
631- for QueryType <' tcx>
632- {
633- type UnerasedValue = queries:: $name:: Value <' tcx>;
626+ /// Marker type that implements [`GetQueryVTable`] for this query.
627+ pub ( crate ) enum VTableGetter { }
628+
629+ impl <' tcx> GetQueryVTable <' tcx, FLAGS > for VTableGetter {
630+ type Cache = queries:: $name:: Storage <' tcx>;
634631
635632 const NAME : & ' static & ' static str = & stringify!( $name) ;
636633
637634 #[ inline( always) ]
638635 fn query_dispatcher( tcx: TyCtxt <' tcx>)
639- -> SemiDynamicQueryDispatcher <' tcx, queries :: $name :: Storage < ' tcx> , FLAGS >
636+ -> SemiDynamicQueryDispatcher <' tcx, Self :: Cache , FLAGS >
640637 {
641638 SemiDynamicQueryDispatcher {
642639 vtable: & tcx. query_system. query_vtables. $name,
643640 }
644641 }
645-
646- #[ inline( always) ]
647- fn restore_val( value: <queries:: $name:: Storage <' tcx> as QueryCache >:: Value )
648- -> Self :: UnerasedValue
649- {
650- erase:: restore_val:: <queries:: $name:: Value <' tcx>>( value)
651- }
652642 }
653643
654644 /// Internal per-query plumbing for collecting the set of active jobs for this query.
@@ -702,12 +692,11 @@ macro_rules! define_queries {
702692 encoder: & mut CacheEncoder <' _, ' tcx>,
703693 query_result_index: & mut EncodedDepNodeIndex
704694 ) {
705- $crate:: plumbing:: encode_query_results :: <
706- query_impl :: $name :: QueryType < ' tcx> ,
695+ $crate:: plumbing:: encode_query_results_inner :: <
696+ VTableGetter ,
707697 _,
708698 _
709699 > (
710- query_impl:: $name:: QueryType :: query_dispatcher( tcx) ,
711700 tcx,
712701 encoder,
713702 query_result_index,
@@ -717,7 +706,7 @@ macro_rules! define_queries {
717706
718707 pub ( crate ) fn query_key_hash_verify<' tcx>( tcx: TyCtxt <' tcx>) {
719708 $crate:: plumbing:: query_key_hash_verify(
720- query_impl:: $name:: QueryType :: query_dispatcher( tcx) ,
709+ query_impl:: $name:: VTableGetter :: query_dispatcher( tcx) ,
721710 tcx,
722711 )
723712 }
@@ -793,8 +782,8 @@ macro_rules! define_queries {
793782 $(
794783 /// `DepKindVTable` constructor for this query.
795784 pub ( crate ) fn $name<' tcx>( ) -> DepKindVTable <' tcx> {
796- use $crate:: query_impl:: $name:: QueryType ;
797- make_dep_kind_vtable_for_query:: <QueryType < ' tcx> , _ , _>(
785+ use $crate:: query_impl:: $name:: VTableGetter ;
786+ make_dep_kind_vtable_for_query:: <VTableGetter , _>(
798787 is_eval_always!( [ $( $modifiers) * ] ) ,
799788 )
800789 }
0 commit comments