@@ -63,11 +63,8 @@ use rustc_data_structures::fingerprint::Fingerprint;
63
63
use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId , CRATE_DEF_INDEX } ;
64
64
use rustc_hir:: definitions:: DefPathHash ;
65
65
use rustc_hir:: HirId ;
66
- use rustc_query_system:: dep_graph:: FingerprintStyle ;
66
+ use rustc_query_system:: dep_graph:: { DepKind , DepNode , DepNodeParams , FingerprintStyle } ;
67
67
use rustc_span:: symbol:: Symbol ;
68
- use std:: hash:: Hash ;
69
-
70
- pub use rustc_query_system:: dep_graph:: { DepContext , DepNodeParams } ;
71
68
72
69
/// This struct stores metadata about each DepKind.
73
70
///
@@ -89,6 +86,9 @@ pub struct DepKindStruct {
89
86
/// See [DepNodeParams] trait for the behaviour of each key type.
90
87
pub fingerprint_style : FingerprintStyle ,
91
88
89
+ /// Name of the query for pretty-printing.
90
+ pub label : & ' static str ,
91
+
92
92
/// The red/green evaluation system will try to mark a specific DepNode in the
93
93
/// dependency graph as green by recursively trying to mark the dependencies of
94
94
/// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
@@ -130,16 +130,21 @@ pub struct DepKindStruct {
130
130
pub try_load_from_on_disk_cache : Option < fn ( TyCtxt < ' _ > , DepNode ) > ,
131
131
}
132
132
133
- impl DepKind {
133
+ impl TyCtxt < ' _ > {
134
134
#[ inline( always) ]
135
- pub fn fingerprint_style ( self , tcx : TyCtxt < ' _ > ) -> FingerprintStyle {
135
+ crate fn query_fingerprint_style ( self , dep_kind : DepKind ) -> FingerprintStyle {
136
136
// Only fetch the DepKindStruct once.
137
- let data = tcx . query_kind ( self ) ;
137
+ let data = self . query_kind ( dep_kind ) ;
138
138
if data. is_anon {
139
139
return FingerprintStyle :: Opaque ;
140
140
}
141
141
data. fingerprint_style
142
142
}
143
+
144
+ #[ inline( always) ]
145
+ pub fn query_name ( self , dep_kind : DepKind ) -> & ' static str {
146
+ self . query_kind ( dep_kind) . label
147
+ }
143
148
}
144
149
145
150
macro_rules! define_dep_nodes {
@@ -151,38 +156,40 @@ macro_rules! define_dep_nodes {
151
156
) => (
152
157
#[ macro_export]
153
158
macro_rules! make_dep_kind_array {
154
- ( $mod: ident) => { [ $( $mod:: $variant( ) ) ,* ] } ;
159
+ ( $mod: ident) => { [ $mod :: NULL ( ) , $ ( $mod:: $variant( ) ) ,* ] } ;
155
160
}
156
161
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( ) } ) ; ) *
162
172
}
163
173
164
174
fn dep_kind_from_label_string( label: & str ) -> Result <DepKind , ( ) > {
165
175
match label {
166
- $( stringify!( $variant) => Ok ( DepKind :: $variant) , ) *
176
+ "NULL" => Ok ( dep_kind:: NULL ) ,
177
+ $( stringify!( $variant) => Ok ( dep_kind:: $variant) , ) *
167
178
_ => Err ( ( ) ) ,
168
179
}
169
180
}
170
181
171
182
/// Contains variant => str representations for constructing
172
183
/// DepNode groups for tests.
173
- #[ allow( dead_code , non_upper_case_globals) ]
184
+ #[ allow( non_upper_case_globals) ]
174
185
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) ; ) *
178
188
}
179
189
) ;
180
190
}
181
191
182
192
rustc_dep_node_append ! ( [ define_dep_nodes!] [ <' tcx>
183
- // We use this for most things when incr. comp. is turned off.
184
- [ ] Null ,
185
-
186
193
[ anon] TraitSelect ,
187
194
188
195
// 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>
196
203
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
197
204
// Be very careful changing this type signature!
198
205
crate 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)
200
207
}
201
208
202
209
// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
203
210
// Be very careful changing this type signature!
204
211
crate 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)
206
213
}
207
214
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
-
221
215
pub trait DepNodeExt : Sized {
222
216
/// Construct a DepNode from the given DepKind and DefPathHash. This
223
217
/// method will assert that the given DepKind actually requires a
@@ -252,7 +246,7 @@ impl DepNodeExt for DepNode {
252
246
/// method will assert that the given DepKind actually requires a
253
247
/// single DefId/DefPathHash parameter.
254
248
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 ) ;
256
250
DepNode { kind, hash : def_path_hash. 0 . into ( ) }
257
251
}
258
252
@@ -267,7 +261,7 @@ impl DepNodeExt for DepNode {
267
261
/// refers to something from the previous compilation session that
268
262
/// has been removed.
269
263
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 {
271
265
Some ( tcx. def_path_hash_to_def_id ( DefPathHash ( self . hash . into ( ) ) , & mut || {
272
266
panic ! ( "Failed to extract DefId: {:?} {}" , self . kind, self . hash)
273
267
} ) )
@@ -284,7 +278,7 @@ impl DepNodeExt for DepNode {
284
278
) -> Result < DepNode , ( ) > {
285
279
let kind = dep_kind_from_label_string ( label) ?;
286
280
287
- match kind . fingerprint_style ( tcx ) {
281
+ match tcx . query_fingerprint_style ( kind ) {
288
282
FingerprintStyle :: Opaque => Err ( ( ) ) ,
289
283
FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
290
284
FingerprintStyle :: DefPathHash => {
0 commit comments