1 // Copyright 2017 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.
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.
12 use rustc_data_structures::fx::FxHashMap;
13 use super::dep_node::DepNode;
14 use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
16 #[derive(Debug, RustcEncodable, RustcDecodable)]
17 pub struct PreviousDepGraph {
18 data: SerializedDepGraph,
19 index: FxHashMap<DepNode, SerializedDepNodeIndex>,
22 impl PreviousDepGraph {
23 pub fn new(data: SerializedDepGraph) -> PreviousDepGraph {
24 let index: FxHashMap<_, _> = data.nodes
26 .map(|(idx, &(dep_node, _))| (dep_node, idx))
28 PreviousDepGraph { data, index }
32 pub fn edges_from(&self,
34 -> Option<(&[SerializedDepNodeIndex], SerializedDepNodeIndex)> {
38 (self.data.edge_targets_from(node_index), node_index)
43 pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode {
44 self.data.nodes[dep_node_index].0
48 pub fn fingerprint_of(&self, dep_node: &DepNode) -> Option<Fingerprint> {
51 .map(|&node_index| self.data.nodes[node_index].1)
55 pub fn fingerprint_by_index(&self,
56 dep_node_index: SerializedDepNodeIndex)
58 self.data.nodes[dep_node_index].1