@@ -43,6 +43,7 @@ use crate::ty::subst::{GenericArg, SubstsRef};
4343use crate :: ty:: util:: AlwaysRequiresDrop ;
4444use crate :: ty:: GeneratorDiagnosticData ;
4545use crate :: ty:: { self , CrateInherentImpls , ParamEnvAnd , Ty , TyCtxt , UnusedGenericParams } ;
46+ use field_offset:: FieldOffset ;
4647use measureme:: StringId ;
4748use rustc_arena:: TypedArena ;
4849use rustc_ast as ast;
@@ -66,9 +67,12 @@ use rustc_hir::hir_id::OwnerId;
6667use rustc_hir:: lang_items:: { LangItem , LanguageItems } ;
6768use rustc_hir:: { Crate , ItemLocalId , TraitCandidate } ;
6869use rustc_index:: IndexVec ;
70+ use rustc_query_system:: dep_graph:: DepNodeIndex ;
71+ use rustc_query_system:: dep_graph:: SerializedDepNodeIndex ;
6972use rustc_query_system:: ich:: StableHashingContext ;
7073pub ( crate ) use rustc_query_system:: query:: QueryJobId ;
7174use rustc_query_system:: query:: * ;
75+ use rustc_query_system:: HandleCycleError ;
7276use rustc_session:: config:: { EntryFnType , OptLevel , OutputFilenames , SymbolManglingVersion } ;
7377use rustc_session:: cstore:: { CrateDepKind , CrateSource } ;
7478use rustc_session:: cstore:: { ExternCrate , ForeignModule , LinkagePreference , NativeLib } ;
@@ -78,8 +82,6 @@ use rustc_span::symbol::Symbol;
7882use rustc_span:: { Span , DUMMY_SP } ;
7983use rustc_target:: abi;
8084use rustc_target:: spec:: PanicStrategy ;
81-
82- use std:: marker:: PhantomData ;
8385use std:: mem;
8486use std:: ops:: Deref ;
8587use std:: path:: PathBuf ;
@@ -103,6 +105,31 @@ pub struct QueryStruct<'tcx> {
103105 Option < fn ( TyCtxt < ' tcx > , & mut CacheEncoder < ' _ , ' tcx > , & mut EncodedDepNodeIndex ) > ,
104106}
105107
108+ pub struct DynamicQuery < ' tcx , C : QueryCache > {
109+ pub name : & ' static str ,
110+ pub eval_always : bool ,
111+ pub dep_kind : rustc_middle:: dep_graph:: DepKind ,
112+ pub handle_cycle_error : HandleCycleError ,
113+ pub query_state : FieldOffset < QueryStates < ' tcx > , QueryState < C :: Key , crate :: dep_graph:: DepKind > > ,
114+ pub query_cache : FieldOffset < QueryCaches < ' tcx > , C > ,
115+ pub cache_on_disk : fn ( tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> bool ,
116+ pub execute_query : fn ( tcx : TyCtxt < ' tcx > , k : C :: Key ) -> C :: Value ,
117+ pub compute : fn ( tcx : TyCtxt < ' tcx > , key : C :: Key ) -> C :: Value ,
118+ pub can_load_from_disk : bool ,
119+ pub try_load_from_disk : fn (
120+ tcx : TyCtxt < ' tcx > ,
121+ key : & C :: Key ,
122+ prev_index : SerializedDepNodeIndex ,
123+ index : DepNodeIndex ,
124+ ) -> Option < C :: Value > ,
125+ pub loadable_from_disk :
126+ fn ( tcx : TyCtxt < ' tcx > , key : & C :: Key , index : SerializedDepNodeIndex ) -> bool ,
127+ pub hash_result : HashResult < C :: Value > ,
128+ pub value_from_cycle_error :
129+ fn ( tcx : TyCtxt < ' tcx > , cycle : & [ QueryInfo < crate :: dep_graph:: DepKind > ] ) -> C :: Value ,
130+ pub format_value : fn ( & C :: Value ) -> String ,
131+ }
132+
106133pub struct QuerySystemFns < ' tcx > {
107134 pub engine : QueryEngine ,
108135 pub local_providers : Providers ,
@@ -120,6 +147,7 @@ pub struct QuerySystem<'tcx> {
120147 pub states : QueryStates < ' tcx > ,
121148 pub arenas : QueryArenas < ' tcx > ,
122149 pub caches : QueryCaches < ' tcx > ,
150+ pub dynamic_queries : DynamicQueries < ' tcx > ,
123151
124152 /// This provides access to the incremental compilation on-disk cache for query results.
125153 /// Do not access this directly. It is only meant to be used by
@@ -130,23 +158,6 @@ pub struct QuerySystem<'tcx> {
130158 pub fns : QuerySystemFns < ' tcx > ,
131159
132160 pub jobs : AtomicU64 ,
133-
134- // Since we erase query value types we tell the typesystem about them with `PhantomData`.
135- _phantom_values : QueryPhantomValues < ' tcx > ,
136- }
137-
138- impl < ' tcx > QuerySystem < ' tcx > {
139- pub fn new ( fns : QuerySystemFns < ' tcx > , on_disk_cache : Option < OnDiskCache < ' tcx > > ) -> Self {
140- QuerySystem {
141- states : Default :: default ( ) ,
142- arenas : Default :: default ( ) ,
143- caches : Default :: default ( ) ,
144- on_disk_cache,
145- fns,
146- jobs : AtomicU64 :: new ( 1 ) ,
147- _phantom_values : Default :: default ( ) ,
148- }
149- }
150161}
151162
152163#[ derive( Copy , Clone ) ]
@@ -427,11 +438,6 @@ macro_rules! define_callbacks {
427438 }
428439 }
429440
430- #[ derive( Default ) ]
431- pub struct QueryPhantomValues <' tcx> {
432- $( $( #[ $attr] ) * pub $name: PhantomData <query_values:: $name<' tcx>>, ) *
433- }
434-
435441 #[ derive( Default ) ]
436442 pub struct QueryCaches <' tcx> {
437443 $( $( #[ $attr] ) * pub $name: query_storage:: $name<' tcx>, ) *
@@ -490,6 +496,12 @@ macro_rules! define_callbacks {
490496 } ) *
491497 }
492498
499+ pub struct DynamicQueries <' tcx> {
500+ $(
501+ pub $name: DynamicQuery <' tcx, query_storage:: $name<' tcx>>,
502+ ) *
503+ }
504+
493505 #[ derive( Default ) ]
494506 pub struct QueryStates <' tcx> {
495507 $(
0 commit comments