From b51f24f021a985e689f35214302ed5844907962d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 1 Jun 2021 21:46:30 +0200 Subject: [PATCH] Make the reasoning more explicit. --- compiler/rustc_query_system/src/dep_graph/graph.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 9481da70f42..71e67dfee53 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -44,7 +44,7 @@ rustc_index::newtype_index! { impl DepNodeIndex { pub const INVALID: DepNodeIndex = DepNodeIndex::MAX; - pub const DUMMY_ANON: DepNodeIndex = DepNodeIndex::from_u32(0); + pub const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0); } impl std::convert::From for QueryInvocationId { @@ -121,14 +121,14 @@ impl DepGraph { let current = CurrentDepGraph::new(prev_graph_node_count, encoder, record_graph, record_stats); - // Instantiate an *always green* node for dependency-less anonymous queries. + // Instantiate a dependy-less node only once for anonymous queries. let _green_node_index = current.intern_new_node( profiler, DepNode { kind: DepKind::NULL, hash: current.anon_id_seed.into() }, smallvec![], Fingerprint::ZERO, ); - debug_assert_eq!(_green_node_index, DepNodeIndex::DUMMY_ANON); + debug_assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE); DepGraph { data: Some(Lrc::new(DepGraphData { @@ -300,8 +300,12 @@ impl DepGraph { let dep_node_index = match task_deps.len() { 0 => { - // Dependency-less anonymous nodes can safely be replaced by a dummy node. - DepNodeIndex::DUMMY_ANON + // Because the dep-node id of anon nodes is computed from the sets of its + // dependencies we already know what the ID of this dependency-less node is + // going to be (i.e. equal to the precomputed + // `SINGLETON_DEPENDENCYLESS_ANON_NODE`). As a consequence we can skip creating + // a `StableHasher` and sending the node through interning. + DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE } 1 => { // When there is only one dependency, don't bother creating a node.