1
1
use rustc_data_structures:: fingerprint:: Fingerprint ;
2
2
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
3
- use rustc_data_structures:: profiling:: { EventId , QueryInvocationId , SelfProfilerRef } ;
3
+ use rustc_data_structures:: profiling:: { QueryInvocationId , SelfProfilerRef } ;
4
4
use rustc_data_structures:: sharded:: { self , Sharded } ;
5
5
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
6
- use rustc_data_structures:: steal:: Steal ;
7
6
use rustc_data_structures:: sync:: { AtomicU32 , AtomicU64 , Lock , Lrc } ;
8
7
use rustc_data_structures:: unord:: UnordMap ;
9
8
use rustc_index:: IndexVec ;
@@ -14,6 +13,7 @@ use std::fmt::Debug;
14
13
use std:: hash:: Hash ;
15
14
use std:: marker:: PhantomData ;
16
15
use std:: sync:: atomic:: Ordering ;
16
+ use std:: sync:: Arc ;
17
17
18
18
use super :: query:: DepGraphQuery ;
19
19
use super :: serialized:: { GraphEncoder , SerializedDepGraph , SerializedDepNodeIndex } ;
@@ -82,7 +82,7 @@ pub(crate) struct DepGraphData<D: Deps> {
82
82
83
83
/// The dep-graph from the previous compilation session. It contains all
84
84
/// nodes and edges as well as all fingerprints of nodes that have them.
85
- previous : SerializedDepGraph ,
85
+ previous : Arc < SerializedDepGraph > ,
86
86
87
87
colors : DepNodeColorMap ,
88
88
@@ -114,7 +114,7 @@ where
114
114
impl < D : Deps > DepGraph < D > {
115
115
pub fn new (
116
116
profiler : & SelfProfilerRef ,
117
- prev_graph : SerializedDepGraph ,
117
+ prev_graph : Arc < SerializedDepGraph > ,
118
118
prev_work_products : WorkProductMap ,
119
119
encoder : FileEncoder ,
120
120
record_graph : bool ,
@@ -128,13 +128,13 @@ impl<D: Deps> DepGraph<D> {
128
128
encoder,
129
129
record_graph,
130
130
record_stats,
131
+ prev_graph. clone ( ) ,
131
132
) ;
132
133
133
134
let colors = DepNodeColorMap :: new ( prev_graph_node_count) ;
134
135
135
136
// Instantiate a dependy-less node only once for anonymous queries.
136
137
let _green_node_index = current. intern_new_node (
137
- profiler,
138
138
DepNode { kind : D :: DEP_KIND_NULL , hash : current. anon_id_seed . into ( ) } ,
139
139
EdgesVec :: new ( ) ,
140
140
Fingerprint :: ZERO ,
@@ -143,7 +143,6 @@ impl<D: Deps> DepGraph<D> {
143
143
144
144
// Instantiate a dependy-less red node only once for anonymous queries.
145
145
let ( red_node_index, red_node_prev_index_and_color) = current. intern_node (
146
- profiler,
147
146
& prev_graph,
148
147
DepNode { kind : D :: DEP_KIND_RED , hash : Fingerprint :: ZERO . into ( ) } ,
149
148
EdgesVec :: new ( ) ,
@@ -196,7 +195,7 @@ impl<D: Deps> DepGraph<D> {
196
195
197
196
pub fn with_query ( & self , f : impl Fn ( & DepGraphQuery ) ) {
198
197
if let Some ( data) = & self . data {
199
- data. current . encoder . borrow ( ) . with_query ( f)
198
+ data. current . encoder . with_query ( f)
200
199
}
201
200
}
202
201
@@ -372,13 +371,8 @@ impl<D: Deps> DepGraphData<D> {
372
371
hash_result. map ( |f| dcx. with_stable_hashing_context ( |mut hcx| f ( & mut hcx, & result) ) ) ;
373
372
374
373
// Intern the new `DepNode`.
375
- let ( dep_node_index, prev_and_color) = self . current . intern_node (
376
- dcx. profiler ( ) ,
377
- & self . previous ,
378
- key,
379
- edges,
380
- current_fingerprint,
381
- ) ;
374
+ let ( dep_node_index, prev_and_color) =
375
+ self . current . intern_node ( & self . previous , key, edges, current_fingerprint) ;
382
376
383
377
hashing_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
384
378
@@ -443,12 +437,7 @@ impl<D: Deps> DepGraphData<D> {
443
437
hash : self . current . anon_id_seed . combine ( hasher. finish ( ) ) . into ( ) ,
444
438
} ;
445
439
446
- self . current . intern_new_node (
447
- cx. profiler ( ) ,
448
- target_dep_node,
449
- task_deps,
450
- Fingerprint :: ZERO ,
451
- )
440
+ self . current . intern_new_node ( target_dep_node, task_deps, Fingerprint :: ZERO )
452
441
}
453
442
} ;
454
443
@@ -585,13 +574,8 @@ impl<D: Deps> DepGraph<D> {
585
574
} ) ;
586
575
587
576
// Intern the new `DepNode` with the dependencies up-to-now.
588
- let ( dep_node_index, prev_and_color) = data. current . intern_node (
589
- cx. profiler ( ) ,
590
- & data. previous ,
591
- node,
592
- edges,
593
- current_fingerprint,
594
- ) ;
577
+ let ( dep_node_index, prev_and_color) =
578
+ data. current . intern_node ( & data. previous , node, edges, current_fingerprint) ;
595
579
596
580
hashing_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
597
581
@@ -871,11 +855,8 @@ impl<D: Deps> DepGraphData<D> {
871
855
872
856
// We allocating an entry for the node in the current dependency graph and
873
857
// adding all the appropriate edges imported from the previous graph
874
- let dep_node_index = self . current . promote_node_and_deps_to_current (
875
- qcx. dep_context ( ) . profiler ( ) ,
876
- & self . previous ,
877
- prev_dep_node_index,
878
- ) ;
858
+ let dep_node_index =
859
+ self . current . promote_node_and_deps_to_current ( & self . previous , prev_dep_node_index) ;
879
860
880
861
// ... emitting any stored diagnostic ...
881
862
@@ -974,19 +955,15 @@ impl<D: Deps> DepGraph<D> {
974
955
975
956
pub fn print_incremental_info ( & self ) {
976
957
if let Some ( data) = & self . data {
977
- data. current . encoder . borrow ( ) . print_incremental_info (
958
+ data. current . encoder . print_incremental_info (
978
959
data. current . total_read_count . load ( Ordering :: Relaxed ) ,
979
960
data. current . total_duplicate_read_count . load ( Ordering :: Relaxed ) ,
980
961
)
981
962
}
982
963
}
983
964
984
- pub fn finish_encoding ( & self , profiler : & SelfProfilerRef ) -> FileEncodeResult {
985
- if let Some ( data) = & self . data {
986
- data. current . encoder . steal ( ) . finish ( profiler)
987
- } else {
988
- Ok ( 0 )
989
- }
965
+ pub fn finish_encoding ( & self ) -> FileEncodeResult {
966
+ if let Some ( data) = & self . data { data. current . encoder . finish ( ) } else { Ok ( 0 ) }
990
967
}
991
968
992
969
pub ( crate ) fn next_virtual_depnode_index ( & self ) -> DepNodeIndex {
@@ -1069,7 +1046,7 @@ rustc_index::newtype_index! {
1069
1046
/// manipulating both, we acquire `new_node_to_index` or `prev_index_to_index`
1070
1047
/// first, and `data` second.
1071
1048
pub ( super ) struct CurrentDepGraph < D : Deps > {
1072
- encoder : Steal < GraphEncoder < D > > ,
1049
+ encoder : GraphEncoder < D > ,
1073
1050
new_node_to_index : Sharded < FxHashMap < DepNode , DepNodeIndex > > ,
1074
1051
prev_index_to_index : Lock < IndexVec < SerializedDepNodeIndex , Option < DepNodeIndex > > > ,
1075
1052
@@ -1100,12 +1077,6 @@ pub(super) struct CurrentDepGraph<D: Deps> {
1100
1077
/// debugging and only active with `debug_assertions`.
1101
1078
total_read_count : AtomicU64 ,
1102
1079
total_duplicate_read_count : AtomicU64 ,
1103
-
1104
- /// The cached event id for profiling node interning. This saves us
1105
- /// from having to look up the event id every time we intern a node
1106
- /// which may incur too much overhead.
1107
- /// This will be None if self-profiling is disabled.
1108
- node_intern_event_id : Option < EventId > ,
1109
1080
}
1110
1081
1111
1082
impl < D : Deps > CurrentDepGraph < D > {
@@ -1115,6 +1086,7 @@ impl<D: Deps> CurrentDepGraph<D> {
1115
1086
encoder : FileEncoder ,
1116
1087
record_graph : bool ,
1117
1088
record_stats : bool ,
1089
+ previous : Arc < SerializedDepGraph > ,
1118
1090
) -> Self {
1119
1091
use std:: time:: { SystemTime , UNIX_EPOCH } ;
1120
1092
@@ -1140,17 +1112,15 @@ impl<D: Deps> CurrentDepGraph<D> {
1140
1112
1141
1113
let new_node_count_estimate = 102 * prev_graph_node_count / 100 + 200 ;
1142
1114
1143
- let node_intern_event_id = profiler
1144
- . get_or_alloc_cached_string ( "incr_comp_intern_dep_graph_node" )
1145
- . map ( EventId :: from_label) ;
1146
-
1147
1115
CurrentDepGraph {
1148
- encoder : Steal :: new ( GraphEncoder :: new (
1116
+ encoder : GraphEncoder :: new (
1149
1117
encoder,
1150
1118
prev_graph_node_count,
1151
1119
record_graph,
1152
1120
record_stats,
1153
- ) ) ,
1121
+ profiler,
1122
+ previous,
1123
+ ) ,
1154
1124
new_node_to_index : Sharded :: new ( || {
1155
1125
FxHashMap :: with_capacity_and_hasher (
1156
1126
new_node_count_estimate / sharded:: shards ( ) ,
@@ -1165,7 +1135,6 @@ impl<D: Deps> CurrentDepGraph<D> {
1165
1135
fingerprints : Lock :: new ( IndexVec :: from_elem_n ( None , new_node_count_estimate) ) ,
1166
1136
total_read_count : AtomicU64 :: new ( 0 ) ,
1167
1137
total_duplicate_read_count : AtomicU64 :: new ( 0 ) ,
1168
- node_intern_event_id,
1169
1138
}
1170
1139
}
1171
1140
@@ -1183,16 +1152,14 @@ impl<D: Deps> CurrentDepGraph<D> {
1183
1152
#[ inline( always) ]
1184
1153
fn intern_new_node (
1185
1154
& self ,
1186
- profiler : & SelfProfilerRef ,
1187
1155
key : DepNode ,
1188
1156
edges : EdgesVec ,
1189
1157
current_fingerprint : Fingerprint ,
1190
1158
) -> DepNodeIndex {
1191
1159
let dep_node_index = match self . new_node_to_index . lock_shard_by_value ( & key) . entry ( key) {
1192
1160
Entry :: Occupied ( entry) => * entry. get ( ) ,
1193
1161
Entry :: Vacant ( entry) => {
1194
- let dep_node_index =
1195
- self . encoder . borrow ( ) . send ( profiler, key, current_fingerprint, edges) ;
1162
+ let dep_node_index = self . encoder . send ( key, current_fingerprint, edges) ;
1196
1163
entry. insert ( dep_node_index) ;
1197
1164
dep_node_index
1198
1165
}
@@ -1206,25 +1173,19 @@ impl<D: Deps> CurrentDepGraph<D> {
1206
1173
1207
1174
fn intern_node (
1208
1175
& self ,
1209
- profiler : & SelfProfilerRef ,
1210
1176
prev_graph : & SerializedDepGraph ,
1211
1177
key : DepNode ,
1212
1178
edges : EdgesVec ,
1213
1179
fingerprint : Option < Fingerprint > ,
1214
1180
) -> ( DepNodeIndex , Option < ( SerializedDepNodeIndex , DepNodeColor ) > ) {
1215
- // Get timer for profiling `DepNode` interning
1216
- let _node_intern_timer =
1217
- self . node_intern_event_id . map ( |eid| profiler. generic_activity_with_event_id ( eid) ) ;
1218
-
1219
1181
if let Some ( prev_index) = prev_graph. node_to_index_opt ( & key) {
1220
1182
let get_dep_node_index = |fingerprint| {
1221
1183
let mut prev_index_to_index = self . prev_index_to_index . lock ( ) ;
1222
1184
1223
1185
let dep_node_index = match prev_index_to_index[ prev_index] {
1224
1186
Some ( dep_node_index) => dep_node_index,
1225
1187
None => {
1226
- let dep_node_index =
1227
- self . encoder . borrow ( ) . send ( profiler, key, fingerprint, edges) ;
1188
+ let dep_node_index = self . encoder . send ( key, fingerprint, edges) ;
1228
1189
prev_index_to_index[ prev_index] = Some ( dep_node_index) ;
1229
1190
dep_node_index
1230
1191
}
@@ -1261,15 +1222,14 @@ impl<D: Deps> CurrentDepGraph<D> {
1261
1222
let fingerprint = fingerprint. unwrap_or ( Fingerprint :: ZERO ) ;
1262
1223
1263
1224
// This is a new node: it didn't exist in the previous compilation session.
1264
- let dep_node_index = self . intern_new_node ( profiler , key, edges, fingerprint) ;
1225
+ let dep_node_index = self . intern_new_node ( key, edges, fingerprint) ;
1265
1226
1266
1227
( dep_node_index, None )
1267
1228
}
1268
1229
}
1269
1230
1270
1231
fn promote_node_and_deps_to_current (
1271
1232
& self ,
1272
- profiler : & SelfProfilerRef ,
1273
1233
prev_graph : & SerializedDepGraph ,
1274
1234
prev_index : SerializedDepNodeIndex ,
1275
1235
) -> DepNodeIndex {
@@ -1280,16 +1240,14 @@ impl<D: Deps> CurrentDepGraph<D> {
1280
1240
match prev_index_to_index[ prev_index] {
1281
1241
Some ( dep_node_index) => dep_node_index,
1282
1242
None => {
1283
- let key = prev_graph. index_to_node ( prev_index) ;
1284
- let edges = prev_graph
1285
- . edge_targets_from ( prev_index)
1286
- . map ( |i| prev_index_to_index[ i] . unwrap ( ) )
1287
- . collect ( ) ;
1288
- let fingerprint = prev_graph. fingerprint_by_index ( prev_index) ;
1289
- let dep_node_index = self . encoder . borrow ( ) . send ( profiler, key, fingerprint, edges) ;
1243
+ let dep_node_index = self . encoder . promote ( prev_index, & mut * prev_index_to_index) ;
1290
1244
prev_index_to_index[ prev_index] = Some ( dep_node_index) ;
1291
1245
#[ cfg( debug_assertions) ]
1292
- self . record_edge ( dep_node_index, key, fingerprint) ;
1246
+ self . record_edge (
1247
+ dep_node_index,
1248
+ prev_graph. index_to_node ( prev_index) ,
1249
+ prev_graph. fingerprint_by_index ( prev_index) ,
1250
+ ) ;
1293
1251
dep_node_index
1294
1252
}
1295
1253
}
0 commit comments