1- use std:: fmt:: Debug ;
1+ use std:: fmt;
22use std:: ops:: Deref ;
33
44use rustc_data_structures:: fingerprint:: Fingerprint ;
@@ -12,7 +12,7 @@ use rustc_span::{ErrorGuaranteed, Span};
1212pub use sealed:: IntoQueryParam ;
1313
1414use crate :: dep_graph;
15- use crate :: dep_graph:: { DepKind , DepNodeIndex , SerializedDepNodeIndex } ;
15+ use crate :: dep_graph:: { DepKind , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
1616use crate :: ich:: StableHashingContext ;
1717use crate :: queries:: {
1818 ExternProviders , PerQueryVTables , Providers , QueryArenas , QueryCaches , QueryEngine , QueryStates ,
@@ -104,7 +104,16 @@ pub enum QueryMode {
104104/// Stores function pointers and other metadata for a particular query.
105105pub struct QueryVTable < ' tcx , C : QueryCache > {
106106 pub name : & ' static str ,
107+
108+ /// True if this query has the `anon` modifier.
109+ pub anon : bool ,
110+ /// True if this query has the `eval_always` modifier.
107111 pub eval_always : bool ,
112+ /// True if this query has the `depth_limit` modifier.
113+ pub depth_limit : bool ,
114+ /// True if this query has the `feedable` modifier.
115+ pub feedable : bool ,
116+
108117 pub dep_kind : DepKind ,
109118 /// How this query deals with query cycle errors.
110119 pub cycle_error_handling : CycleErrorHandling ,
@@ -142,6 +151,85 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
142151 pub description_fn : fn ( TyCtxt < ' tcx > , C :: Key ) -> String ,
143152}
144153
154+ impl < ' tcx , C : QueryCache > fmt:: Debug for QueryVTable < ' tcx , C > {
155+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
156+ // When debug-printing a query vtable (e.g. for ICE or tracing),
157+ // just print the query name to know what query we're dealing with.
158+ // The other fields and flags are probably just unhelpful noise.
159+ //
160+ // If there is need for a more detailed dump of all flags and fields,
161+ // consider writing a separate dump method and calling it explicitly.
162+ f. write_str ( self . name )
163+ }
164+ }
165+
166+ impl < ' tcx , C : QueryCache > QueryVTable < ' tcx , C > {
167+ #[ inline( always) ]
168+ pub fn will_cache_on_disk_for_key ( & self , tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> bool {
169+ self . will_cache_on_disk_for_key_fn . map_or ( false , |f| f ( tcx, key) )
170+ }
171+
172+ // Don't use this method to access query results, instead use the methods on TyCtxt.
173+ #[ inline( always) ]
174+ pub fn query_state ( & self , tcx : TyCtxt < ' tcx > ) -> & ' tcx QueryState < ' tcx , C :: Key > {
175+ // Safety:
176+ // This is just manually doing the subfield referencing through pointer math.
177+ unsafe {
178+ & * ( & tcx. query_system . states as * const QueryStates < ' tcx > )
179+ . byte_add ( self . query_state )
180+ . cast :: < QueryState < ' tcx , C :: Key > > ( )
181+ }
182+ }
183+
184+ // Don't use this method to access query results, instead use the methods on TyCtxt.
185+ #[ inline( always) ]
186+ pub fn query_cache ( & self , tcx : TyCtxt < ' tcx > ) -> & ' tcx C {
187+ // Safety:
188+ // This is just manually doing the subfield referencing through pointer math.
189+ unsafe {
190+ & * ( & tcx. query_system . caches as * const QueryCaches < ' tcx > )
191+ . byte_add ( self . query_cache )
192+ . cast :: < C > ( )
193+ }
194+ }
195+
196+ #[ inline( always) ]
197+ pub fn try_load_from_disk (
198+ & self ,
199+ tcx : TyCtxt < ' tcx > ,
200+ key : & C :: Key ,
201+ prev_index : SerializedDepNodeIndex ,
202+ index : DepNodeIndex ,
203+ ) -> Option < C :: Value > {
204+ // `?` will return None immediately for queries that never cache to disk.
205+ self . try_load_from_disk_fn ?( tcx, key, prev_index, index)
206+ }
207+
208+ #[ inline]
209+ pub fn is_loadable_from_disk (
210+ & self ,
211+ tcx : TyCtxt < ' tcx > ,
212+ key : & C :: Key ,
213+ index : SerializedDepNodeIndex ,
214+ ) -> bool {
215+ self . is_loadable_from_disk_fn . map_or ( false , |f| f ( tcx, key, index) )
216+ }
217+
218+ /// Synthesize an error value to let compilation continue after a cycle.
219+ pub fn value_from_cycle_error (
220+ & self ,
221+ tcx : TyCtxt < ' tcx > ,
222+ cycle_error : & CycleError ,
223+ guar : ErrorGuaranteed ,
224+ ) -> C :: Value {
225+ ( self . value_from_cycle_error ) ( tcx, cycle_error, guar)
226+ }
227+
228+ pub fn construct_dep_node ( & self , tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> DepNode {
229+ DepNode :: construct ( tcx, self . dep_kind , key)
230+ }
231+ }
232+
145233pub struct QuerySystemFns {
146234 pub engine : QueryEngine ,
147235 pub local_providers : Providers ,
0 commit comments