Skip to content

Only hash dep node indices of deps of anon tasks #60573

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

Merged
merged 1 commit into from
May 7, 2019
Merged
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
21 changes: 9 additions & 12 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,25 +1021,22 @@ impl CurrentDepGraph {
fn complete_anon_task(&mut self, kind: DepKind, task_deps: TaskDeps) -> DepNodeIndex {
debug_assert!(!kind.is_eval_always());

let mut fingerprint = self.anon_id_seed;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining why this works? Especially why it is OK to stable-hash unstable data like DepNodeIndex values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

let mut hasher = StableHasher::new();

for &read in task_deps.reads.iter() {
let read_dep_node = self.data[read].node;
// The dep node indices are hashed here instead of hashing the dep nodes of the
// dependencies. These indices may refer to different nodes per session, but this isn't
// a problem here because we that ensure the final dep node hash is per session only by
// combining it with the per session random number `anon_id_seed`. This hash only need
// to map the dependencies to a single value on a per session basis.
task_deps.reads.hash(&mut hasher);

::std::mem::discriminant(&read_dep_node.kind).hash(&mut hasher);
let target_dep_node = DepNode {
kind,

// Fingerprint::combine() is faster than sending Fingerprint
// through the StableHasher (at least as long as StableHasher
// is so slow).
fingerprint = fingerprint.combine(read_dep_node.hash);
}

fingerprint = fingerprint.combine(hasher.finish());

let target_dep_node = DepNode {
kind,
hash: fingerprint,
hash: self.anon_id_seed.combine(hasher.finish()),
};

self.intern_node(target_dep_node, task_deps.reads, Fingerprint::ZERO).0
Expand Down