@@ -19,21 +19,24 @@ use super::debug::EdgeFilter;
19
19
20
20
pub struct DepGraphEdges {
21
21
nodes : Vec < DepNode > ,
22
- indices : FxHashMap < DepNode , IdIndex > ,
23
- edges : FxHashSet < ( IdIndex , IdIndex ) > ,
22
+ indices : FxHashMap < DepNode , DepNodeIndex > ,
23
+ edges : FxHashSet < ( DepNodeIndex , DepNodeIndex ) > ,
24
24
task_stack : Vec < OpenTask > ,
25
25
forbidden_edge : Option < EdgeFilter > ,
26
26
}
27
27
28
28
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
29
- struct IdIndex {
29
+ pub struct DepNodeIndex {
30
30
index : u32
31
31
}
32
32
33
- impl IdIndex {
34
- fn new ( v : usize ) -> IdIndex {
33
+ impl DepNodeIndex {
34
+
35
+ pub const INVALID : DepNodeIndex = DepNodeIndex { index : :: std:: u32:: MAX } ;
36
+
37
+ fn new ( v : usize ) -> DepNodeIndex {
35
38
assert ! ( ( v & 0xFFFF_FFFF ) == v) ;
36
- IdIndex { index : v as u32 }
39
+ DepNodeIndex { index : v as u32 }
37
40
}
38
41
39
42
fn index ( self ) -> usize {
@@ -80,7 +83,7 @@ impl DepGraphEdges {
80
83
}
81
84
}
82
85
83
- fn id ( & self , index : IdIndex ) -> DepNode {
86
+ fn id ( & self , index : DepNodeIndex ) -> DepNode {
84
87
self . nodes [ index. index ( ) ]
85
88
}
86
89
@@ -101,7 +104,7 @@ impl DepGraphEdges {
101
104
} ) ;
102
105
}
103
106
104
- pub fn pop_task ( & mut self , key : DepNode ) {
107
+ pub fn pop_task ( & mut self , key : DepNode ) -> DepNodeIndex {
105
108
let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
106
109
107
110
if let OpenTask :: Regular {
@@ -117,6 +120,8 @@ impl DepGraphEdges {
117
120
let source_id = self . get_or_create_node ( read) ;
118
121
self . edges . insert ( ( source_id, target_id) ) ;
119
122
}
123
+
124
+ target_id
120
125
} else {
121
126
bug ! ( "pop_task() - Expected regular task to be popped" )
122
127
}
@@ -129,7 +134,7 @@ impl DepGraphEdges {
129
134
} ) ;
130
135
}
131
136
132
- pub fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNode {
137
+ pub fn pop_anon_task ( & mut self , kind : DepKind ) -> DepNodeIndex {
133
138
let popped_node = self . task_stack . pop ( ) . unwrap ( ) ;
134
139
135
140
if let OpenTask :: Anon {
@@ -155,8 +160,8 @@ impl DepGraphEdges {
155
160
hash : fingerprint,
156
161
} ;
157
162
158
- if self . indices . contains_key ( & target_dep_node) {
159
- return target_dep_node ;
163
+ if let Some ( & index ) = self . indices . get ( & target_dep_node) {
164
+ return index ;
160
165
}
161
166
162
167
let target_id = self . get_or_create_node ( target_dep_node) ;
@@ -166,7 +171,7 @@ impl DepGraphEdges {
166
171
self . edges . insert ( ( source_id, target_id) ) ;
167
172
}
168
173
169
- target_dep_node
174
+ target_id
170
175
} else {
171
176
bug ! ( "pop_anon_task() - Expected anonymous task to be popped" )
172
177
}
@@ -210,6 +215,11 @@ impl DepGraphEdges {
210
215
}
211
216
}
212
217
218
+ pub fn read_index ( & mut self , source : DepNodeIndex ) {
219
+ let dep_node = self . nodes [ source. index ( ) ] ;
220
+ self . read ( dep_node) ;
221
+ }
222
+
213
223
pub fn query ( & self ) -> DepGraphQuery {
214
224
let edges: Vec < _ > = self . edges . iter ( )
215
225
. map ( |& ( i, j) | ( self . id ( i) , self . id ( j) ) )
@@ -229,7 +239,7 @@ impl DepGraphEdges {
229
239
}
230
240
231
241
#[ inline]
232
- fn get_or_create_node ( & mut self , dep_node : DepNode ) -> IdIndex {
242
+ fn get_or_create_node ( & mut self , dep_node : DepNode ) -> DepNodeIndex {
233
243
let DepGraphEdges {
234
244
ref mut indices,
235
245
ref mut nodes,
@@ -239,7 +249,7 @@ impl DepGraphEdges {
239
249
* indices. entry ( dep_node) . or_insert_with ( || {
240
250
let next_id = nodes. len ( ) ;
241
251
nodes. push ( dep_node) ;
242
- IdIndex :: new ( next_id)
252
+ DepNodeIndex :: new ( next_id)
243
253
} )
244
254
}
245
255
}
0 commit comments