@@ -44,6 +44,7 @@ rustc_index::newtype_index! {
44
44
45
45
impl DepNodeIndex {
46
46
pub const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
47
+ pub const DUMMY_ANON : DepNodeIndex = DepNodeIndex :: from_u32 ( 0 ) ;
47
48
}
48
49
49
50
impl std:: convert:: From < DepNodeIndex > for QueryInvocationId {
@@ -108,6 +109,7 @@ where
108
109
109
110
impl < K : DepKind > DepGraph < K > {
110
111
pub fn new (
112
+ profiler : & SelfProfilerRef ,
111
113
prev_graph : SerializedDepGraph < K > ,
112
114
prev_work_products : FxHashMap < WorkProductId , WorkProduct > ,
113
115
encoder : FileEncoder ,
@@ -116,16 +118,23 @@ impl<K: DepKind> DepGraph<K> {
116
118
) -> DepGraph < K > {
117
119
let prev_graph_node_count = prev_graph. node_count ( ) ;
118
120
121
+ let current =
122
+ CurrentDepGraph :: new ( prev_graph_node_count, encoder, record_graph, record_stats) ;
123
+
124
+ // Instantiate an *always green* node for dependency-less anonymous queries.
125
+ let _green_node_index = current. intern_new_node (
126
+ profiler,
127
+ DepNode { kind : DepKind :: NULL , hash : current. anon_id_seed . into ( ) } ,
128
+ smallvec ! [ ] ,
129
+ Fingerprint :: ZERO ,
130
+ ) ;
131
+ debug_assert_eq ! ( _green_node_index, DepNodeIndex :: DUMMY_ANON ) ;
132
+
119
133
DepGraph {
120
134
data : Some ( Lrc :: new ( DepGraphData {
121
135
previous_work_products : prev_work_products,
122
136
dep_node_debug : Default :: default ( ) ,
123
- current : CurrentDepGraph :: new (
124
- prev_graph_node_count,
125
- encoder,
126
- record_graph,
127
- record_stats,
128
- ) ,
137
+ current,
129
138
emitting_diagnostics : Default :: default ( ) ,
130
139
emitting_diagnostics_cond_var : Condvar :: new ( ) ,
131
140
previous : prev_graph,
@@ -287,29 +296,42 @@ impl<K: DepKind> DepGraph<K> {
287
296
let task_deps = Lock :: new ( TaskDeps :: default ( ) ) ;
288
297
let result = K :: with_deps ( Some ( & task_deps) , op) ;
289
298
let task_deps = task_deps. into_inner ( ) ;
299
+ let task_deps = task_deps. reads ;
290
300
291
- // The dep node indices are hashed here instead of hashing the dep nodes of the
292
- // dependencies. These indices may refer to different nodes per session, but this isn't
293
- // a problem here because we that ensure the final dep node hash is per session only by
294
- // combining it with the per session random number `anon_id_seed`. This hash only need
295
- // to map the dependencies to a single value on a per session basis.
296
- let mut hasher = StableHasher :: new ( ) ;
297
- task_deps. reads . hash ( & mut hasher) ;
298
-
299
- let target_dep_node = DepNode {
300
- kind : dep_kind,
301
- // Fingerprint::combine() is faster than sending Fingerprint
302
- // through the StableHasher (at least as long as StableHasher
303
- // is so slow).
304
- hash : data. current . anon_id_seed . combine ( hasher. finish ( ) ) . into ( ) ,
305
- } ;
301
+ let dep_node_index = match task_deps. len ( ) {
302
+ 0 => {
303
+ // Dependency-less anonymous nodes can safely be replaced by a dummy node.
304
+ DepNodeIndex :: DUMMY_ANON
305
+ }
306
+ 1 => {
307
+ // When there is only one dependency, don't bother creating a node.
308
+ task_deps[ 0 ]
309
+ }
310
+ _ => {
311
+ // The dep node indices are hashed here instead of hashing the dep nodes of the
312
+ // dependencies. These indices may refer to different nodes per session, but this isn't
313
+ // a problem here because we that ensure the final dep node hash is per session only by
314
+ // combining it with the per session random number `anon_id_seed`. This hash only need
315
+ // to map the dependencies to a single value on a per session basis.
316
+ let mut hasher = StableHasher :: new ( ) ;
317
+ task_deps. hash ( & mut hasher) ;
318
+
319
+ let target_dep_node = DepNode {
320
+ kind : dep_kind,
321
+ // Fingerprint::combine() is faster than sending Fingerprint
322
+ // through the StableHasher (at least as long as StableHasher
323
+ // is so slow).
324
+ hash : data. current . anon_id_seed . combine ( hasher. finish ( ) ) . into ( ) ,
325
+ } ;
306
326
307
- let dep_node_index = data. current . intern_new_node (
308
- cx. profiler ( ) ,
309
- target_dep_node,
310
- task_deps. reads ,
311
- Fingerprint :: ZERO ,
312
- ) ;
327
+ data. current . intern_new_node (
328
+ cx. profiler ( ) ,
329
+ target_dep_node,
330
+ task_deps,
331
+ Fingerprint :: ZERO ,
332
+ )
333
+ }
334
+ } ;
313
335
314
336
( result, dep_node_index)
315
337
} else {
0 commit comments