@@ -146,26 +146,6 @@ impl<N: Node> EntryState<N> {
146
146
}
147
147
}
148
148
149
- ///
150
- /// Because there are guaranteed to be more edges than nodes in Graphs, we mark cyclic
151
- /// dependencies via a wrapper around the Node (rather than adding a byte to every
152
- /// valid edge).
153
- ///
154
- #[ derive( Clone , Debug , Eq , Hash , PartialEq ) ]
155
- pub ( crate ) enum EntryKey < N : Node > {
156
- Valid ( N ) ,
157
- Cyclic ( N ) ,
158
- }
159
-
160
- impl < N : Node > EntryKey < N > {
161
- pub ( crate ) fn content ( & self ) -> & N {
162
- match self {
163
- & EntryKey :: Valid ( ref v) => v,
164
- & EntryKey :: Cyclic ( ref v) => v,
165
- }
166
- }
167
- }
168
-
169
149
///
170
150
/// An Entry and its adjacencies.
171
151
///
@@ -174,7 +154,7 @@ pub struct Entry<N: Node> {
174
154
// TODO: This is a clone of the Node, which is also kept in the `nodes` map. It would be
175
155
// nice to avoid keeping two copies of each Node, but tracking references between the two
176
156
// maps is painful.
177
- node : EntryKey < N > ,
157
+ node : N ,
178
158
179
159
state : Arc < Mutex < EntryState < N > > > ,
180
160
}
@@ -185,15 +165,15 @@ impl<N: Node> Entry<N> {
185
165
/// the EntryId of an Entry until after it is stored in the Graph, and we need the EntryId
186
166
/// in order to run the Entry.
187
167
///
188
- pub ( crate ) fn new ( node : EntryKey < N > ) -> Entry < N > {
168
+ pub ( crate ) fn new ( node : N ) -> Entry < N > {
189
169
Entry {
190
170
node : node,
191
171
state : Arc :: new ( Mutex :: new ( EntryState :: initial ( ) ) ) ,
192
172
}
193
173
}
194
174
195
175
pub fn node ( & self ) -> & N {
196
- self . node . content ( )
176
+ & self . node
197
177
}
198
178
199
179
///
@@ -216,7 +196,7 @@ impl<N: Node> Entry<N> {
216
196
///
217
197
pub ( crate ) fn run < C > (
218
198
context_factory : & C ,
219
- entry_key : & EntryKey < N > ,
199
+ node : & N ,
220
200
entry_id : EntryId ,
221
201
run_token : RunToken ,
222
202
generation : Generation ,
@@ -228,77 +208,67 @@ impl<N: Node> Entry<N> {
228
208
{
229
209
// Increment the RunToken to uniquely identify this work.
230
210
let run_token = run_token. next ( ) ;
231
- match entry_key {
232
- & EntryKey :: Valid ( ref n) => {
233
- let context = context_factory. clone_for ( entry_id) ;
234
- let node = n. clone ( ) ;
235
-
236
- context_factory. spawn ( future:: lazy ( move || {
237
- // If we have previous result generations, compare them to all current dependency
238
- // generations (which, if they are dirty, will cause recursive cleaning). If they
239
- // match, we can consider the previous result value to be clean for reuse.
240
- let was_clean = if let Some ( previous_dep_generations) = previous_dep_generations {
241
- let context2 = context. clone ( ) ;
242
- context
243
- . graph ( )
244
- . dep_generations ( entry_id, & context)
245
- . then ( move |generation_res| match generation_res {
246
- Ok ( ref dep_generations) if dep_generations == & previous_dep_generations => {
247
- // Dependencies have not changed: Node is clean.
248
- Ok ( true )
249
- }
250
- _ => {
251
- // If dependency generations mismatched or failed to fetch, clear its
252
- // dependencies and indicate that it should re-run.
253
- context2. graph ( ) . clear_deps ( entry_id, run_token) ;
254
- Ok ( false )
255
- }
256
- } )
257
- . to_boxed ( )
258
- } else {
259
- future:: ok ( false ) . to_boxed ( )
260
- } ;
261
-
262
- // If the Node was clean, complete it. Otherwise, re-run.
263
- was_clean. and_then ( move |was_clean| {
264
- if was_clean {
265
- // No dependencies have changed: we can complete the Node without changing its
266
- // previous_result or generation.
267
- context
268
- . graph ( )
269
- . complete ( & context, entry_id, run_token, None ) ;
270
- future:: ok ( ( ) ) . to_boxed ( )
271
- } else {
272
- // The Node needs to (re-)run!
273
- let context2 = context. clone ( ) ;
274
- node
275
- . run ( context)
276
- . then ( move |res| {
277
- context2
278
- . graph ( )
279
- . complete ( & context2, entry_id, run_token, Some ( res) ) ;
280
- Ok ( ( ) )
281
- } )
282
- . to_boxed ( )
211
+ let context = context_factory. clone_for ( entry_id) ;
212
+ let node = node. clone ( ) ;
213
+
214
+ context_factory. spawn ( future:: lazy ( move || {
215
+ // If we have previous result generations, compare them to all current dependency
216
+ // generations (which, if they are dirty, will cause recursive cleaning). If they
217
+ // match, we can consider the previous result value to be clean for reuse.
218
+ let was_clean = if let Some ( previous_dep_generations) = previous_dep_generations {
219
+ let context2 = context. clone ( ) ;
220
+ context
221
+ . graph ( )
222
+ . dep_generations ( entry_id, & context)
223
+ . then ( move |generation_res| match generation_res {
224
+ Ok ( ref dep_generations) if dep_generations == & previous_dep_generations => {
225
+ // Dependencies have not changed: Node is clean.
226
+ Ok ( true )
227
+ }
228
+ _ => {
229
+ // If dependency generations mismatched or failed to fetch, clear its
230
+ // dependencies and indicate that it should re-run.
231
+ context2. graph ( ) . clear_deps ( entry_id, run_token) ;
232
+ Ok ( false )
283
233
}
284
234
} )
285
- } ) ) ;
235
+ . to_boxed ( )
236
+ } else {
237
+ future:: ok ( false ) . to_boxed ( )
238
+ } ;
286
239
287
- EntryState :: Running {
288
- waiters : Vec :: new ( ) ,
289
- start_time : Instant :: now ( ) ,
290
- run_token,
291
- generation,
292
- previous_result,
293
- dirty : false ,
240
+ // If the Node was clean, complete it. Otherwise, re-run.
241
+ was_clean. and_then ( move |was_clean| {
242
+ if was_clean {
243
+ // No dependencies have changed: we can complete the Node without changing its
244
+ // previous_result or generation.
245
+ context
246
+ . graph ( )
247
+ . complete ( & context, entry_id, run_token, None ) ;
248
+ future:: ok ( ( ) ) . to_boxed ( )
249
+ } else {
250
+ // The Node needs to (re-)run!
251
+ let context2 = context. clone ( ) ;
252
+ node
253
+ . run ( context)
254
+ . then ( move |res| {
255
+ context2
256
+ . graph ( )
257
+ . complete ( & context2, entry_id, run_token, Some ( res) ) ;
258
+ Ok ( ( ) )
259
+ } )
260
+ . to_boxed ( )
294
261
}
295
- }
296
- & EntryKey :: Cyclic ( _) => EntryState :: Completed {
297
- result : EntryResult :: Clean ( Err ( N :: Error :: cyclic ( ) ) ) ,
298
- dep_generations : Vec :: new ( ) ,
299
- run_token,
300
- generation,
301
- } ,
262
+ } )
263
+ } ) ) ;
264
+
265
+ EntryState :: Running {
266
+ waiters : Vec :: new ( ) ,
267
+ start_time : Instant :: now ( ) ,
268
+ run_token,
269
+ generation,
270
+ previous_result,
271
+ dirty : false ,
302
272
}
303
273
}
304
274
@@ -339,7 +309,7 @@ impl<N: Node> Entry<N> {
339
309
ref result,
340
310
generation,
341
311
..
342
- } if self . node . content ( ) . cacheable ( ) && !result. is_dirty ( ) => {
312
+ } if self . node . cacheable ( ) && !result. is_dirty ( ) => {
343
313
return future:: result ( result. as_ref ( ) . clone ( ) )
344
314
. map ( move |res| ( res, generation) )
345
315
. to_boxed ( ) ;
@@ -374,10 +344,10 @@ impl<N: Node> Entry<N> {
374
344
"Re-starting node {:?}. It was: previous_result={:?}, cacheable={}" ,
375
345
self . node,
376
346
result,
377
- self . node. content ( ) . cacheable( )
347
+ self . node. cacheable( )
378
348
) ;
379
349
assert ! (
380
- result. is_dirty( ) || !self . node. content ( ) . cacheable( ) ,
350
+ result. is_dirty( ) || !self . node. cacheable( ) ,
381
351
"A clean Node should not reach this point: {:?}" ,
382
352
result
383
353
) ;
@@ -394,12 +364,12 @@ impl<N: Node> Entry<N> {
394
364
entry_id,
395
365
run_token,
396
366
generation,
397
- if self . node . content ( ) . cacheable ( ) {
367
+ if self . node . cacheable ( ) {
398
368
Some ( dep_generations)
399
369
} else {
400
370
None
401
371
} ,
402
- if self . node . content ( ) . cacheable ( ) {
372
+ if self . node . cacheable ( ) {
403
373
Some ( result)
404
374
} else {
405
375
None
@@ -684,6 +654,6 @@ impl<N: Node> Entry<N> {
684
654
Some ( Err ( ref x) ) => format ! ( "{:?}" , x) ,
685
655
None => "<None>" . to_string ( ) ,
686
656
} ;
687
- format ! ( "{} == {}" , self . node. content ( ) , state) . replace ( "\" " , "\\ \" " )
657
+ format ! ( "{} == {}" , self . node, state) . replace ( "\" " , "\\ \" " )
688
658
}
689
659
}
0 commit comments