@@ -2,26 +2,27 @@ use rustc_data_structures::fingerprint::Fingerprint;
2
2
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
3
3
use rustc_data_structures:: profiling:: QueryInvocationId ;
4
4
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5
- use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc , RwLock } ;
5
+ use rustc_data_structures:: sync:: { AtomicU32 , Lock , Lrc , RwLock } ;
6
6
use rustc_data_structures:: unlikely;
7
7
use rustc_errors:: Diagnostic ;
8
8
use rustc_index:: vec:: IndexVec ;
9
9
use rustc_serialize:: { Encodable , Encoder } ;
10
10
11
11
use smallvec:: { smallvec, SmallVec } ;
12
- use std:: env;
13
12
use std:: hash:: Hash ;
14
13
use std:: marker:: PhantomData ;
15
14
use std:: sync:: atomic:: Ordering :: Relaxed ;
16
15
17
- use super :: debug:: EdgeFilter ;
18
16
use super :: query:: DepGraphQuery ;
19
17
use super :: serialized:: {
20
18
CurrentDepGraph , DepNodeColor , DepNodeIndex , SerializedDepGraph , SerializedDepNodeIndex ,
21
19
} ;
22
20
use super :: { DepContext , DepKind , DepNode , HasDepContext , WorkProductId } ;
23
21
use crate :: query:: QueryContext ;
24
22
23
+ #[ cfg( debug_assertions) ]
24
+ use { super :: debug:: EdgeFilter , rustc_data_structures:: sync:: AtomicU64 , std:: env} ;
25
+
25
26
#[ derive( Clone ) ]
26
27
pub struct DepGraph < K : DepKind > {
27
28
data : Option < Lrc < DepGraphData < K > > > ,
@@ -49,11 +50,6 @@ struct DepGraphData<K: DepKind> {
49
50
/// nodes and edges as well as all fingerprints of nodes that have them.
50
51
previous : RwLock < CurrentDepGraph < K > > ,
51
52
52
- /// Used to trap when a specific edge is added to the graph.
53
- /// This is used for debug purposes and is only active with `debug_assertions`.
54
- #[ allow( dead_code) ]
55
- forbidden_edge : Option < EdgeFilter > ,
56
-
57
53
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
58
54
/// their edges. This has the beneficial side-effect that multiple anonymous
59
55
/// nodes can be coalesced into one without changing the semantics of the
@@ -67,11 +63,6 @@ struct DepGraphData<K: DepKind> {
67
63
/// the `DepGraph` is created.
68
64
anon_id_seed : Fingerprint ,
69
65
70
- /// These are simple counters that are for profiling and
71
- /// debugging and only active with `debug_assertions`.
72
- total_read_count : AtomicU64 ,
73
- total_duplicate_read_count : AtomicU64 ,
74
-
75
66
/// A set of loaded diagnostics that is in the progress of being emitted.
76
67
emitting_diagnostics : Lock < FxHashSet < DepNodeIndex > > ,
77
68
@@ -82,6 +73,18 @@ struct DepGraphData<K: DepKind> {
82
73
previous_work_products : FxHashMap < WorkProductId , WorkProduct > ,
83
74
84
75
dep_node_debug : Lock < FxHashMap < DepNode < K > , String > > ,
76
+
77
+ /// Used to trap when a specific edge is added to the graph.
78
+ /// This is used for debug purposes and is only active with `debug_assertions`.
79
+ #[ cfg( debug_assertions) ]
80
+ forbidden_edge : Option < EdgeFilter > ,
81
+
82
+ /// These are simple counters that are for profiling and
83
+ /// debugging and only active with `debug_assertions`.
84
+ #[ cfg( debug_assertions) ]
85
+ total_read_count : AtomicU64 ,
86
+ #[ cfg( debug_assertions) ]
87
+ total_duplicate_read_count : AtomicU64 ,
85
88
}
86
89
87
90
pub fn hash_result < HashCtxt , R > ( hcx : & mut HashCtxt , result : & R ) -> Option < Fingerprint >
@@ -106,28 +109,28 @@ impl<K: DepKind> DepGraph<K> {
106
109
let mut stable_hasher = StableHasher :: new ( ) ;
107
110
nanos. hash ( & mut stable_hasher) ;
108
111
109
- let forbidden_edge = if cfg ! ( debug_assertions) {
110
- match env:: var ( "RUST_FORBID_DEP_GRAPH_EDGE" ) {
111
- Ok ( s) => match EdgeFilter :: new ( & s) {
112
- Ok ( f) => Some ( f) ,
113
- Err ( err) => panic ! ( "RUST_FORBID_DEP_GRAPH_EDGE invalid: {}" , err) ,
114
- } ,
115
- Err ( _) => None ,
116
- }
117
- } else {
118
- None
112
+ #[ cfg( debug_assertions) ]
113
+ let forbidden_edge = match env:: var ( "RUST_FORBID_DEP_GRAPH_EDGE" ) {
114
+ Ok ( s) => match EdgeFilter :: new ( & s) {
115
+ Ok ( f) => Some ( f) ,
116
+ Err ( err) => panic ! ( "RUST_FORBID_DEP_GRAPH_EDGE invalid: {}" , err) ,
117
+ } ,
118
+ Err ( _) => None ,
119
119
} ;
120
120
121
121
DepGraph {
122
122
data : Some ( Lrc :: new ( DepGraphData {
123
+ previous : RwLock :: new ( CurrentDepGraph :: new ( prev_graph) ) ,
124
+ emitting_diagnostics : Default :: default ( ) ,
123
125
previous_work_products : prev_work_products,
124
126
dep_node_debug : Default :: default ( ) ,
125
127
anon_id_seed : stable_hasher. finish ( ) ,
128
+ #[ cfg( debug_assertions) ]
126
129
forbidden_edge,
130
+ #[ cfg( debug_assertions) ]
127
131
total_read_count : AtomicU64 :: new ( 0 ) ,
132
+ #[ cfg( debug_assertions) ]
128
133
total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
129
- emitting_diagnostics : Default :: default ( ) ,
130
- previous : RwLock :: new ( CurrentDepGraph :: new ( prev_graph) ) ,
131
134
} ) ) ,
132
135
virtual_dep_node_index : Lrc :: new ( AtomicU32 :: new ( 0 ) ) ,
133
136
}
@@ -305,14 +308,13 @@ impl<K: DepKind> DepGraph<K> {
305
308
306
309
#[ inline]
307
310
pub fn read_index ( & self , dep_node_index : DepNodeIndex ) {
308
- if let Some ( ref data ) = self . data {
311
+ if let Some ( ref _data ) = self . data {
309
312
K :: read_deps ( |task_deps| {
310
313
if let Some ( task_deps) = task_deps {
311
314
let mut task_deps = task_deps. lock ( ) ;
312
315
let task_deps = & mut * task_deps;
313
- if cfg ! ( debug_assertions) {
314
- data. total_read_count . fetch_add ( 1 , Relaxed ) ;
315
- }
316
+ #[ cfg( debug_assertions) ]
317
+ _data. total_read_count . fetch_add ( 1 , Relaxed ) ;
316
318
317
319
// As long as we only have a low number of reads we can avoid doing a hash
318
320
// insert and potentially allocating/reallocating the hashmap
@@ -330,18 +332,17 @@ impl<K: DepKind> DepGraph<K> {
330
332
}
331
333
332
334
#[ cfg( debug_assertions) ]
333
- {
334
- if let Some ( target) = task_deps. node {
335
- if let Some ( ref forbidden_edge) = data. forbidden_edge {
336
- let src = self . dep_node_of ( dep_node_index) ;
337
- if forbidden_edge. test ( & src, & target) {
338
- panic ! ( "forbidden edge {:?} -> {:?} created" , src, target)
339
- }
335
+ if let Some ( target) = task_deps. node {
336
+ if let Some ( ref forbidden_edge) = _data. forbidden_edge {
337
+ let src = self . dep_node_of ( dep_node_index) ;
338
+ if forbidden_edge. test ( & src, & target) {
339
+ panic ! ( "forbidden edge {:?} -> {:?} created" , src, target)
340
340
}
341
341
}
342
342
}
343
- } else if cfg ! ( debug_assertions) {
344
- data. total_duplicate_read_count . fetch_add ( 1 , Relaxed ) ;
343
+ } else {
344
+ #[ cfg( debug_assertions) ]
345
+ _data. total_duplicate_read_count . fetch_add ( 1 , Relaxed ) ;
345
346
}
346
347
}
347
348
} )
@@ -750,7 +751,8 @@ impl<K: DepKind> DepGraph<K> {
750
751
eprintln ! ( "[incremental] Total Node Count: {}" , total_node_count) ;
751
752
eprintln ! ( "[incremental] Total Edge Count: {}" , total_edge_count) ;
752
753
753
- if cfg ! ( debug_assertions) {
754
+ #[ cfg( debug_assertions) ]
755
+ {
754
756
let total_edge_reads = data. total_read_count . load ( Relaxed ) ;
755
757
let total_duplicate_edge_reads = data. total_duplicate_read_count . load ( Relaxed ) ;
756
758
0 commit comments