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,15 @@ 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+ /// True if this query has the `anon` modifier.
108+ pub anon : bool ,
109+ /// True if this query has the `eval_always` modifier.
107110 pub eval_always : bool ,
111+ /// True if this query has the `depth_limit` modifier.
112+ pub depth_limit : bool ,
113+ /// True if this query has the `feedable` modifier.
114+ pub feedable : bool ,
115+
108116 pub dep_kind : DepKind ,
109117 /// How this query deals with query cycle errors.
110118 pub cycle_error_handling : CycleErrorHandling ,
@@ -142,6 +150,85 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
142150 pub description_fn : fn ( TyCtxt < ' tcx > , C :: Key ) -> String ,
143151}
144152
153+ impl < ' tcx , C : QueryCache > fmt:: Debug for QueryVTable < ' tcx , C > {
154+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
155+ // When debug-printing a query vtable (e.g. for ICE or tracing),
156+ // just print the query name to know what query we're dealing with.
157+ // The other fields and flags are probably just unhelpful noise.
158+ //
159+ // If there is need for a more detailed dump of all flags and fields,
160+ // consider writing a separate dump method and calling it explicitly.
161+ f. write_str ( self . name )
162+ }
163+ }
164+
165+ impl < ' tcx , C : QueryCache > QueryVTable < ' tcx , C > {
166+ #[ inline( always) ]
167+ pub fn will_cache_on_disk_for_key ( & self , tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> bool {
168+ self . will_cache_on_disk_for_key_fn . map_or ( false , |f| f ( tcx, key) )
169+ }
170+
171+ // Don't use this method to access query results, instead use the methods on TyCtxt.
172+ #[ inline( always) ]
173+ pub fn query_state ( & self , tcx : TyCtxt < ' tcx > ) -> & ' tcx QueryState < ' tcx , C :: Key > {
174+ // Safety:
175+ // This is just manually doing the subfield referencing through pointer math.
176+ unsafe {
177+ & * ( & tcx. query_system . states as * const QueryStates < ' tcx > )
178+ . byte_add ( self . query_state )
179+ . cast :: < QueryState < ' tcx , C :: Key > > ( )
180+ }
181+ }
182+
183+ // Don't use this method to access query results, instead use the methods on TyCtxt.
184+ #[ inline( always) ]
185+ pub fn query_cache ( & self , tcx : TyCtxt < ' tcx > ) -> & ' tcx C {
186+ // Safety:
187+ // This is just manually doing the subfield referencing through pointer math.
188+ unsafe {
189+ & * ( & tcx. query_system . caches as * const QueryCaches < ' tcx > )
190+ . byte_add ( self . query_cache )
191+ . cast :: < C > ( )
192+ }
193+ }
194+
195+ #[ inline( always) ]
196+ pub fn try_load_from_disk (
197+ & self ,
198+ tcx : TyCtxt < ' tcx > ,
199+ key : & C :: Key ,
200+ prev_index : SerializedDepNodeIndex ,
201+ index : DepNodeIndex ,
202+ ) -> Option < C :: Value > {
203+ // `?` will return None immediately for queries that never cache to disk.
204+ self . try_load_from_disk_fn ?( tcx, key, prev_index, index)
205+ }
206+
207+ #[ inline]
208+ pub fn is_loadable_from_disk (
209+ & self ,
210+ tcx : TyCtxt < ' tcx > ,
211+ key : & C :: Key ,
212+ index : SerializedDepNodeIndex ,
213+ ) -> bool {
214+ self . is_loadable_from_disk_fn . map_or ( false , |f| f ( tcx, key, index) )
215+ }
216+
217+ /// Synthesize an error value to let compilation continue after a cycle.
218+ pub fn value_from_cycle_error (
219+ & self ,
220+ tcx : TyCtxt < ' tcx > ,
221+ cycle_error : & CycleError ,
222+ guar : ErrorGuaranteed ,
223+ ) -> C :: Value {
224+ ( self . value_from_cycle_error ) ( tcx, cycle_error, guar)
225+ }
226+
227+ pub fn construct_dep_node ( & self , tcx : TyCtxt < ' tcx > , key : & C :: Key ) -> DepNode {
228+ DepNode :: construct ( tcx, self . dep_kind , key)
229+ }
230+ }
231+
145232pub struct QuerySystemFns {
146233 pub engine : QueryEngine ,
147234 pub local_providers : Providers ,
0 commit comments