@@ -69,79 +69,6 @@ use std::hash::Hash;
69
69
70
70
pub use rustc_query_system:: dep_graph:: { DepContext , DepNodeParams } ;
71
71
72
- /// This struct stores metadata about each DepKind.
73
- ///
74
- /// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
75
- /// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
76
- /// jump table instead of large matches.
77
- pub struct DepKindStruct < ' tcx > {
78
- /// Anonymous queries cannot be replayed from one compiler invocation to the next.
79
- /// When their result is needed, it is recomputed. They are useful for fine-grained
80
- /// dependency tracking, and caching within one compiler invocation.
81
- pub is_anon : bool ,
82
-
83
- /// Eval-always queries do not track their dependencies, and are always recomputed, even if
84
- /// their inputs have not changed since the last compiler invocation. The result is still
85
- /// cached within one compiler invocation.
86
- pub is_eval_always : bool ,
87
-
88
- /// Whether the query key can be recovered from the hashed fingerprint.
89
- /// See [DepNodeParams] trait for the behaviour of each key type.
90
- pub fingerprint_style : FingerprintStyle ,
91
-
92
- /// The red/green evaluation system will try to mark a specific DepNode in the
93
- /// dependency graph as green by recursively trying to mark the dependencies of
94
- /// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
95
- /// where we don't know if it is red or green and we therefore actually have
96
- /// to recompute its value in order to find out. Since the only piece of
97
- /// information that we have at that point is the `DepNode` we are trying to
98
- /// re-evaluate, we need some way to re-run a query from just that. This is what
99
- /// `force_from_dep_node()` implements.
100
- ///
101
- /// In the general case, a `DepNode` consists of a `DepKind` and an opaque
102
- /// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint
103
- /// is usually constructed by computing a stable hash of the query-key that the
104
- /// `DepNode` corresponds to. Consequently, it is not in general possible to go
105
- /// back from hash to query-key (since hash functions are not reversible). For
106
- /// this reason `force_from_dep_node()` is expected to fail from time to time
107
- /// because we just cannot find out, from the `DepNode` alone, what the
108
- /// corresponding query-key is and therefore cannot re-run the query.
109
- ///
110
- /// The system deals with this case letting `try_mark_green` fail which forces
111
- /// the root query to be re-evaluated.
112
- ///
113
- /// Now, if `force_from_dep_node()` would always fail, it would be pretty useless.
114
- /// Fortunately, we can use some contextual information that will allow us to
115
- /// reconstruct query-keys for certain kinds of `DepNode`s. In particular, we
116
- /// enforce by construction that the GUID/fingerprint of certain `DepNode`s is a
117
- /// valid `DefPathHash`. Since we also always build a huge table that maps every
118
- /// `DefPathHash` in the current codebase to the corresponding `DefId`, we have
119
- /// everything we need to re-run the query.
120
- ///
121
- /// Take the `mir_promoted` query as an example. Like many other queries, it
122
- /// just has a single parameter: the `DefId` of the item it will compute the
123
- /// validated MIR for. Now, when we call `force_from_dep_node()` on a `DepNode`
124
- /// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
125
- /// is actually a `DefPathHash`, and can therefore just look up the corresponding
126
- /// `DefId` in `tcx.def_path_hash_to_def_id`.
127
- pub force_from_dep_node : Option < fn ( tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool > ,
128
-
129
- /// Invoke a query to put the on-disk cached value in memory.
130
- pub try_load_from_on_disk_cache : Option < fn ( TyCtxt < ' tcx > , DepNode ) > ,
131
- }
132
-
133
- impl DepKind {
134
- #[ inline( always) ]
135
- pub fn fingerprint_style ( self , tcx : TyCtxt < ' _ > ) -> FingerprintStyle {
136
- // Only fetch the DepKindStruct once.
137
- let data = tcx. query_kind ( self ) ;
138
- if data. is_anon {
139
- return FingerprintStyle :: Opaque ;
140
- }
141
- data. fingerprint_style
142
- }
143
- }
144
-
145
72
macro_rules! define_dep_nodes {
146
73
(
147
74
$( $( #[ $attr: meta] ) *
@@ -159,7 +86,7 @@ macro_rules! define_dep_nodes {
159
86
$( $( #[ $attr] ) * $variant) ,*
160
87
}
161
88
162
- fn dep_kind_from_label_string( label: & str ) -> Result <DepKind , ( ) > {
89
+ pub ( super ) fn dep_kind_from_label_string( label: & str ) -> Result <DepKind , ( ) > {
163
90
match label {
164
91
$( stringify!( $variant) => Ok ( DepKind :: $variant) , ) *
165
92
_ => Err ( ( ) ) ,
@@ -214,11 +141,6 @@ static_assert_size!(DepNode, 18);
214
141
static_assert_size ! ( DepNode , 24 ) ;
215
142
216
143
pub trait DepNodeExt : Sized {
217
- /// Construct a DepNode from the given DepKind and DefPathHash. This
218
- /// method will assert that the given DepKind actually requires a
219
- /// single DefId/DefPathHash parameter.
220
- fn from_def_path_hash ( tcx : TyCtxt < ' _ > , def_path_hash : DefPathHash , kind : DepKind ) -> Self ;
221
-
222
144
/// Extracts the DefId corresponding to this DepNode. This will work
223
145
/// if two conditions are met:
224
146
///
@@ -243,14 +165,6 @@ pub trait DepNodeExt: Sized {
243
165
}
244
166
245
167
impl DepNodeExt for DepNode {
246
- /// Construct a DepNode from the given DepKind and DefPathHash. This
247
- /// method will assert that the given DepKind actually requires a
248
- /// single DefId/DefPathHash parameter.
249
- fn from_def_path_hash ( tcx : TyCtxt < ' _ > , def_path_hash : DefPathHash , kind : DepKind ) -> DepNode {
250
- debug_assert ! ( kind. fingerprint_style( tcx) == FingerprintStyle :: DefPathHash ) ;
251
- DepNode { kind, hash : def_path_hash. 0 . into ( ) }
252
- }
253
-
254
168
/// Extracts the DefId corresponding to this DepNode. This will work
255
169
/// if two conditions are met:
256
170
///
@@ -262,7 +176,7 @@ impl DepNodeExt for DepNode {
262
176
/// refers to something from the previous compilation session that
263
177
/// has been removed.
264
178
fn extract_def_id < ' tcx > ( & self , tcx : TyCtxt < ' tcx > ) -> Option < DefId > {
265
- if self . kind . fingerprint_style ( tcx ) == FingerprintStyle :: DefPathHash {
179
+ if tcx . fingerprint_style ( self . kind ) == FingerprintStyle :: DefPathHash {
266
180
Some ( tcx. def_path_hash_to_def_id ( DefPathHash ( self . hash . into ( ) ) , & mut || {
267
181
panic ! ( "Failed to extract DefId: {:?} {}" , self . kind, self . hash)
268
182
} ) )
@@ -279,7 +193,7 @@ impl DepNodeExt for DepNode {
279
193
) -> Result < DepNode , ( ) > {
280
194
let kind = dep_kind_from_label_string ( label) ?;
281
195
282
- match kind . fingerprint_style ( tcx ) {
196
+ match tcx . fingerprint_style ( kind ) {
283
197
FingerprintStyle :: Opaque => Err ( ( ) ) ,
284
198
FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
285
199
FingerprintStyle :: DefPathHash => {
0 commit comments