@@ -2,6 +2,7 @@ use crate::ty::{self, TyCtxt};
2
2
use errors:: Diagnostic ;
3
3
use parking_lot:: { Condvar , Mutex } ;
4
4
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
5
+ use rustc_data_structures:: profiling:: QueryInvocationId ;
5
6
use rustc_data_structures:: sharded:: { self , Sharded } ;
6
7
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
7
8
use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , Ordering } ;
@@ -11,7 +12,7 @@ use std::collections::hash_map::Entry;
11
12
use std:: env;
12
13
use std:: hash:: Hash ;
13
14
use std:: mem;
14
- use std:: sync:: atomic:: Ordering :: SeqCst ;
15
+ use std:: sync:: atomic:: Ordering :: Relaxed ;
15
16
16
17
use crate :: ich:: { Fingerprint , StableHashingContext , StableHashingContextProvider } ;
17
18
@@ -25,6 +26,12 @@ use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
25
26
#[ derive( Clone ) ]
26
27
pub struct DepGraph {
27
28
data : Option < Lrc < DepGraphData > > ,
29
+
30
+ /// This field is used for assigning DepNodeIndices when running in
31
+ /// non-incremental mode. Even in non-incremental mode we make sure that
32
+ /// each task has a `DepNodeIndex` that uniquely identifies it. This unique
33
+ /// ID is used for self-profiling.
34
+ virtual_dep_node_index : Lrc < AtomicU32 > ,
28
35
}
29
36
30
37
rustc_index:: newtype_index! {
@@ -35,6 +42,13 @@ impl DepNodeIndex {
35
42
pub const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
36
43
}
37
44
45
+ impl std:: convert:: From < DepNodeIndex > for QueryInvocationId {
46
+ #[ inline]
47
+ fn from ( dep_node_index : DepNodeIndex ) -> Self {
48
+ QueryInvocationId ( dep_node_index. as_u32 ( ) )
49
+ }
50
+ }
51
+
38
52
#[ derive( PartialEq ) ]
39
53
pub enum DepNodeColor {
40
54
Red ,
@@ -105,11 +119,12 @@ impl DepGraph {
105
119
previous : prev_graph,
106
120
colors : DepNodeColorMap :: new ( prev_graph_node_count) ,
107
121
} ) ) ,
122
+ virtual_dep_node_index : Lrc :: new ( AtomicU32 :: new ( 0 ) ) ,
108
123
}
109
124
}
110
125
111
126
pub fn new_disabled ( ) -> DepGraph {
112
- DepGraph { data : None }
127
+ DepGraph { data : None , virtual_dep_node_index : Lrc :: new ( AtomicU32 :: new ( 0 ) ) }
113
128
}
114
129
115
130
/// Returns `true` if we are actually building the full dep-graph, and `false` otherwise.
@@ -322,7 +337,7 @@ impl DepGraph {
322
337
323
338
( result, dep_node_index)
324
339
} else {
325
- ( task ( cx, arg) , DepNodeIndex :: INVALID )
340
+ ( task ( cx, arg) , self . next_virtual_depnode_index ( ) )
326
341
}
327
342
}
328
343
@@ -352,7 +367,7 @@ impl DepGraph {
352
367
let dep_node_index = data. current . complete_anon_task ( dep_kind, task_deps) ;
353
368
( result, dep_node_index)
354
369
} else {
355
- ( op ( ) , DepNodeIndex :: INVALID )
370
+ ( op ( ) , self . next_virtual_depnode_index ( ) )
356
371
}
357
372
}
358
373
@@ -478,8 +493,8 @@ impl DepGraph {
478
493
let current_dep_graph = & self . data . as_ref ( ) . unwrap ( ) . current ;
479
494
480
495
Some ( (
481
- current_dep_graph. total_read_count . load ( SeqCst ) ,
482
- current_dep_graph. total_duplicate_read_count . load ( SeqCst ) ,
496
+ current_dep_graph. total_read_count . load ( Relaxed ) ,
497
+ current_dep_graph. total_duplicate_read_count . load ( Relaxed ) ,
483
498
) )
484
499
} else {
485
500
None
@@ -877,6 +892,11 @@ impl DepGraph {
877
892
}
878
893
}
879
894
}
895
+
896
+ fn next_virtual_depnode_index ( & self ) -> DepNodeIndex {
897
+ let index = self . virtual_dep_node_index . fetch_add ( 1 , Relaxed ) ;
898
+ DepNodeIndex :: from_u32 ( index)
899
+ }
880
900
}
881
901
882
902
/// A "work product" is an intermediate result that we save into the
@@ -1087,7 +1107,7 @@ impl DepGraphData {
1087
1107
if let Some ( task_deps) = icx. task_deps {
1088
1108
let mut task_deps = task_deps. lock ( ) ;
1089
1109
if cfg ! ( debug_assertions) {
1090
- self . current . total_read_count . fetch_add ( 1 , SeqCst ) ;
1110
+ self . current . total_read_count . fetch_add ( 1 , Relaxed ) ;
1091
1111
}
1092
1112
if task_deps. read_set . insert ( source) {
1093
1113
task_deps. reads . push ( source) ;
@@ -1105,7 +1125,7 @@ impl DepGraphData {
1105
1125
}
1106
1126
}
1107
1127
} else if cfg ! ( debug_assertions) {
1108
- self . current . total_duplicate_read_count . fetch_add ( 1 , SeqCst ) ;
1128
+ self . current . total_duplicate_read_count . fetch_add ( 1 , Relaxed ) ;
1109
1129
}
1110
1130
}
1111
1131
} )
0 commit comments