Skip to content

Commit 25bc69e

Browse files
incr.comp.: Allow for marking DepKinds as inputs.
1 parent 3b75a3d commit 25bc69e

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,28 @@ macro_rules! erase {
8080
($x:tt) => ({})
8181
}
8282

83-
macro_rules! anon_attr_to_bool {
84-
(anon) => (true)
83+
macro_rules! is_anon_attr {
84+
(anon) => (true);
85+
($attr:ident) => (false);
86+
}
87+
88+
macro_rules! is_input_attr {
89+
(input) => (true);
90+
($attr:ident) => (false);
91+
}
92+
93+
macro_rules! contains_anon_attr {
94+
($($attr:ident),*) => ({$(is_anon_attr!($attr) | )* false});
95+
}
96+
97+
macro_rules! contains_input_attr {
98+
($($attr:ident),*) => ({$(is_input_attr!($attr) | )* false});
8599
}
86100

87101
macro_rules! define_dep_nodes {
88102
(<$tcx:tt>
89103
$(
90-
[$($anon:ident)*]
104+
[$($attr:ident),* ]
91105
$variant:ident $(( $($tuple_arg:tt),* ))*
92106
$({ $($struct_arg_name:ident : $struct_arg_ty:ty),* })*
93107
,)*
@@ -105,7 +119,9 @@ macro_rules! define_dep_nodes {
105119
match *self {
106120
$(
107121
DepKind :: $variant => {
108-
$(return !anon_attr_to_bool!($anon);)*
122+
if contains_anon_attr!($($attr),*) {
123+
return false;
124+
}
109125

110126
// tuple args
111127
$({
@@ -126,15 +142,20 @@ macro_rules! define_dep_nodes {
126142
}
127143
}
128144

129-
#[allow(unreachable_code)]
130145
#[inline]
131-
pub fn is_anon<$tcx>(&self) -> bool {
146+
pub fn is_anon(&self) -> bool {
132147
match *self {
133148
$(
134-
DepKind :: $variant => {
135-
$(return anon_attr_to_bool!($anon);)*
136-
false
137-
}
149+
DepKind :: $variant => { contains_anon_attr!($($attr),*) }
150+
)*
151+
}
152+
}
153+
154+
#[inline]
155+
pub fn is_input(&self) -> bool {
156+
match *self {
157+
$(
158+
DepKind :: $variant => { contains_input_attr!($($attr),*) }
138159
)*
139160
}
140161
}
@@ -378,18 +399,17 @@ define_dep_nodes!( <'tcx>
378399
// suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
379400
// access to the krate, but you must remember to add suitable
380401
// edges yourself for the individual items that you read.
381-
[] Krate,
402+
[input] Krate,
382403

383404
// Represents the HIR node with the given node-id
384-
[] Hir(DefId),
405+
[input] Hir(DefId),
385406

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

390-
// Represents the metadata for a given HIR node, typically found
391-
// in an extern crate.
392-
[] MetaData(DefId),
411+
// Represents metadata from an extern crate.
412+
[input] MetaData(DefId),
393413

394414
// Represents some artifact that we save to disk. Note that these
395415
// do not have a def-id as part of their identifier.
@@ -529,7 +549,7 @@ define_dep_nodes!( <'tcx>
529549
[] ExternCrate(DefId),
530550
[] LintLevels,
531551
[] Specializes { impl1: DefId, impl2: DefId },
532-
[] InScopeTraits(DefIndex),
552+
[input] InScopeTraits(DefIndex),
533553
[] ModuleExports(DefId),
534554
[] IsSanitizerRuntime(CrateNum),
535555
[] IsProfilerRuntime(CrateNum),

src/librustc/dep_graph/edges.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl DepGraphEdges {
123123
reads
124124
} = popped_node {
125125
debug_assert_eq!(node, key);
126+
debug_assert!(!node.kind.is_input() || reads.is_empty());
126127

127128
let target_id = self.get_or_create_node(node);
128129

src/librustc_incremental/persist/hash.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
4545
}
4646
}
4747

48-
pub fn is_hashable(tcx: TyCtxt, dep_node: &DepNode) -> bool {
49-
match dep_node.kind {
50-
DepKind::Krate |
51-
DepKind::Hir |
52-
DepKind::InScopeTraits |
53-
DepKind::HirBody =>
54-
true,
55-
DepKind::MetaData => {
56-
let def_id = dep_node.extract_def_id(tcx).unwrap();
57-
!def_id.is_local()
58-
}
59-
_ => false,
60-
}
61-
}
62-
6348
pub fn hash(&mut self, dep_node: &DepNode) -> Option<Fingerprint> {
6449
match dep_node.kind {
6550
DepKind::Krate => {
@@ -79,13 +64,11 @@ impl<'a, 'tcx> HashContext<'a, 'tcx> {
7964
// save it for others to use.
8065
DepKind::MetaData => {
8166
let def_id = dep_node.extract_def_id(self.tcx).unwrap();
82-
if !def_id.is_local() {
83-
Some(self.metadata_hash(def_id,
67+
assert!(!def_id.is_local());
68+
69+
Some(self.metadata_hash(def_id,
8470
def_id.krate,
8571
|this| &mut this.metadata_hashes))
86-
} else {
87-
None
88-
}
8972
}
9073

9174
_ => {

src/librustc_incremental/persist/preds/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'q> Predecessors<'q> {
6666
// Reduce the graph to the most important nodes.
6767
let compress::Reduction { graph, input_nodes } =
6868
compress::reduce_graph(&query.graph,
69-
|n| HashContext::is_hashable(tcx, n),
69+
|n| n.kind.is_input(),
7070
|n| is_output(n));
7171

7272
let mut hashes = FxHashMap();

0 commit comments

Comments
 (0)