Skip to content

Commit 229bee3

Browse files
committed
Rename read_node_index to try_mark_green_and_read in plumbing
This should limit the availability of `try_mark_green_and_read` making it harder to abuse.
1 parent 549f855 commit 229bee3

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/librustc/dep_graph/graph.rs

-34
Original file line numberDiff line numberDiff line change
@@ -427,40 +427,6 @@ impl DepGraph {
427427
self.data.as_ref().and_then(|data| data.colors.borrow().get(dep_node).cloned())
428428
}
429429

430-
/// Try to read a node index for the node dep_node.
431-
/// A node will have an index, when it's already been marked green, or when we can mark it
432-
/// green. This function will mark the current task as a reader of the specified node, when
433-
/// the a node index can be found for that node.
434-
pub fn read_node_index(&self, tcx: TyCtxt, dep_node: &DepNode) -> Option<DepNodeIndex> {
435-
match self.node_color(dep_node) {
436-
Some(DepNodeColor::Green(dep_node_index)) => {
437-
self.read_index(dep_node_index);
438-
Some(dep_node_index)
439-
}
440-
Some(DepNodeColor::Red) => {
441-
None
442-
}
443-
None => {
444-
// try_mark_green (called below) will panic when full incremental
445-
// compilation is disabled. If that's the case, we can't try to mark nodes
446-
// as green anyway, so we can safely return None here.
447-
if !self.is_fully_enabled() {
448-
return None;
449-
}
450-
match self.try_mark_green(tcx, &dep_node) {
451-
Some(dep_node_index) => {
452-
debug_assert!(tcx.dep_graph.is_green(dep_node_index));
453-
tcx.dep_graph.read_index(dep_node_index);
454-
Some(dep_node_index)
455-
}
456-
None => {
457-
None
458-
}
459-
}
460-
}
461-
}
462-
}
463-
464430
pub fn try_mark_green(&self,
465431
tcx: TyCtxt,
466432
dep_node: &DepNode)

src/librustc/ty/maps/plumbing.rs

+38-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! that generate the actual methods on tcx which find and execute the
1313
//! provider, manage the caches, and so forth.
1414
15-
use dep_graph::{DepNodeIndex, DepNode, DepKind};
15+
use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
1616
use errors::{Diagnostic, DiagnosticBuilder};
1717
use ty::{TyCtxt};
1818
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> {
133133

134134
Ok(result)
135135
}
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+
}
136170
}
137171

138172
// If enabled, send a message to the profile-queries thread
@@ -309,7 +343,7 @@ macro_rules! define_maps {
309343
}
310344

311345
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) {
313347
profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
314348
return Self::load_from_disk_and_cache_in_memory(tcx,
315349
key,
@@ -340,8 +374,8 @@ macro_rules! define_maps {
340374
// Ensuring an "input" or anonymous query makes no sense
341375
assert!(!dep_node.kind.is_anon());
342376
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
345379
// a new dep node or that the dep node has already been marked red.
346380
// Either way, we can't call `dep_graph.read()` as we don't have the
347381
// DepNodeIndex. We must invoke the query itself. The performance cost

0 commit comments

Comments
 (0)