Skip to content

Commit

Permalink
Auto merge of #44696 - michaelwoerister:fingerprints-in-dep-graph-3, …
Browse files Browse the repository at this point in the history
…r=nikomatsakis

incr.comp.: Move task result fingerprinting into DepGraph.

This PR
- makes the DepGraph store all `Fingerprints` of task results,
- allows `DepNode` to be marked as input nodes,
- makes HIR node hashing use the regular fingerprinting infrastructure,
- removes the now unused `IncrementalHashesMap`, and
- makes sure that `traits_in_scope_map` fingerprints are stable.

r? @nikomatsakis
cc @alexcrichton
  • Loading branch information
bors committed Sep 22, 2017
2 parents 3eb19bf + 9798a88 commit 14039a4
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 515 deletions.
69 changes: 50 additions & 19 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),* })*
,)*
Expand All @@ -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
$({
Expand All @@ -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),*) }
)*
}
}
Expand Down Expand Up @@ -366,6 +387,17 @@ impl DefId {
}
}

impl DepKind {
#[inline]
pub fn fingerprint_needed_for_crate_hash(self) -> bool {
match self {
DepKind::HirBody |
DepKind::Krate => true,
_ => false,
}
}
}

define_dep_nodes!( <'tcx>
// Represents the `Krate` as a whole (the `hir::Krate` value) (as
// distinct from the krate module). This is basically a hash of
Expand All @@ -378,18 +410,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,

// Represents the HIR node with the given node-id
[] Hir(DefId),
[input] Krate,

// Represents the body of a function or method. The def-id is that of the
// function/method.
[] HirBody(DefId),
[input] HirBody(DefId),

// Represents the HIR node with the given node-id
[input] Hir(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.
Expand Down Expand Up @@ -529,7 +560,7 @@ define_dep_nodes!( <'tcx>
[] ExternCrate(DefId),
[] LintLevels,
[] Specializes { impl1: DefId, impl2: DefId },
[] InScopeTraits(DefIndex),
[input] InScopeTraits(DefIndex),
[] ModuleExports(DefId),
[] IsSanitizerRuntime(CrateNum),
[] IsProfilerRuntime(CrateNum),
Expand Down
1 change: 1 addition & 0 deletions src/librustc/dep_graph/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
38 changes: 34 additions & 4 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ use super::edges::{DepGraphEdges, DepNodeIndex};

#[derive(Clone)]
pub struct DepGraph {
data: Option<Rc<DepGraphData>>
data: Option<Rc<DepGraphData>>,

// At the moment we are using DepNode as key here. In the future it might
// be possible to use an IndexVec<DepNodeIndex, _> here. At the moment there
// are a few problems with that:
// - Some fingerprints are needed even if incr. comp. is disabled -- yet
// we need to have a dep-graph to generate DepNodeIndices.
// - The architecture is still in flux and it's not clear what how to best
// implement things.
fingerprints: Rc<RefCell<FxHashMap<DepNode, Fingerprint>>>
}

struct DepGraphData {
Expand Down Expand Up @@ -57,7 +66,8 @@ impl DepGraph {
}))
} else {
None
}
},
fingerprints: Rc::new(RefCell::new(FxHashMap())),
}
}

Expand Down Expand Up @@ -139,11 +149,27 @@ impl DepGraph {

let mut stable_hasher = StableHasher::new();
result.hash_stable(&mut hcx, &mut stable_hasher);
let _: Fingerprint = stable_hasher.finish();

assert!(self.fingerprints
.borrow_mut()
.insert(key, stable_hasher.finish())
.is_none());

(result, dep_node_index)
} else {
(task(cx, arg), DepNodeIndex::INVALID)
if key.kind.fingerprint_needed_for_crate_hash() {
let mut hcx = cx.create_stable_hashing_context();
let result = task(cx, arg);
let mut stable_hasher = StableHasher::new();
result.hash_stable(&mut hcx, &mut stable_hasher);
assert!(self.fingerprints
.borrow_mut()
.insert(key, stable_hasher.finish())
.is_none());
(result, DepNodeIndex::INVALID)
} else {
(task(cx, arg), DepNodeIndex::INVALID)
}
}
}

Expand Down Expand Up @@ -195,6 +221,10 @@ impl DepGraph {
}
}

pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
self.fingerprints.borrow().get(dep_node).cloned()
}

/// Indicates that a previous work product exists for `v`. This is
/// invoked during initial start-up based on what nodes are clean
/// (and what files exist in the incr. directory).
Expand Down
Loading

0 comments on commit 14039a4

Please sign in to comment.