diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2017-02-04 06:09:19 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-02-04 06:09:19 -0500 |
| commit | b3096e25c0a574cb20706adabe75667a215a86b9 (patch) | |
| tree | a0a3cdc5ea3e6d0fd15fc478cb77cad78ae661d5 | |
| parent | 7abab8aee09cdc8d23ec8fae5b5ec7675486aef0 (diff) | |
| download | rust-b3096e25c0a574cb20706adabe75667a215a86b9.tar.gz rust-b3096e25c0a574cb20706adabe75667a215a86b9.zip | |
pacify the mercilous tidy, improve cycle unit test
7 files changed, 76 insertions, 8 deletions
diff --git a/src/librustc_incremental/persist/preds/compress/classify/mod.rs b/src/librustc_incremental/persist/preds/compress/classify/mod.rs index f75063f8b9c..559bdbdd1e2 100644 --- a/src/librustc_incremental/persist/preds/compress/classify/mod.rs +++ b/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::*; @@ -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); } } diff --git a/src/librustc_incremental/persist/preds/compress/classify/test.rs b/src/librustc_incremental/persist/preds/compress/classify/test.rs index 22067a10343..ca26f714a2a 100644 --- a/src/librustc_incremental/persist/preds/compress/classify/test.rs +++ b/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] @@ -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 diff --git a/src/librustc_incremental/persist/preds/compress/construct.rs b/src/librustc_incremental/persist/preds/compress/construct.rs index 965c773597e..394be74f783 100644 --- a/src/librustc_incremental/persist/preds/compress/construct.rs +++ b/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 diff --git a/src/librustc_incremental/persist/preds/compress/dag_id.rs b/src/librustc_incremental/persist/preds/compress/dag_id.rs index c79930bfae5..a286862e955 100644 --- a/src/librustc_incremental/persist/preds/compress/dag_id.rs +++ b/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; diff --git a/src/librustc_incremental/persist/preds/compress/test.rs b/src/librustc_incremental/persist/preds/compress/test.rs index be91677f4d1..1c5130845a8 100644 --- a/src/librustc_incremental/persist/preds/compress/test.rs +++ b/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, ()>, diff --git a/src/librustc_incremental/persist/preds/compress/test_macro.rs b/src/librustc_incremental/persist/preds/compress/test_macro.rs index 66712c018d0..31b30d2b285 100644 --- a/src/librustc_incremental/persist/preds/compress/test_macro.rs +++ b/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, )*) => { { diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs index 93600631b8d..34bb125ef3f 100644 --- a/src/librustc_incremental/persist/save.rs +++ b/src/librustc_incremental/persist/save.rs @@ -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) }) |
