@@ -37,17 +37,19 @@ rustc_index::newtype_index! {
37
37
#[ derive( Debug ) ]
38
38
pub struct SerializedDepGraph < K : DepKind > {
39
39
/// The set of all DepNodes in the graph
40
- pub nodes : IndexVec < SerializedDepNodeIndex , DepNode < K > > ,
40
+ nodes : IndexVec < SerializedDepNodeIndex , DepNode < K > > ,
41
41
/// The set of all Fingerprints in the graph. Each Fingerprint corresponds to
42
42
/// the DepNode at the same index in the nodes vector.
43
- pub fingerprints : IndexVec < SerializedDepNodeIndex , Fingerprint > ,
43
+ fingerprints : IndexVec < SerializedDepNodeIndex , Fingerprint > ,
44
44
/// For each DepNode, stores the list of edges originating from that
45
45
/// DepNode. Encoded as a [start, end) pair indexing into edge_list_data,
46
46
/// 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 ) > ,
48
48
/// A flattened list of all edge targets in the graph. Edge sources are
49
49
/// 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 > ,
51
53
}
52
54
53
55
impl < K : DepKind > Default for SerializedDepGraph < K > {
@@ -57,6 +59,7 @@ impl<K: DepKind> Default for SerializedDepGraph<K> {
57
59
fingerprints : Default :: default ( ) ,
58
60
edge_list_indices : Default :: default ( ) ,
59
61
edge_list_data : Default :: default ( ) ,
62
+ index : Default :: default ( ) ,
60
63
}
61
64
}
62
65
}
@@ -67,6 +70,30 @@ impl<K: DepKind> SerializedDepGraph<K> {
67
70
let targets = self . edge_list_indices [ source] ;
68
71
& self . edge_list_data [ targets. 0 as usize ..targets. 1 as usize ]
69
72
}
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
+ }
70
97
}
71
98
72
99
impl < ' 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<
121
148
} ) ?;
122
149
}
123
150
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 } )
125
155
}
126
156
}
127
157
0 commit comments