Skip to content

Commit

Permalink
pacify the mercilous tidy, improve cycle unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Feb 4, 2017
1 parent 7abab8a commit b3096e2
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 8 deletions.
14 changes: 13 additions & 1 deletion src/librustc_incremental/persist/preds/compress/classify/mod.rs
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! First phase. Detect cycles and cross-edges.

use super::*;
Expand Down Expand Up @@ -122,7 +132,9 @@ impl<'a, 'g, N, I, O> Classify<'a, 'g, N, I, O>
assert!(self.stack[stack_index] == child);

for &n in &self.stack[stack_index..] {
debug!("cycle `{:?}` and `{:?}`", self.r.in_graph.node_data(n), self.r.in_graph.node_data(parent));
debug!("cycle `{:?}` and `{:?}`",
self.r.in_graph.node_data(n),
self.r.in_graph.node_data(parent));
self.r.mark_cycle(n, parent);
}
}
Expand Down
27 changes: 21 additions & 6 deletions src/librustc_incremental/persist/preds/compress/classify/test.rs
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::*;

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

assert!(reduce.in_cycle(nodes("B"), nodes("C")));

assert!(!reduce.in_cycle(nodes("IN"), nodes("A")));
assert!(!reduce.in_cycle(nodes("IN"), nodes("B")));
assert!(!reduce.in_cycle(nodes("IN"), nodes("C")));
assert!(!reduce.in_cycle(nodes("IN"), nodes("OUT")));
// A, B, and C are mutually in a cycle, but IN/OUT are not participating.
let names = ["A", "B", "C", "IN", "OUT"];
let cycle_names = ["A", "B", "C"];
for &i in &names {
for &j in names.iter().filter(|&&j| j != i) {
let in_cycle = cycle_names.contains(&i) && cycle_names.contains(&j);
assert_eq!(reduce.in_cycle(nodes(i), nodes(j)), in_cycle,
"cycle status for nodes {} and {} is incorrect",
i, j);
}
}
}

/// Same as `edge_order1` but in reverse order so as to detect a failure
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_incremental/persist/preds/compress/construct.rs
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Second phase. Construct new graph. The previous phase has
//! converted the input graph into a DAG by detecting and unifying
//! cycles. It provides us with the following (which is a
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_incremental/persist/preds/compress/dag_id.rs
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rustc_data_structures::graph::NodeIndex;
use rustc_data_structures::unify::UnifyKey;

Expand Down
10 changes: 10 additions & 0 deletions src/librustc_incremental/persist/preds/compress/test.rs
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::*;

fn reduce(graph: &Graph<&'static str, ()>,
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_incremental/persist/preds/compress/test_macro.rs
@@ -1,3 +1,13 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

macro_rules! graph {
($( $source:ident -> $target:ident, )*) => {
{
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_incremental/persist/save.rs
Expand Up @@ -290,7 +290,8 @@ pub fn encode_metadata_hashes(tcx: TyCtxt,
.map(|index| preds.reduced_graph.node_data(index))
.filter(|dep_node| HashContext::is_hashable(dep_node))
.map(|dep_node| {
let hash_dep_node = dep_node.map_def(|&def_id| Some(def_id_hash(def_id))).unwrap();
let hash_dep_node = dep_node.map_def(|&def_id| Some(def_id_hash(def_id)))
.unwrap();
let hash = preds.hashes[dep_node];
(hash_dep_node, hash)
})
Expand Down

0 comments on commit b3096e2

Please sign in to comment.