@@ -37,17 +37,19 @@ rustc_index::newtype_index! {
3737#[ derive( Debug ) ]
3838pub struct SerializedDepGraph < K : DepKind > {
3939 /// The set of all DepNodes in the graph
40- pub nodes : IndexVec < SerializedDepNodeIndex , DepNode < K > > ,
40+ nodes : IndexVec < SerializedDepNodeIndex , DepNode < K > > ,
4141 /// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
4242 /// the DepNode at the same index in the nodes vector.
43- pub fingerprints : IndexVec < SerializedDepNodeIndex , Fingerprint > ,
43+ fingerprints : IndexVec < SerializedDepNodeIndex , Fingerprint > ,
4444 /// For each DepNode, stores the list of edges originating from that
4545 /// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
4646 /// which holds the actual DepNodeIndices of the target nodes.
47- pub edge_list_indices : IndexVec < SerializedDepNodeIndex , ( u32 , u32 ) > ,
47+ edge_list_indices : IndexVec < SerializedDepNodeIndex , ( u32 , u32 ) > ,
4848 /// A flattened list of all edge targets in the graph. Edge sources are
4949 /// implicit in edge_list_indices.
50- pub edge_list_data : Vec < SerializedDepNodeIndex > ,
50+ edge_list_data : Vec < SerializedDepNodeIndex > ,
51+ /// Reciprocal map to `nodes`.
52+ index : FxHashMap < DepNode < K > , SerializedDepNodeIndex > ,
5153}
5254
5355impl < K : DepKind > Default for SerializedDepGraph < K > {
@@ -57,6 +59,7 @@ impl<K: DepKind> Default for SerializedDepGraph<K> {
5759 fingerprints : Default :: default ( ) ,
5860 edge_list_indices : Default :: default ( ) ,
5961 edge_list_data : Default :: default ( ) ,
62+ index : Default :: default ( ) ,
6063 }
6164 }
6265}
@@ -67,6 +70,30 @@ impl<K: DepKind> SerializedDepGraph<K> {
6770 let targets = self . edge_list_indices [ source] ;
6871 & self . edge_list_data [ targets. 0 as usize ..targets. 1 as usize ]
6972 }
73+
74+ #[ inline]
75+ pub fn index_to_node ( & self , dep_node_index : SerializedDepNodeIndex ) -> DepNode < K > {
76+ self . nodes [ dep_node_index]
77+ }
78+
79+ #[ inline]
80+ pub fn node_to_index_opt ( & self , dep_node : & DepNode < K > ) -> Option < SerializedDepNodeIndex > {
81+ self . index . get ( dep_node) . cloned ( )
82+ }
83+
84+ #[ inline]
85+ pub fn fingerprint_of ( & self , dep_node : & DepNode < K > ) -> Option < Fingerprint > {
86+ self . index . get ( dep_node) . map ( |& node_index| self . fingerprints [ node_index] )
87+ }
88+
89+ #[ inline]
90+ pub fn fingerprint_by_index ( & self , dep_node_index : SerializedDepNodeIndex ) -> Fingerprint {
91+ self . fingerprints [ dep_node_index]
92+ }
93+
94+ pub fn node_count ( & self ) -> usize {
95+ self . index . len ( )
96+ }
7097}
7198
7299impl < ' a , K : DepKind + Decodable < opaque:: Decoder < ' a > > > Decodable < opaque:: Decoder < ' a > >
@@ -121,7 +148,10 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
121148 } ) ?;
122149 }
123150
124- Ok ( SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data } )
151+ let index: FxHashMap < _ , _ > =
152+ nodes. iter_enumerated ( ) . map ( |( idx, & dep_node) | ( dep_node, idx) ) . collect ( ) ;
153+
154+ Ok ( SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data, index } )
125155 }
126156}
127157
0 commit comments