Skip to content

Commit b3096e2

Browse files
committed
pacify the mercilous tidy, improve cycle unit test
1 parent 7abab8a commit b3096e2

File tree

7 files changed

+76
-8
lines changed

7 files changed

+76
-8
lines changed

src/librustc_incremental/persist/preds/compress/classify/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
//! First phase. Detect cycles and cross-edges.
212
313
use super::*;
@@ -122,7 +132,9 @@ impl<'a, 'g, N, I, O> Classify<'a, 'g, N, I, O>
122132
assert!(self.stack[stack_index] == child);
123133

124134
for &n in &self.stack[stack_index..] {
125-
debug!("cycle `{:?}` and `{:?}`", self.r.in_graph.node_data(n), self.r.in_graph.node_data(parent));
135+
debug!("cycle `{:?}` and `{:?}`",
136+
self.r.in_graph.node_data(n),
137+
self.r.in_graph.node_data(parent));
126138
self.r.mark_cycle(n, parent);
127139
}
128140
}

src/librustc_incremental/persist/preds/compress/classify/test.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use super::*;
212

313
#[test]
@@ -45,12 +55,17 @@ fn edge_order1() {
4555
let mut reduce = GraphReduce::new(&graph, |n| inputs.contains(n), |n| outputs.contains(n));
4656
Classify::new(&mut reduce).walk();
4757

48-
assert!(reduce.in_cycle(nodes("B"), nodes("C")));
49-
50-
assert!(!reduce.in_cycle(nodes("IN"), nodes("A")));
51-
assert!(!reduce.in_cycle(nodes("IN"), nodes("B")));
52-
assert!(!reduce.in_cycle(nodes("IN"), nodes("C")));
53-
assert!(!reduce.in_cycle(nodes("IN"), nodes("OUT")));
58+
// A, B, and C are mutually in a cycle, but IN/OUT are not participating.
59+
let names = ["A", "B", "C", "IN", "OUT"];
60+
let cycle_names = ["A", "B", "C"];
61+
for &i in &names {
62+
for &j in names.iter().filter(|&&j| j != i) {
63+
let in_cycle = cycle_names.contains(&i) && cycle_names.contains(&j);
64+
assert_eq!(reduce.in_cycle(nodes(i), nodes(j)), in_cycle,
65+
"cycle status for nodes {} and {} is incorrect",
66+
i, j);
67+
}
68+
}
5469
}
5570

5671
/// Same as `edge_order1` but in reverse order so as to detect a failure

src/librustc_incremental/persist/preds/compress/construct.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
//! Second phase. Construct new graph. The previous phase has
212
//! converted the input graph into a DAG by detecting and unifying
313
//! cycles. It provides us with the following (which is a

src/librustc_incremental/persist/preds/compress/dag_id.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use rustc_data_structures::graph::NodeIndex;
212
use rustc_data_structures::unify::UnifyKey;
313

src/librustc_incremental/persist/preds/compress/test.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use super::*;
212

313
fn reduce(graph: &Graph<&'static str, ()>,

src/librustc_incremental/persist/preds/compress/test_macro.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
macro_rules! graph {
212
($( $source:ident -> $target:ident, )*) => {
313
{

src/librustc_incremental/persist/save.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ pub fn encode_metadata_hashes(tcx: TyCtxt,
290290
.map(|index| preds.reduced_graph.node_data(index))
291291
.filter(|dep_node| HashContext::is_hashable(dep_node))
292292
.map(|dep_node| {
293-
let hash_dep_node = dep_node.map_def(|&def_id| Some(def_id_hash(def_id))).unwrap();
293+
let hash_dep_node = dep_node.map_def(|&def_id| Some(def_id_hash(def_id)))
294+
.unwrap();
294295
let hash = preds.hashes[dep_node];
295296
(hash_dep_node, hash)
296297
})

0 commit comments

Comments
 (0)