@@ -63,11 +63,8 @@ use rustc_data_structures::fingerprint::Fingerprint;
6363use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_INDEX } ;
6464use rustc_hir:: definitions:: DefPathHash ;
6565use rustc_hir:: HirId ;
66- use rustc_query_system:: dep_graph:: FingerprintStyle ;
66+ use rustc_query_system:: dep_graph:: { DepKind , DepNode , DepNodeParams , FingerprintStyle } ;
6767use rustc_span:: symbol:: Symbol ;
68- use std:: hash:: Hash ;
69-
70- pub use rustc_query_system:: dep_graph:: { DepContext , DepNodeParams } ;
7168
7269/// This struct stores metadata about each DepKind.
7370///
@@ -89,6 +86,9 @@ pub struct DepKindStruct {
8986 /// See [DepNodeParams] trait for the behaviour of each key type.
9087 pub fingerprint_style : FingerprintStyle ,
9188
89+ /// Name of the query for pretty-printing.
90+ pub label : & ' static str ,
91+
9292 /// The red/green evaluation system will try to mark a specific DepNode in the
9393 /// dependency graph as green by recursively trying to mark the dependencies of
9494 /// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
@@ -130,16 +130,21 @@ pub struct DepKindStruct {
130130 pub try_load_from_on_disk_cache : Option < fn ( TyCtxt < ' _ > , DepNode ) > ,
131131}
132132
133- impl DepKind {
133+ impl TyCtxt < ' _ > {
134134 #[ inline( always) ]
135- pub fn fingerprint_style ( self , tcx : TyCtxt < ' _ > ) -> FingerprintStyle {
135+ crate fn query_fingerprint_style ( self , dep_kind : DepKind ) -> FingerprintStyle {
136136 // Only fetch the DepKindStruct once.
137- let data = tcx . query_kind ( self ) ;
137+ let data = self . query_kind ( dep_kind ) ;
138138 if data. is_anon {
139139 return FingerprintStyle :: Opaque ;
140140 }
141141 data. fingerprint_style
142142 }
143+
144+ #[ inline( always) ]
145+ pub fn query_name ( self , dep_kind : DepKind ) -> & ' static str {
146+ self . query_kind ( dep_kind) . label
147+ }
143148}
144149
145150macro_rules! define_dep_nodes {
@@ -151,38 +156,40 @@ macro_rules! define_dep_nodes {
151156 ) => (
152157 #[ macro_export]
153158 macro_rules! make_dep_kind_array {
154- ( $mod: ident) => { [ $( $mod:: $variant( ) ) ,* ] } ;
159+ ( $mod: ident) => { [ $mod :: NULL ( ) , $ ( $mod:: $variant( ) ) ,* ] } ;
155160 }
156161
157- /// This enum serves as an index into arrays built by `make_dep_kind_array`.
158- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , Encodable , Decodable ) ]
159- #[ allow( non_camel_case_types) ]
160- pub enum DepKind {
161- $( $variant) ,*
162+ /// Definition of the `DepKind`s for the known queries.
163+ /// The constants are indices in the arrays produced by `make_dep_kind_array`,
164+ /// and should be kept in sync.
165+ #[ allow( non_upper_case_globals) ]
166+ pub mod dep_kind {
167+ use super :: DepKind ;
168+
169+ /// We use this for most things when incr. comp. is turned off.
170+ pub const NULL : DepKind = DepKind :: NULL ;
171+ $( pub const $variant: DepKind = DepKind :: new( 1 + ${ index( ) } ) ; ) *
162172 }
163173
164174 fn dep_kind_from_label_string( label: & str ) -> Result <DepKind , ( ) > {
165175 match label {
166- $( stringify!( $variant) => Ok ( DepKind :: $variant) , ) *
176+ "NULL" => Ok ( dep_kind:: NULL ) ,
177+ $( stringify!( $variant) => Ok ( dep_kind:: $variant) , ) *
167178 _ => Err ( ( ) ) ,
168179 }
169180 }
170181
171182 /// Contains variant => str representations for constructing
172183 /// DepNode groups for tests.
173- #[ allow( dead_code , non_upper_case_globals) ]
184+ #[ allow( non_upper_case_globals) ]
174185 pub mod label_strs {
175- $(
176- pub const $variant: & str = stringify!( $variant) ;
177- ) *
186+ pub const NULL : & str = "NULL" ;
187+ $( pub const $variant: & str = stringify!( $variant) ; ) *
178188 }
179189 ) ;
180190}
181191
182192rustc_dep_node_append ! ( [ define_dep_nodes!] [ <' tcx>
183- // We use this for most things when incr. comp. is turned off.
184- [ ] Null ,
185-
186193 [ anon] TraitSelect ,
187194
188195 // WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
@@ -196,28 +203,15 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
196203// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
197204// Be very careful changing this type signature!
198205crate fn make_compile_codegen_unit ( tcx : TyCtxt < ' _ > , name : Symbol ) -> DepNode {
199- DepNode :: construct ( tcx, DepKind :: CompileCodegenUnit , & name)
206+ DepNode :: construct ( tcx, dep_kind :: CompileCodegenUnit , & name)
200207}
201208
202209// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
203210// Be very careful changing this type signature!
204211crate fn make_compile_mono_item < ' tcx > ( tcx : TyCtxt < ' tcx > , mono_item : & MonoItem < ' tcx > ) -> DepNode {
205- DepNode :: construct ( tcx, DepKind :: CompileMonoItem , mono_item)
212+ DepNode :: construct ( tcx, dep_kind :: CompileMonoItem , mono_item)
206213}
207214
208- pub type DepNode = rustc_query_system:: dep_graph:: DepNode < DepKind > ;
209-
210- // We keep a lot of `DepNode`s in memory during compilation. It's not
211- // required that their size stay the same, but we don't want to change
212- // it inadvertently. This assert just ensures we're aware of any change.
213- #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
214- static_assert_size ! ( DepNode , 18 ) ;
215-
216- #[ cfg( not( any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
217- static_assert_size ! ( DepNode , 24 ) ;
218-
219- static_assert_size ! ( DepKind , 2 ) ;
220-
221215pub trait DepNodeExt : Sized {
222216 /// Construct a DepNode from the given DepKind and DefPathHash. This
223217 /// method will assert that the given DepKind actually requires a
@@ -252,7 +246,7 @@ impl DepNodeExt for DepNode {
252246 /// method will assert that the given DepKind actually requires a
253247 /// single DefId/DefPathHash parameter.
254248 fn from_def_path_hash ( tcx : TyCtxt < ' _ > , def_path_hash : DefPathHash , kind : DepKind ) -> DepNode {
255- debug_assert ! ( kind . fingerprint_style ( tcx ) == FingerprintStyle :: DefPathHash ) ;
249+ debug_assert ! ( tcx . query_fingerprint_style ( kind ) == FingerprintStyle :: DefPathHash ) ;
256250 DepNode { kind, hash : def_path_hash. 0 . into ( ) }
257251 }
258252
@@ -267,7 +261,7 @@ impl DepNodeExt for DepNode {
267261 /// refers to something from the previous compilation session that
268262 /// has been removed.
269263 fn extract_def_id < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Option < DefId > {
270- if self . kind . fingerprint_style ( tcx ) == FingerprintStyle :: DefPathHash {
264+ if tcx . query_fingerprint_style ( self . kind ) == FingerprintStyle :: DefPathHash {
271265 Some ( tcx. def_path_hash_to_def_id ( DefPathHash ( self . hash . into ( ) ) , & mut || {
272266 panic ! ( "Failed to extract DefId: {:?} {}" , self . kind, self . hash)
273267 } ) )
@@ -284,7 +278,7 @@ impl DepNodeExt for DepNode {
284278 ) -> Result < DepNode , ( ) > {
285279 let kind = dep_kind_from_label_string ( label) ?;
286280
287- match kind . fingerprint_style ( tcx ) {
281+ match tcx . query_fingerprint_style ( kind ) {
288282 FingerprintStyle :: Opaque => Err ( ( ) ) ,
289283 FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
290284 FingerprintStyle :: DefPathHash => {
0 commit comments