Skip to content

Commit 93a0fb1

Browse files
committed
Move DepKindStruct from rustc_middle to rustc_query_system
1 parent 4652f5e commit 93a0fb1

File tree

4 files changed

+65
-63
lines changed

4 files changed

+65
-63
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

-61
Original file line numberDiff line numberDiff line change
@@ -69,67 +69,6 @@ use std::hash::Hash;
6969

7070
pub use rustc_query_system::dep_graph::{DepContext, DepNodeParams};
7171

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-
13372
impl DepKind {
13473
#[inline(always)]
13574
pub fn fingerprint_style(self, tcx: TyCtxt<'_>) -> FingerprintStyle {

compiler/rustc_middle/src/dep_graph/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ pub use rustc_query_system::dep_graph::{
1111
SerializedDepNodeIndex, WorkProduct, WorkProductId,
1212
};
1313

14-
pub use dep_node::{label_strs, DepKind, DepKindStruct, DepNode, DepNodeExt};
14+
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
1515
pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
1616

1717
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
18+
1819
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
1920
pub type TaskDepsRef<'a> = rustc_query_system::dep_graph::TaskDepsRef<'a, DepKind>;
2021
pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
2122
pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
2223
pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;
24+
pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
2325

2426
impl rustc_query_system::dep_graph::DepKind for DepKind {
2527
const NULL: Self = DepKind::Null;

compiler/rustc_query_system/src/dep_graph/dep_node.rs

+61
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,67 @@ where
149149
}
150150
}
151151

152+
/// This struct stores metadata about each DepKind.
153+
///
154+
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
155+
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
156+
/// jump table instead of large matches.
157+
pub struct DepKindStruct<CTX: DepContext> {
158+
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
159+
/// When their result is needed, it is recomputed. They are useful for fine-grained
160+
/// dependency tracking, and caching within one compiler invocation.
161+
pub is_anon: bool,
162+
163+
/// Eval-always queries do not track their dependencies, and are always recomputed, even if
164+
/// their inputs have not changed since the last compiler invocation. The result is still
165+
/// cached within one compiler invocation.
166+
pub is_eval_always: bool,
167+
168+
/// Whether the query key can be recovered from the hashed fingerprint.
169+
/// See [DepNodeParams] trait for the behaviour of each key type.
170+
pub fingerprint_style: FingerprintStyle,
171+
172+
/// The red/green evaluation system will try to mark a specific DepNode in the
173+
/// dependency graph as green by recursively trying to mark the dependencies of
174+
/// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode`
175+
/// where we don't know if it is red or green and we therefore actually have
176+
/// to recompute its value in order to find out. Since the only piece of
177+
/// information that we have at that point is the `DepNode` we are trying to
178+
/// re-evaluate, we need some way to re-run a query from just that. This is what
179+
/// `force_from_dep_node()` implements.
180+
///
181+
/// In the general case, a `DepNode` consists of a `DepKind` and an opaque
182+
/// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint
183+
/// is usually constructed by computing a stable hash of the query-key that the
184+
/// `DepNode` corresponds to. Consequently, it is not in general possible to go
185+
/// back from hash to query-key (since hash functions are not reversible). For
186+
/// this reason `force_from_dep_node()` is expected to fail from time to time
187+
/// because we just cannot find out, from the `DepNode` alone, what the
188+
/// corresponding query-key is and therefore cannot re-run the query.
189+
///
190+
/// The system deals with this case letting `try_mark_green` fail which forces
191+
/// the root query to be re-evaluated.
192+
///
193+
/// Now, if `force_from_dep_node()` would always fail, it would be pretty useless.
194+
/// Fortunately, we can use some contextual information that will allow us to
195+
/// reconstruct query-keys for certain kinds of `DepNode`s. In particular, we
196+
/// enforce by construction that the GUID/fingerprint of certain `DepNode`s is a
197+
/// valid `DefPathHash`. Since we also always build a huge table that maps every
198+
/// `DefPathHash` in the current codebase to the corresponding `DefId`, we have
199+
/// everything we need to re-run the query.
200+
///
201+
/// Take the `mir_promoted` query as an example. Like many other queries, it
202+
/// just has a single parameter: the `DefId` of the item it will compute the
203+
/// validated MIR for. Now, when we call `force_from_dep_node()` on a `DepNode`
204+
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
205+
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
206+
/// `DefId` in `tcx.def_path_hash_to_def_id`.
207+
pub force_from_dep_node: Option<fn(tcx: CTX, dep_node: DepNode<CTX::DepKind>) -> bool>,
208+
209+
/// Invoke a query to put the on-disk cached value in memory.
210+
pub try_load_from_on_disk_cache: Option<fn(CTX, DepNode<CTX::DepKind>)>,
211+
}
212+
152213
/// A "work product" corresponds to a `.o` (or other) file that we
153214
/// save in between runs. These IDs do not have a `DefId` but rather
154215
/// some independent path or string that persists between runs without

compiler/rustc_query_system/src/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod graph;
44
mod query;
55
mod serialized;
66

7-
pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
7+
pub use dep_node::{DepKindStruct, DepNode, DepNodeParams, WorkProductId};
88
pub use graph::{
99
hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, TaskDepsRef, WorkProduct,
1010
};

0 commit comments

Comments
 (0)