Skip to content

Don't allocate DepNode if anonymous #77070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
fn can_reconstruct_query_key(&self) -> bool {
DepKind::can_reconstruct_query_key(self)
}

#[inline]
fn is_anon(&self) -> bool {
Copy link
Member

@bjorn3 bjorn3 Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn is_anon(&self) -> bool {
#[inline]
fn is_anon(&self) -> bool {

can_reconstruct_query_key also seems to be missing it. Or maybe it is missing for a reason?

DepKind::is_anon(self)
}
}

impl<'tcx> DepContext for TyCtxt<'tcx> {
Expand Down
19 changes: 15 additions & 4 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<K: DepKind> DepGraph<K> {
DepNode<K>,
Fingerprint,
Option<TaskDeps<K>>,
) -> DepNodeIndex,
) -> Option<DepNodeIndex>,
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
) -> (R, DepNodeIndex) {
if let Some(ref data) = self.data {
Expand Down Expand Up @@ -260,6 +260,12 @@ impl<K: DepKind> DepGraph<K> {

let print_status = cfg!(debug_assertions) && cx.debug_dep_tasks();

let dep_node_index = if let Some(dep_node_index) = dep_node_index {
dep_node_index
} else {
return (result, self.next_virtual_depnode_index());
};

// 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);
Expand Down Expand Up @@ -956,7 +962,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
node: DepNode<K>,
task_deps: TaskDeps<K>,
fingerprint: Fingerprint,
) -> DepNodeIndex {
) -> Option<DepNodeIndex> {
self.alloc_node(node, task_deps.reads, fingerprint)
}

Expand Down Expand Up @@ -989,11 +995,16 @@ impl<K: DepKind> CurrentDepGraph<K> {
dep_node: DepNode<K>,
edges: EdgesVec,
fingerprint: Fingerprint,
) -> DepNodeIndex {
) -> Option<DepNodeIndex> {
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() {
return None;
}

Some(self.intern_node(dep_node, edges, fingerprint))
}

fn intern_node(
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_query_system/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash {
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps<Self>>>);

fn can_reconstruct_query_key(&self) -> bool;

fn is_anon(&self) -> bool;
}