]> git.lizzy.rs Git - rust.git/commitdiff
Rename `read_node_index` to `try_mark_green_and_read` in plumbing
authorJimmy Brisson <theotherjimmy@gmail.com>
Mon, 16 Oct 2017 22:18:02 +0000 (17:18 -0500)
committerJimmy Brisson <theotherjimmy@gmail.com>
Mon, 16 Oct 2017 22:25:04 +0000 (17:25 -0500)
This should limit the availability of `try_mark_green_and_read` making
it harder to abuse.

src/librustc/dep_graph/graph.rs
src/librustc/ty/maps/plumbing.rs

index 38a27305c2b7dcd2511f946e9755791919cc4cfa..8aff042955c170f54f2dd28f1b1b900b2301797a 100644 (file)
@@ -427,40 +427,6 @@ pub fn node_color(&self, dep_node: &DepNode) -> Option<DepNodeColor> {
         self.data.as_ref().and_then(|data| data.colors.borrow().get(dep_node).cloned())
     }
 
-    /// Try to read a node index for the node dep_node.
-    /// A node will have an index, when it's already been marked green, or when we can mark it
-    /// green. This function will mark the current task as a reader of the specified node, when
-    /// the a node index can be found for that node.
-    pub fn read_node_index(&self, tcx: TyCtxt, dep_node: &DepNode) -> Option<DepNodeIndex> {
-        match self.node_color(dep_node) {
-            Some(DepNodeColor::Green(dep_node_index)) => {
-                self.read_index(dep_node_index);
-                Some(dep_node_index)
-            }
-            Some(DepNodeColor::Red) => {
-                None
-            }
-            None => {
-                // try_mark_green (called below) will panic when full incremental
-                // compilation is disabled. If that's the case, we can't try to mark nodes
-                // as green anyway, so we can safely return None here.
-                if !self.is_fully_enabled() {
-                    return None;
-                }
-                match self.try_mark_green(tcx, &dep_node) {
-                    Some(dep_node_index) => {
-                        debug_assert!(tcx.dep_graph.is_green(dep_node_index));
-                        tcx.dep_graph.read_index(dep_node_index);
-                        Some(dep_node_index)
-                    }
-                    None => {
-                        None
-                    }
-                }
-            }
-        }
-    }
-
     pub fn try_mark_green(&self,
                           tcx: TyCtxt,
                           dep_node: &DepNode)
index 13880b3713613a5fe39f8f1b7207c29edeeab251..be12f443782c2a6cbd39139525d6d3f944911db8 100644 (file)
@@ -12,7 +12,7 @@
 //! that generate the actual methods on tcx which find and execute the
 //! provider, manage the caches, and so forth.
 
-use dep_graph::{DepNodeIndex, DepNode, DepKind};
+use dep_graph::{DepNodeIndex, DepNode, DepKind, DepNodeColor};
 use errors::{Diagnostic, DiagnosticBuilder};
 use ty::{TyCtxt};
 use ty::maps::Query; // NB: actually generated by the macros in this file
@@ -133,6 +133,40 @@ pub(super) fn cycle_check<F, R>(self, span: Span, query: Query<'gcx>, compute: F
 
         Ok(result)
     }
+
+    /// Try to read a node index for the node dep_node.
+    /// A node will have an index, when it's already been marked green, or when we can mark it
+    /// green. This function will mark the current task as a reader of the specified node, when
+    /// the a node index can be found for that node.
+    pub(super) fn try_mark_green_and_read(self, dep_node: &DepNode) -> Option<DepNodeIndex> {
+        match self.dep_graph.node_color(dep_node) {
+            Some(DepNodeColor::Green(dep_node_index)) => {
+                self.dep_graph.read_index(dep_node_index);
+                Some(dep_node_index)
+            }
+            Some(DepNodeColor::Red) => {
+                None
+            }
+            None => {
+                // try_mark_green (called below) will panic when full incremental
+                // compilation is disabled. If that's the case, we can't try to mark nodes
+                // as green anyway, so we can safely return None here.
+                if !self.dep_graph.is_fully_enabled() {
+                    return None;
+                }
+                match self.dep_graph.try_mark_green(self, &dep_node) {
+                    Some(dep_node_index) => {
+                        debug_assert!(self.dep_graph.is_green(dep_node_index));
+                        self.dep_graph.read_index(dep_node_index);
+                        Some(dep_node_index)
+                    }
+                    None => {
+                        None
+                    }
+                }
+            }
+        }
+    }
 }
 
 // If enabled, send a message to the profile-queries thread
@@ -309,7 +343,7 @@ fn try_get_with(tcx: TyCtxt<'a, $tcx, 'lcx>,
                 }
 
                 if !dep_node.kind.is_input() {
-                    if let Some(dep_node_index) = tcx.dep_graph.read_node_index(tcx, &dep_node) {
+                    if let Some(dep_node_index) = tcx.try_mark_green_and_read(&dep_node) {
                         profq_msg!(tcx, ProfileQueriesMsg::CacheHit);
                         return Self::load_from_disk_and_cache_in_memory(tcx,
                                                                         key,
@@ -340,8 +374,8 @@ pub fn ensure(tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> () {
                 // Ensuring an "input" or anonymous query makes no sense
                 assert!(!dep_node.kind.is_anon());
                 assert!(!dep_node.kind.is_input());
-                if tcx.dep_graph.read_node_index(tcx, &dep_node).is_none() {
-                    // A None return from `read_node_index` means that this is either
+                if tcx.try_mark_green_and_read(&dep_node).is_none() {
+                    // A None return from `try_mark_green_and_read` means that this is either
                     // a new dep node or that the dep node has already been marked red.
                     // Either way, we can't call `dep_graph.read()` as we don't have the
                     // DepNodeIndex. We must invoke the query itself. The performance cost