about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2017-09-14 17:42:12 +0200
committerMichael Woerister <michaelwoerister@posteo>2017-09-20 11:21:25 +0200
commit25bc69ec20f19232eb0a1f6cac13cdefdf880dfe (patch)
treef9c30738bd42c9ee879ffa06e951deaeaad4bb54
parent3b75a3dfeaf8261bd59343792b3650550be86c95 (diff)
downloadrust-25bc69ec20f19232eb0a1f6cac13cdefdf880dfe.tar.gz
rust-25bc69ec20f19232eb0a1f6cac13cdefdf880dfe.zip
incr.comp.: Allow for marking DepKinds as inputs.
-rw-r--r--src/librustc/dep_graph/dep_node.rs54
-rw-r--r--src/librustc/dep_graph/edges.rs1
-rw-r--r--src/librustc_incremental/persist/hash.rs23
-rw-r--r--src/librustc_incremental/persist/preds/mod.rs2
4 files changed, 42 insertions, 38 deletions
diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs
index 7c21bba49f8..3befab1fe2a 100644
--- a/src/librustc/dep_graph/dep_node.rs
+++ b/src/librustc/dep_graph/dep_node.rs
@@ -80,14 +80,28 @@ macro_rules! erase {
     ($x:tt) => ({})
 }
 
-macro_rules! anon_attr_to_bool {
-    (anon) => (true)
+macro_rules! is_anon_attr {
+    (anon) => (true);
+    ($attr:ident) => (false);
+}
+
+macro_rules! is_input_attr {
+    (input) => (true);
+    ($attr:ident) => (false);
+}
+
+macro_rules! contains_anon_attr {
+    ($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
+}
+
+macro_rules! contains_input_attr {
+    ($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
 }
 
 macro_rules! define_dep_nodes {
     (<$tcx:tt>
     $(
-        [$($anon:ident)*]
+        [$($attr:ident),* ]
         $variant:ident $(( $($tuple_arg:tt),* ))*
                        $({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
       ,)*
@@ -105,7 +119,9 @@ macro_rules! define_dep_nodes {
                 match *self {
                     $(
                         DepKind :: $variant => {
-                            $(return !anon_attr_to_bool!($anon);)*
+                            if contains_anon_attr!($($attr),*) {
+                                return false;
+                            }
 
                             // tuple args
                             $({
@@ -126,15 +142,20 @@ macro_rules! define_dep_nodes {
                 }
             }
 
-            #[allow(unreachable_code)]
             #[inline]
-            pub fn is_anon<$tcx>(&self) -> bool {
+            pub fn is_anon(&self) -> bool {
                 match *self {
                     $(
-                        DepKind :: $variant => {
-                            $(return anon_attr_to_bool!($anon);)*
-                            false
-                        }
+                        DepKind :: $variant => { contains_anon_attr!($($attr),*) }
+                    )*
+                }
+            }
+
+            #[inline]
+            pub fn is_input(&self) -> bool {
+                match *self {
+                    $(
+                        DepKind :: $variant => { contains_input_attr!($($attr),*) }
                     )*
                 }
             }
@@ -378,18 +399,17 @@ define_dep_nodes!( <'tcx>
     // suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
     // access to the krate, but you must remember to add suitable
     // edges yourself for the individual items that you read.
-    [] Krate,
+    [input] Krate,
 
     // Represents the HIR node with the given node-id
-    [] Hir(DefId),
+    [input] Hir(DefId),
 
     // Represents the body of a function or method. The def-id is that of the
     // function/method.
-    [] HirBody(DefId),
+    [input] HirBody(DefId),
 
-    // Represents the metadata for a given HIR node, typically found
-    // in an extern crate.
-    [] MetaData(DefId),
+    // Represents metadata from an extern crate.
+    [input] MetaData(DefId),
 
     // Represents some artifact that we save to disk. Note that these
     // do not have a def-id as part of their identifier.
@@ -529,7 +549,7 @@ define_dep_nodes!( <'tcx>
     [] ExternCrate(DefId),
     [] LintLevels,
     [] Specializes { impl1: DefId, impl2: DefId },
-    [] InScopeTraits(DefIndex),
+    [input] InScopeTraits(DefIndex),
     [] ModuleExports(DefId),
     [] IsSanitizerRuntime(CrateNum),
     [] IsProfilerRuntime(CrateNum),
diff --git a/src/librustc/dep_graph/edges.rs b/src/librustc/dep_graph/edges.rs
index 809d1dfcf60..29c0ba66f3f 100644
--- a/src/librustc/dep_graph/edges.rs
+++ b/src/librustc/dep_graph/edges.rs
@@ -123,6 +123,7 @@ impl DepGraphEdges {
             reads
         } = popped_node {
             debug_assert_eq!(node, key);
+            debug_assert!(!node.kind.is_input() || reads.is_empty());
 
             let target_id = self.get_or_create_node(node);
 
diff --git a/src/librustc_incremental/persist/hash.rs b/src/librustc_incremental/persist/hash.rs
index 8355f319139..8a7011a0dcc 100644
--- a/src/librustc_incremental/persist/hash.rs
+++ b/src/librustc_incremental/persist/hash.rs
@@ -45,21 +45,6 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
         }
     }
 
-    pub fn is_hashable(tcx: TyCtxt, dep_node: &DepNode) -> bool {
-        match dep_node.kind {
-            DepKind::Krate |
-            DepKind::Hir |
-            DepKind::InScopeTraits |
-            DepKind::HirBody =>
-                true,
-            DepKind::MetaData => {
-                let def_id = dep_node.extract_def_id(tcx).unwrap();
-                !def_id.is_local()
-            }
-            _ => false,
-        }
-    }
-
     pub fn hash(&mut self, dep_node: &DepNode) -> Option<Fingerprint> {
         match dep_node.kind {
             DepKind::Krate => {
@@ -79,13 +64,11 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
             // save it for others to use.
             DepKind::MetaData => {
                 let def_id = dep_node.extract_def_id(self.tcx).unwrap();
-                if !def_id.is_local() {
-                    Some(self.metadata_hash(def_id,
+                assert!(!def_id.is_local());
+
+                Some(self.metadata_hash(def_id,
                                         def_id.krate,
                                         |this| &mut this.metadata_hashes))
-                } else {
-                    None
-                }
             }
 
             _ => {
diff --git a/src/librustc_incremental/persist/preds/mod.rs b/src/librustc_incremental/persist/preds/mod.rs
index 5483134523c..46bb37b017f 100644
--- a/src/librustc_incremental/persist/preds/mod.rs
+++ b/src/librustc_incremental/persist/preds/mod.rs
@@ -66,7 +66,7 @@ impl<'q> Predecessors<'q> {
         // Reduce the graph to the most important nodes.
         let compress::Reduction { graph, input_nodes } =
             compress::reduce_graph(&query.graph,
-                                   |n| HashContext::is_hashable(tcx, n),
+                                   |n| n.kind.is_input(),
                                    |n| is_output(n));
 
         let mut hashes = FxHashMap();