|
12 | 12 | //! that generate the actual methods on tcx which find and execute the
|
13 | 13 | //! provider, manage the caches, and so forth.
|
14 | 14 |
|
15 |
| -use dep_graph::{DepNodeIndex, DepNode, DepKind}; |
| 15 | +use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor}; |
16 | 16 | use errors::{Diagnostic, DiagnosticBuilder};
|
17 | 17 | use ty::{TyCtxt};
|
18 | 18 | use ty::maps::Query; // NB: actually generated by the macros in this file
|
@@ -133,6 +133,40 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
133 | 133 |
|
134 | 134 | Ok(result)
|
135 | 135 | }
|
| 136 | + |
| 137 | + /// Try to read a node index for the node dep_node. |
| 138 | + /// A node will have an index, when it's already been marked green, or when we can mark it |
| 139 | + /// green. This function will mark the current task as a reader of the specified node, when |
| 140 | + /// the a node index can be found for that node. |
| 141 | + pub(super) fn try_mark_green_and_read(self, dep_node: &DepNode) -> Option<DepNodeIndex> { |
| 142 | + match self.dep_graph.node_color(dep_node) { |
| 143 | + Some(DepNodeColor::Green(dep_node_index)) => { |
| 144 | + self.dep_graph.read_index(dep_node_index); |
| 145 | + Some(dep_node_index) |
| 146 | + } |
| 147 | + Some(DepNodeColor::Red) => { |
| 148 | + None |
| 149 | + } |
| 150 | + None => { |
| 151 | + // try_mark_green (called below) will panic when full incremental |
| 152 | + // compilation is disabled. If that's the case, we can't try to mark nodes |
| 153 | + // as green anyway, so we can safely return None here. |
| 154 | + if !self.dep_graph.is_fully_enabled() { |
| 155 | + return None; |
| 156 | + } |
| 157 | + match self.dep_graph.try_mark_green(self, &dep_node) { |
| 158 | + Some(dep_node_index) => { |
| 159 | + debug_assert!(self.dep_graph.is_green(dep_node_index)); |
| 160 | + self.dep_graph.read_index(dep_node_index); |
| 161 | + Some(dep_node_index) |
| 162 | + } |
| 163 | + None => { |
| 164 | + None |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + } |
136 | 170 | }
|
137 | 171 |
|
138 | 172 | // If enabled, send a message to the profile-queries thread
|
@@ -309,7 +343,7 @@ macro_rules! define_maps {
|
309 | 343 | }
|
310 | 344 |
|
311 | 345 | if !dep_node.kind.is_input() {
|
312 |
| - if let Some(dep_node_index) = tcx.dep_graph.read_node_index(tcx, &dep_node) { |
| 346 | + if let Some(dep_node_index) = tcx.try_mark_green_and_read(&dep_node) { |
313 | 347 | profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
|
314 | 348 | return Self::load_from_disk_and_cache_in_memory(tcx,
|
315 | 349 | key,
|
@@ -340,8 +374,8 @@ macro_rules! define_maps {
|
340 | 374 | // Ensuring an "input" or anonymous query makes no sense
|
341 | 375 | assert!(!dep_node.kind.is_anon());
|
342 | 376 | assert!(!dep_node.kind.is_input());
|
343 |
| - if tcx.dep_graph.read_node_index(tcx, &dep_node).is_none() { |
344 |
| - // A None return from `read_node_index` means that this is either |
| 377 | + if tcx.try_mark_green_and_read(&dep_node).is_none() { |
| 378 | + // A None return from `try_mark_green_and_read` means that this is either |
345 | 379 | // a new dep node or that the dep node has already been marked red.
|
346 | 380 | // Either way, we can't call `dep_graph.read()` as we don't have the
|
347 | 381 | // DepNodeIndex. We must invoke the query itself. The performance cost
|
|
0 commit comments