@@ -11,7 +11,7 @@ use rustc_data_structures::outline;
11
11
use rustc_data_structures:: profiling:: QueryInvocationId ;
12
12
use rustc_data_structures:: sharded:: { self , ShardedHashMap } ;
13
13
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
14
- use rustc_data_structures:: sync:: { AtomicU64 , Lock } ;
14
+ use rustc_data_structures:: sync:: { AtomicU64 , Lock , is_dyn_thread_safe } ;
15
15
use rustc_data_structures:: unord:: UnordMap ;
16
16
use rustc_errors:: DiagInner ;
17
17
use rustc_index:: IndexVec ;
@@ -124,19 +124,11 @@ impl<D: Deps> DepGraph<D> {
124
124
prev_graph : Arc < SerializedDepGraph > ,
125
125
prev_work_products : WorkProductMap ,
126
126
encoder : FileEncoder ,
127
- record_graph : bool ,
128
- record_stats : bool ,
129
127
) -> DepGraph < D > {
130
128
let prev_graph_node_count = prev_graph. node_count ( ) ;
131
129
132
- let current = CurrentDepGraph :: new (
133
- session,
134
- prev_graph_node_count,
135
- encoder,
136
- record_graph,
137
- record_stats,
138
- Arc :: clone ( & prev_graph) ,
139
- ) ;
130
+ let current =
131
+ CurrentDepGraph :: new ( session, prev_graph_node_count, encoder, Arc :: clone ( & prev_graph) ) ;
140
132
141
133
let colors = DepNodeColorMap :: new ( prev_graph_node_count) ;
142
134
@@ -1052,17 +1044,8 @@ impl<D: Deps> DepGraph<D> {
1052
1044
}
1053
1045
}
1054
1046
1055
- pub fn print_incremental_info ( & self ) {
1056
- if let Some ( data) = & self . data {
1057
- data. current . encoder . print_incremental_info (
1058
- data. current . total_read_count . load ( Ordering :: Relaxed ) ,
1059
- data. current . total_duplicate_read_count . load ( Ordering :: Relaxed ) ,
1060
- )
1061
- }
1062
- }
1063
-
1064
1047
pub fn finish_encoding ( & self ) -> FileEncodeResult {
1065
- if let Some ( data) = & self . data { data. current . encoder . finish ( ) } else { Ok ( 0 ) }
1048
+ if let Some ( data) = & self . data { data. current . encoder . finish ( & data . current ) } else { Ok ( 0 ) }
1066
1049
}
1067
1050
1068
1051
pub ( crate ) fn next_virtual_depnode_index ( & self ) -> DepNodeIndex {
@@ -1179,17 +1162,15 @@ pub(super) struct CurrentDepGraph<D: Deps> {
1179
1162
1180
1163
/// These are simple counters that are for profiling and
1181
1164
/// debugging and only active with `debug_assertions`.
1182
- total_read_count : AtomicU64 ,
1183
- total_duplicate_read_count : AtomicU64 ,
1165
+ pub ( super ) total_read_count : AtomicU64 ,
1166
+ pub ( super ) total_duplicate_read_count : AtomicU64 ,
1184
1167
}
1185
1168
1186
1169
impl < D : Deps > CurrentDepGraph < D > {
1187
1170
fn new (
1188
1171
session : & Session ,
1189
1172
prev_graph_node_count : usize ,
1190
1173
encoder : FileEncoder ,
1191
- record_graph : bool ,
1192
- record_stats : bool ,
1193
1174
previous : Arc < SerializedDepGraph > ,
1194
1175
) -> Self {
1195
1176
let mut stable_hasher = StableHasher :: new ( ) ;
@@ -1211,14 +1192,7 @@ impl<D: Deps> CurrentDepGraph<D> {
1211
1192
session. opts . unstable_opts . incremental_verify_ich || cfg ! ( debug_assertions) ;
1212
1193
1213
1194
CurrentDepGraph {
1214
- encoder : GraphEncoder :: new (
1215
- encoder,
1216
- prev_graph_node_count,
1217
- record_graph,
1218
- record_stats,
1219
- & session. prof ,
1220
- previous,
1221
- ) ,
1195
+ encoder : GraphEncoder :: new ( session, encoder, prev_graph_node_count, previous) ,
1222
1196
anon_node_to_index : ShardedHashMap :: with_capacity (
1223
1197
// FIXME: The count estimate is off as anon nodes are only a portion of the nodes.
1224
1198
new_node_count_estimate / sharded:: shards ( ) ,
@@ -1345,6 +1319,7 @@ impl Default for TaskDeps {
1345
1319
// array, using one u32 per entry.
1346
1320
pub ( super ) struct DepNodeColorMap {
1347
1321
values : IndexVec < SerializedDepNodeIndex , AtomicU32 > ,
1322
+ sync : bool ,
1348
1323
}
1349
1324
1350
1325
const COMPRESSED_NONE : u32 = u32:: MAX ;
@@ -1353,7 +1328,10 @@ const COMPRESSED_RED: u32 = u32::MAX - 1;
1353
1328
impl DepNodeColorMap {
1354
1329
fn new ( size : usize ) -> DepNodeColorMap {
1355
1330
debug_assert ! ( COMPRESSED_RED > DepNodeIndex :: MAX_AS_U32 ) ;
1356
- DepNodeColorMap { values : ( 0 ..size) . map ( |_| AtomicU32 :: new ( COMPRESSED_NONE ) ) . collect ( ) }
1331
+ DepNodeColorMap {
1332
+ values : ( 0 ..size) . map ( |_| AtomicU32 :: new ( COMPRESSED_NONE ) ) . collect ( ) ,
1333
+ sync : is_dyn_thread_safe ( ) ,
1334
+ }
1357
1335
}
1358
1336
1359
1337
#[ inline]
@@ -1362,6 +1340,37 @@ impl DepNodeColorMap {
1362
1340
if value <= DepNodeIndex :: MAX_AS_U32 { Some ( DepNodeIndex :: from_u32 ( value) ) } else { None }
1363
1341
}
1364
1342
1343
+ /// This tries to atomically mark a node green and assign `index` as the new
1344
+ /// index. This returns `Ok` if `index` gets assigned, otherwise it returns
1345
+ /// the alreadly allocated index in `Err`.
1346
+ #[ inline]
1347
+ pub ( super ) fn try_mark_green (
1348
+ & self ,
1349
+ prev_index : SerializedDepNodeIndex ,
1350
+ index : DepNodeIndex ,
1351
+ ) -> Result < ( ) , DepNodeIndex > {
1352
+ let value = & self . values [ prev_index] ;
1353
+ if self . sync {
1354
+ match value. compare_exchange (
1355
+ COMPRESSED_NONE ,
1356
+ index. as_u32 ( ) ,
1357
+ Ordering :: Relaxed ,
1358
+ Ordering :: Relaxed ,
1359
+ ) {
1360
+ Ok ( _) => Ok ( ( ) ) ,
1361
+ Err ( v) => Err ( DepNodeIndex :: from_u32 ( v) ) ,
1362
+ }
1363
+ } else {
1364
+ let v = value. load ( Ordering :: Relaxed ) ;
1365
+ if v == COMPRESSED_NONE {
1366
+ value. store ( index. as_u32 ( ) , Ordering :: Relaxed ) ;
1367
+ Ok ( ( ) )
1368
+ } else {
1369
+ Err ( DepNodeIndex :: from_u32 ( v) )
1370
+ }
1371
+ }
1372
+ }
1373
+
1365
1374
#[ inline]
1366
1375
pub ( super ) fn get ( & self , index : SerializedDepNodeIndex ) -> Option < DepNodeColor > {
1367
1376
match self . values [ index] . load ( Ordering :: Acquire ) {
0 commit comments