From 08328d329b5ff791e4ac3f7ddb2293a0ae8a4f23 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Sat, 19 Sep 2020 22:30:06 -0400 Subject: [PATCH 1/2] Don't allocate DepNode if anon or no dependencies --- compiler/rustc_middle/src/dep_graph/mod.rs | 4 ++++ .../rustc_query_system/src/dep_graph/graph.rs | 20 +++++++++++++++---- .../rustc_query_system/src/dep_graph/mod.rs | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index 6697524279874..9de7e1bff448e 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -85,6 +85,10 @@ impl rustc_query_system::dep_graph::DepKind for DepKind { fn can_reconstruct_query_key(&self) -> bool { DepKind::can_reconstruct_query_key(self) } + + fn is_anon(&self) -> bool { + DepKind::is_anon(self) + } } impl<'tcx> DepContext for TyCtxt<'tcx> { diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 85335f0ba50c2..5bdf6c889781b 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -230,7 +230,7 @@ impl DepGraph { DepNode, Fingerprint, Option>, - ) -> DepNodeIndex, + ) -> Option, hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option, ) -> (R, DepNodeIndex) { if let Some(ref data) = self.data { @@ -260,6 +260,13 @@ impl DepGraph { let print_status = cfg!(debug_assertions) && cx.debug_dep_tasks(); + if matches!(dep_node_index, None) { + return (result, self.next_virtual_depnode_index()); + } + + // Handled None case above, safe to unwrap here. + let dep_node_index = dep_node_index.unwrap(); + // Determine the color of the new DepNode. if let Some(prev_index) = data.previous.node_to_index_opt(&key) { let prev_fingerprint = data.previous.fingerprint_by_index(prev_index); @@ -956,7 +963,7 @@ impl CurrentDepGraph { node: DepNode, task_deps: TaskDeps, fingerprint: Fingerprint, - ) -> DepNodeIndex { + ) -> Option { self.alloc_node(node, task_deps.reads, fingerprint) } @@ -989,11 +996,16 @@ impl CurrentDepGraph { dep_node: DepNode, edges: EdgesVec, fingerprint: Fingerprint, - ) -> DepNodeIndex { + ) -> Option { debug_assert!( !self.node_to_node_index.get_shard_by_value(&dep_node).lock().contains_key(&dep_node) ); - self.intern_node(dep_node, edges, fingerprint) + + if dep_node.kind.is_anon() || edges.is_empty() { + return None; + } + + Some(self.intern_node(dep_node, edges, fingerprint)) } fn intern_node( diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index e8d02692f37ba..9a13dfc3debab 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -82,4 +82,6 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash { OP: for<'a> FnOnce(Option<&'a Lock>>); fn can_reconstruct_query_key(&self) -> bool; + + fn is_anon(&self) -> bool; } From 6c03fb8dd0535d9131a67a242247cf6f9b9fe1d9 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Sun, 20 Sep 2020 01:10:49 -0400 Subject: [PATCH 2/2] Don't check edges empty --- compiler/rustc_middle/src/dep_graph/mod.rs | 1 + compiler/rustc_query_system/src/dep_graph/graph.rs | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index 9de7e1bff448e..2b4bced34b29d 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -86,6 +86,7 @@ impl rustc_query_system::dep_graph::DepKind for DepKind { DepKind::can_reconstruct_query_key(self) } + #[inline] fn is_anon(&self) -> bool { DepKind::is_anon(self) } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 5bdf6c889781b..ab6a82c82b2ac 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -260,12 +260,11 @@ impl DepGraph { let print_status = cfg!(debug_assertions) && cx.debug_dep_tasks(); - if matches!(dep_node_index, None) { + let dep_node_index = if let Some(dep_node_index) = dep_node_index { + dep_node_index + } else { return (result, self.next_virtual_depnode_index()); - } - - // Handled None case above, safe to unwrap here. - let dep_node_index = dep_node_index.unwrap(); + }; // Determine the color of the new DepNode. if let Some(prev_index) = data.previous.node_to_index_opt(&key) { @@ -1001,7 +1000,7 @@ impl CurrentDepGraph { !self.node_to_node_index.get_shard_by_value(&dep_node).lock().contains_key(&dep_node) ); - if dep_node.kind.is_anon() || edges.is_empty() { + if dep_node.kind.is_anon() { return None; }