|
1 |
| -use crate::dep_graph::{self, dep_kind, DepNode}; |
| 1 | +use crate::dep_graph; |
2 | 2 | use crate::hir::exports::Export;
|
3 | 3 | use crate::hir::map;
|
4 | 4 | use crate::infer::canonical::{self, Canonical};
|
@@ -103,74 +103,6 @@ pub use self::profiling_support::{IntoSelfProfilingString, QueryKeyStringBuilder
|
103 | 103 |
|
104 | 104 | rustc_query_append! { [define_queries!][<'tcx>] }
|
105 | 105 |
|
106 |
| -/// The red/green evaluation system will try to mark a specific DepNode in the |
107 |
| -/// dependency graph as green by recursively trying to mark the dependencies of |
108 |
| -/// that `DepNode` as green. While doing so, it will sometimes encounter a `DepNode` |
109 |
| -/// where we don't know if it is red or green and we therefore actually have |
110 |
| -/// to recompute its value in order to find out. Since the only piece of |
111 |
| -/// information that we have at that point is the `DepNode` we are trying to |
112 |
| -/// re-evaluate, we need some way to re-run a query from just that. This is what |
113 |
| -/// `force_from_dep_node()` implements. |
114 |
| -/// |
115 |
| -/// In the general case, a `DepNode` consists of a `DepKind` and an opaque |
116 |
| -/// GUID/fingerprint that will uniquely identify the node. This GUID/fingerprint |
117 |
| -/// is usually constructed by computing a stable hash of the query-key that the |
118 |
| -/// `DepNode` corresponds to. Consequently, it is not in general possible to go |
119 |
| -/// back from hash to query-key (since hash functions are not reversible). For |
120 |
| -/// this reason `force_from_dep_node()` is expected to fail from time to time |
121 |
| -/// because we just cannot find out, from the `DepNode` alone, what the |
122 |
| -/// corresponding query-key is and therefore cannot re-run the query. |
123 |
| -/// |
124 |
| -/// The system deals with this case letting `try_mark_green` fail which forces |
125 |
| -/// the root query to be re-evaluated. |
126 |
| -/// |
127 |
| -/// Now, if `force_from_dep_node()` would always fail, it would be pretty useless. |
128 |
| -/// Fortunately, we can use some contextual information that will allow us to |
129 |
| -/// reconstruct query-keys for certain kinds of `DepNode`s. In particular, we |
130 |
| -/// enforce by construction that the GUID/fingerprint of certain `DepNode`s is a |
131 |
| -/// valid `DefPathHash`. Since we also always build a huge table that maps every |
132 |
| -/// `DefPathHash` in the current codebase to the corresponding `DefId`, we have |
133 |
| -/// everything we need to re-run the query. |
134 |
| -/// |
135 |
| -/// Take the `mir_promoted` query as an example. Like many other queries, it |
136 |
| -/// just has a single parameter: the `DefId` of the item it will compute the |
137 |
| -/// validated MIR for. Now, when we call `force_from_dep_node()` on a `DepNode` |
138 |
| -/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode` |
139 |
| -/// is actually a `DefPathHash`, and can therefore just look up the corresponding |
140 |
| -/// `DefId` in `tcx.def_path_hash_to_def_id`. |
141 |
| -/// |
142 |
| -/// When you implement a new query, it will likely have a corresponding new |
143 |
| -/// `DepKind`, and you'll have to support it here in `force_from_dep_node()`. As |
144 |
| -/// a rule of thumb, if your query takes a `DefId` or `LocalDefId` as sole parameter, |
145 |
| -/// then `force_from_dep_node()` should not fail for it. Otherwise, you can just |
146 |
| -/// add it to the "We don't have enough information to reconstruct..." group in |
147 |
| -/// the match below. |
148 |
| -pub fn force_from_dep_node<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool { |
149 |
| - // We must avoid ever having to call `force_from_dep_node()` for a |
150 |
| - // `DepNode::codegen_unit`: |
151 |
| - // Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we |
152 |
| - // would always end up having to evaluate the first caller of the |
153 |
| - // `codegen_unit` query that *is* reconstructible. This might very well be |
154 |
| - // the `compile_codegen_unit` query, thus re-codegenning the whole CGU just |
155 |
| - // to re-trigger calling the `codegen_unit` query with the right key. At |
156 |
| - // that point we would already have re-done all the work we are trying to |
157 |
| - // avoid doing in the first place. |
158 |
| - // The solution is simple: Just explicitly call the `codegen_unit` query for |
159 |
| - // each CGU, right after partitioning. This way `try_mark_green` will always |
160 |
| - // hit the cache instead of having to go through `force_from_dep_node`. |
161 |
| - // This assertion makes sure, we actually keep applying the solution above. |
162 |
| - debug_assert!( |
163 |
| - dep_node.kind != &dep_kind::codegen_unit, |
164 |
| - "calling force_from_dep_node() on DepKind::codegen_unit" |
165 |
| - ); |
166 |
| - |
167 |
| - dep_node.kind.force_from_dep_node(tcx, dep_node) |
168 |
| -} |
169 |
| - |
170 |
| -pub(crate) fn try_load_from_on_disk_cache<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) { |
171 |
| - dep_node.kind.try_load_from_on_disk_cache(tcx, dep_node) |
172 |
| -} |
173 |
| - |
174 | 106 | mod sealed {
|
175 | 107 | use super::{DefId, LocalDefId};
|
176 | 108 |
|
|
0 commit comments