@@ -17,6 +17,7 @@ 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:: { self , Erasable , Erased } ;
2021use rustc_middle:: query:: on_disk_cache:: {
2122 AbsoluteBytePos , CacheDecoder , CacheEncoder , EncodedDepNodeIndex ,
2223} ;
@@ -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 :: { QueryFlags , QueryVTableGetter } ;
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 , Value , Q , const FLAGS : QueryFlags > (
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+ Value : Erasable + Encodable < CacheEncoder < ' a , ' tcx > > ,
345+ Q : QueryVTableGetter < ' tcx , FLAGS > ,
346+ Q :: Cache : QueryCache < Value = Erased < Value > > ,
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,15 +359,16 @@ 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}
364366
365- pub ( crate ) fn query_key_hash_verify < ' tcx , C : QueryCache , const FLAGS : QueryFlags > (
366- query : SemiDynamicQueryDispatcher < ' tcx , C , FLAGS > ,
367- tcx : TyCtxt < ' tcx > ,
368- ) {
367+ pub ( crate ) fn query_key_hash_verify_inner < ' tcx , Q , const FLAGS : QueryFlags > ( tcx : TyCtxt < ' tcx > )
368+ where
369+ Q : QueryVTableGetter < ' tcx , FLAGS > ,
370+ {
371+ let query = Q :: query_dispatcher ( tcx) ;
369372 let _timer = tcx. prof . generic_activity_with_arg ( "query_key_hash_verify_for" , query. name ( ) ) ;
370373
371374 let cache = query. query_cache ( tcx) ;
@@ -389,19 +392,21 @@ pub(crate) fn query_key_hash_verify<'tcx, C: QueryCache, const FLAGS: QueryFlags
389392}
390393
391394/// Implementation of [`DepKindVTable::try_load_from_on_disk_cache`] for queries.
392- pub ( crate ) fn try_load_from_on_disk_cache_inner < ' tcx , C : QueryCache , const FLAGS : QueryFlags > (
393- query : SemiDynamicQueryDispatcher < ' tcx , C , FLAGS > ,
395+ pub ( crate ) fn try_load_from_on_disk_cache_inner < ' tcx , Q , const FLAGS : QueryFlags > (
394396 tcx : TyCtxt < ' tcx > ,
395397 dep_node : DepNode ,
396- ) {
398+ ) where
399+ Q : QueryVTableGetter < ' tcx , FLAGS > ,
400+ {
397401 debug_assert ! ( tcx. dep_graph. is_green( & dep_node) ) ;
398402
399- let key = C :: Key :: try_recover_key ( tcx, & dep_node) . unwrap_or_else ( || {
403+ let key = < Q :: Cache as QueryCache > :: Key :: try_recover_key ( tcx, & dep_node) . unwrap_or_else ( || {
400404 panic ! (
401405 "Failed to recover key for {dep_node:?} with key fingerprint {}" ,
402406 dep_node. key_fingerprint
403407 )
404408 } ) ;
409+ let query = Q :: query_dispatcher ( tcx) ;
405410 if query. will_cache_on_disk_for_key ( tcx, & key) {
406411 // Call `tcx.$query(key)` for its side-effect of loading the disk-cached
407412 // value into memory.
@@ -442,11 +447,14 @@ where
442447}
443448
444449/// Implementation of [`DepKindVTable::force_from_dep_node`] for queries.
445- pub ( crate ) fn force_from_dep_node_inner < ' tcx , C : QueryCache , const FLAGS : QueryFlags > (
446- query : SemiDynamicQueryDispatcher < ' tcx , C , FLAGS > ,
450+ pub ( crate ) fn force_from_dep_node_inner < ' tcx , Q , const FLAGS : QueryFlags > (
447451 tcx : TyCtxt < ' tcx > ,
448452 dep_node : DepNode ,
449- ) -> bool {
453+ _prev_index : SerializedDepNodeIndex , // Required by vtable but not used by queries
454+ ) -> bool
455+ where
456+ Q : QueryVTableGetter < ' tcx , FLAGS > ,
457+ {
450458 // We must avoid ever having to call `force_from_dep_node()` for a
451459 // `DepNode::codegen_unit`:
452460 // Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we
@@ -465,7 +473,8 @@ pub(crate) fn force_from_dep_node_inner<'tcx, C: QueryCache, const FLAGS: QueryF
465473 "calling force_from_dep_node() on dep_kinds::codegen_unit"
466474 ) ;
467475
468- if let Some ( key) = C :: Key :: try_recover_key ( tcx, & dep_node) {
476+ if let Some ( key) = <Q :: Cache as QueryCache >:: Key :: try_recover_key ( tcx, & dep_node) {
477+ let query = Q :: query_dispatcher ( tcx) ;
469478 force_query ( query, tcx, key, dep_node) ;
470479 true
471480 } else {
@@ -485,7 +494,6 @@ macro_rules! define_queries {
485494
486495 pub ( crate ) mod query_impl { $( pub ( crate ) mod $name {
487496 use super :: super :: * ;
488- use std:: marker:: PhantomData ;
489497 use :: rustc_middle:: query:: erase:: { self , Erased } ;
490498
491499 pub ( crate ) mod get_query_incr {
@@ -503,7 +511,7 @@ macro_rules! define_queries {
503511 #[ cfg( debug_assertions) ]
504512 let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered( ) ;
505513 execution:: get_query_incr(
506- QueryType :: query_dispatcher( tcx) ,
514+ VTableGetter :: query_dispatcher( tcx) ,
507515 tcx,
508516 span,
509517 key,
@@ -523,7 +531,7 @@ macro_rules! define_queries {
523531 __mode: QueryMode ,
524532 ) -> Option <Erased <queries:: $name:: Value <' tcx>>> {
525533 Some ( execution:: get_query_non_incr(
526- QueryType :: query_dispatcher( tcx) ,
534+ VTableGetter :: query_dispatcher( tcx) ,
527535 tcx,
528536 span,
529537 key,
@@ -616,39 +624,28 @@ macro_rules! define_queries {
616624 }
617625 }
618626
619- #[ derive( Copy , Clone , Default ) ]
620- pub ( crate ) struct QueryType <' tcx> {
621- data: PhantomData <& ' tcx ( ) >
622- }
623-
624627 const FLAGS : QueryFlags = QueryFlags {
625628 is_anon: is_anon!( [ $( $modifiers) * ] ) ,
626629 is_depth_limit: depth_limit!( [ $( $modifiers) * ] ) ,
627630 is_feedable: feedable!( [ $( $modifiers) * ] ) ,
628631 } ;
629632
630- impl <' tcx> QueryDispatcherUnerased <' tcx, queries:: $name:: Storage <' tcx>, FLAGS >
631- for QueryType <' tcx>
632- {
633- type UnerasedValue = queries:: $name:: Value <' tcx>;
633+ /// Marker type that implements [`QueryVTableGetter`] for this query.
634+ pub ( crate ) enum VTableGetter { }
635+
636+ impl <' tcx> QueryVTableGetter <' tcx, FLAGS > for VTableGetter {
637+ type Cache = queries:: $name:: Storage <' tcx>;
634638
635639 const NAME : & ' static & ' static str = & stringify!( $name) ;
636640
637641 #[ inline( always) ]
638642 fn query_dispatcher( tcx: TyCtxt <' tcx>)
639- -> SemiDynamicQueryDispatcher <' tcx, queries :: $name :: Storage < ' tcx> , FLAGS >
643+ -> SemiDynamicQueryDispatcher <' tcx, Self :: Cache , FLAGS >
640644 {
641645 SemiDynamicQueryDispatcher {
642646 vtable: & tcx. query_system. query_vtables. $name,
643647 }
644648 }
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- }
652649 }
653650
654651 /// Internal per-query plumbing for collecting the set of active jobs for this query.
@@ -702,12 +699,7 @@ macro_rules! define_queries {
702699 encoder: & mut CacheEncoder <' _, ' tcx>,
703700 query_result_index: & mut EncodedDepNodeIndex
704701 ) {
705- $crate:: plumbing:: encode_query_results:: <
706- query_impl:: $name:: QueryType <' tcx>,
707- _,
708- _
709- > (
710- query_impl:: $name:: QueryType :: query_dispatcher( tcx) ,
702+ $crate:: plumbing:: encode_query_results_inner:: <_, VTableGetter , _>(
711703 tcx,
712704 encoder,
713705 query_result_index,
@@ -716,10 +708,7 @@ macro_rules! define_queries {
716708 }
717709
718710 pub ( crate ) fn query_key_hash_verify<' tcx>( tcx: TyCtxt <' tcx>) {
719- $crate:: plumbing:: query_key_hash_verify(
720- query_impl:: $name:: QueryType :: query_dispatcher( tcx) ,
721- tcx,
722- )
711+ $crate:: plumbing:: query_key_hash_verify_inner:: <VTableGetter , _>( tcx)
723712 }
724713 } ) * }
725714
@@ -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