@@ -5,6 +5,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
5
5
use smallvec:: SmallVec ;
6
6
use rustc_data_structures:: sync:: { Lrc , Lock , AtomicU32 , Ordering } ;
7
7
use std:: env;
8
+ use std:: fs:: File ;
8
9
use std:: hash:: Hash ;
9
10
use std:: collections:: hash_map:: Entry ;
10
11
use crate :: ty:: { self , TyCtxt } ;
@@ -17,7 +18,7 @@ use super::debug::EdgeFilter;
17
18
use super :: dep_node:: { DepNode , DepKind , WorkProductId } ;
18
19
use super :: query:: DepGraphQuery ;
19
20
use super :: safe:: DepGraphSafe ;
20
- use super :: serialized:: { SerializedDepGraph , SerializedDepNodeIndex } ;
21
+ use super :: serialized:: { SerializedDepNodeIndex , Serializer } ;
21
22
use super :: prev:: PreviousDepGraph ;
22
23
23
24
#[ derive( Clone ) ]
@@ -30,7 +31,7 @@ newtype_index! {
30
31
}
31
32
32
33
impl DepNodeIndex {
33
- const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
34
+ pub ( super ) const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
34
35
}
35
36
36
37
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
@@ -76,7 +77,7 @@ struct DepGraphData {
76
77
dep_node_debug : Lock < FxHashMap < DepNode , String > > ,
77
78
78
79
// Used for testing, only populated when -Zquery-dep-graph is specified.
79
- loaded_from_cache : Lock < FxHashMap < DepNodeIndex , bool > > ,
80
+ loaded_from_cache : Lock < FxHashMap < DepNode , bool > > ,
80
81
}
81
82
82
83
pub fn hash_result < R > ( hcx : & mut StableHashingContext < ' _ > , result : & R ) -> Option < Fingerprint >
@@ -91,15 +92,18 @@ where
91
92
92
93
impl DepGraph {
93
94
94
- pub fn new ( prev_graph : PreviousDepGraph ,
95
- prev_work_products : FxHashMap < WorkProductId , WorkProduct > ) -> DepGraph {
95
+ pub fn new (
96
+ prev_graph : PreviousDepGraph ,
97
+ prev_work_products : FxHashMap < WorkProductId , WorkProduct > ,
98
+ file : File ,
99
+ ) -> DepGraph {
96
100
let prev_graph_node_count = prev_graph. node_count ( ) ;
97
101
98
102
DepGraph {
99
103
data : Some ( Lrc :: new ( DepGraphData {
100
104
previous_work_products : prev_work_products,
101
105
dep_node_debug : Default :: default ( ) ,
102
- current : Lock :: new ( CurrentDepGraph :: new ( prev_graph_node_count) ) ,
106
+ current : Lock :: new ( CurrentDepGraph :: new ( prev_graph_node_count, file ) ) ,
103
107
emitted_diagnostics : Default :: default ( ) ,
104
108
emitted_diagnostics_cond_var : Condvar :: new ( ) ,
105
109
previous : prev_graph,
@@ -122,6 +126,8 @@ impl DepGraph {
122
126
}
123
127
124
128
pub fn query ( & self ) -> DepGraphQuery {
129
+ // FIXME
130
+ panic ! ( ) /*
125
131
let current_dep_graph = self.data.as_ref().unwrap().current.borrow();
126
132
let nodes: Vec<_> = current_dep_graph.data.iter().map(|n| n.node).collect();
127
133
let mut edges = Vec::new();
@@ -133,7 +139,7 @@ impl DepGraph {
133
139
}
134
140
}
135
141
136
- DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
142
+ DepGraphQuery::new(&nodes[..], &edges[..])*/
137
143
}
138
144
139
145
pub fn assert_ignored ( & self )
@@ -436,9 +442,10 @@ impl DepGraph {
436
442
}
437
443
438
444
#[ inline]
439
- pub fn fingerprint_of ( & self , dep_node_index : DepNodeIndex ) -> Fingerprint {
445
+ pub fn fingerprint_of ( & self , _dep_node_index : DepNodeIndex ) -> Fingerprint {
446
+ panic ! ( ) /*
440
447
let current = self.data.as_ref().expect("dep graph enabled").current.borrow_mut();
441
- current. data [ dep_node_index] . fingerprint
448
+ current.data[dep_node_index].fingerprint*/
442
449
}
443
450
444
451
pub fn prev_fingerprint_of ( & self , dep_node : & DepNode ) -> Option < Fingerprint > {
@@ -501,41 +508,9 @@ impl DepGraph {
501
508
}
502
509
}
503
510
504
- pub fn serialize ( & self ) -> SerializedDepGraph {
505
- let current_dep_graph = self . data . as_ref ( ) . unwrap ( ) . current . borrow ( ) ;
506
-
507
- let fingerprints: IndexVec < SerializedDepNodeIndex , _ > =
508
- current_dep_graph. data . iter ( ) . map ( |d| d. fingerprint ) . collect ( ) ;
509
- let nodes: IndexVec < SerializedDepNodeIndex , _ > =
510
- current_dep_graph. data . iter ( ) . map ( |d| d. node ) . collect ( ) ;
511
-
512
- let total_edge_count: usize = current_dep_graph. data . iter ( )
513
- . map ( |d| d. edges . len ( ) )
514
- . sum ( ) ;
515
-
516
- let mut edge_list_indices = IndexVec :: with_capacity ( nodes. len ( ) ) ;
517
- let mut edge_list_data = Vec :: with_capacity ( total_edge_count) ;
518
-
519
- for ( current_dep_node_index, edges) in current_dep_graph. data . iter_enumerated ( )
520
- . map ( |( i, d) | ( i, & d. edges ) ) {
521
- let start = edge_list_data. len ( ) as u32 ;
522
- // This should really just be a memcpy :/
523
- edge_list_data. extend ( edges. iter ( ) . map ( |i| SerializedDepNodeIndex :: new ( i. index ( ) ) ) ) ;
524
- let end = edge_list_data. len ( ) as u32 ;
525
-
526
- debug_assert_eq ! ( current_dep_node_index. index( ) , edge_list_indices. len( ) ) ;
527
- edge_list_indices. push ( ( start, end) ) ;
528
- }
529
-
530
- debug_assert ! ( edge_list_data. len( ) <= :: std:: u32 :: MAX as usize ) ;
531
- debug_assert_eq ! ( edge_list_data. len( ) , total_edge_count) ;
532
-
533
- SerializedDepGraph {
534
- nodes,
535
- fingerprints,
536
- edge_list_indices,
537
- edge_list_data,
538
- }
511
+ pub fn serialize ( & self ) {
512
+ // FIXME: Can this deadlock?
513
+ self . data . as_ref ( ) . unwrap ( ) . current . lock ( ) . serializer . complete ( )
539
514
}
540
515
541
516
pub fn node_color ( & self , dep_node : & DepNode ) -> Option < DepNodeColor > {
@@ -871,23 +846,20 @@ impl DepGraph {
871
846
}
872
847
}
873
848
874
- pub fn mark_loaded_from_cache ( & self , dep_node_index : DepNodeIndex , state : bool ) {
875
- debug ! ( "mark_loaded_from_cache({:?}, {})" ,
876
- self . data. as_ref( ) . unwrap( ) . current. borrow( ) . data[ dep_node_index] . node,
877
- state) ;
849
+ pub fn mark_loaded_from_cache ( & self , dep_node : DepNode , state : bool ) {
850
+ debug ! ( "mark_loaded_from_cache({:?}, {})" , dep_node, state) ;
878
851
879
852
self . data
880
853
. as_ref ( )
881
854
. unwrap ( )
882
855
. loaded_from_cache
883
856
. borrow_mut ( )
884
- . insert ( dep_node_index , state) ;
857
+ . insert ( dep_node , state) ;
885
858
}
886
859
887
860
pub fn was_loaded_from_cache ( & self , dep_node : & DepNode ) -> Option < bool > {
888
861
let data = self . data . as_ref ( ) . unwrap ( ) ;
889
- let dep_node_index = data. current . borrow ( ) . node_to_node_index [ dep_node] ;
890
- data. loaded_from_cache . borrow ( ) . get ( & dep_node_index) . cloned ( )
862
+ data. loaded_from_cache . borrow ( ) . get ( & dep_node) . cloned ( )
891
863
}
892
864
}
893
865
@@ -936,15 +908,15 @@ pub enum WorkProductFileKind {
936
908
BytecodeCompressed ,
937
909
}
938
910
939
- #[ derive( Clone ) ]
940
- struct DepNodeData {
941
- node : DepNode ,
942
- edges : SmallVec < [ DepNodeIndex ; 8 ] > ,
943
- fingerprint : Fingerprint ,
911
+ #[ derive( Clone , Debug ) ]
912
+ pub ( super ) struct DepNodeData {
913
+ pub ( super ) node : DepNode ,
914
+ pub ( super ) edges : SmallVec < [ DepNodeIndex ; 8 ] > ,
915
+ pub ( super ) fingerprint : Fingerprint ,
944
916
}
945
917
946
918
pub ( super ) struct CurrentDepGraph {
947
- data : IndexVec < DepNodeIndex , DepNodeData > ,
919
+ nodes : usize ,
948
920
node_to_node_index : FxHashMap < DepNode , DepNodeIndex > ,
949
921
#[ allow( dead_code) ]
950
922
forbidden_edge : Option < EdgeFilter > ,
@@ -964,10 +936,13 @@ pub(super) struct CurrentDepGraph {
964
936
965
937
total_read_count : u64 ,
966
938
total_duplicate_read_count : u64 ,
939
+
940
+ /// Produces the serialized dep graph for the next session,
941
+ serializer : Serializer ,
967
942
}
968
943
969
944
impl CurrentDepGraph {
970
- fn new ( prev_graph_node_count : usize ) -> CurrentDepGraph {
945
+ fn new ( prev_graph_node_count : usize , file : File ) -> CurrentDepGraph {
971
946
use std:: time:: { SystemTime , UNIX_EPOCH } ;
972
947
973
948
let duration = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . unwrap ( ) ;
@@ -997,7 +972,7 @@ impl CurrentDepGraph {
997
972
let new_node_count_estimate = ( prev_graph_node_count * 102 ) / 100 + 200 ;
998
973
999
974
CurrentDepGraph {
1000
- data : IndexVec :: with_capacity ( new_node_count_estimate ) ,
975
+ nodes : 0 ,
1001
976
node_to_node_index : FxHashMap :: with_capacity_and_hasher (
1002
977
new_node_count_estimate,
1003
978
Default :: default ( ) ,
@@ -1006,6 +981,7 @@ impl CurrentDepGraph {
1006
981
forbidden_edge,
1007
982
total_read_count : 0 ,
1008
983
total_duplicate_read_count : 0 ,
984
+ serializer : Serializer :: new ( file) ,
1009
985
}
1010
986
}
1011
987
@@ -1058,13 +1034,14 @@ impl CurrentDepGraph {
1058
1034
edges : SmallVec < [ DepNodeIndex ; 8 ] > ,
1059
1035
fingerprint : Fingerprint
1060
1036
) -> ( DepNodeIndex , bool ) {
1061
- debug_assert_eq ! ( self . node_to_node_index. len( ) , self . data . len ( ) ) ;
1037
+ debug_assert_eq ! ( self . node_to_node_index. len( ) , self . nodes ) ;
1062
1038
1063
1039
match self . node_to_node_index . entry ( dep_node) {
1064
1040
Entry :: Occupied ( entry) => ( * entry. get ( ) , false ) ,
1065
1041
Entry :: Vacant ( entry) => {
1066
- let dep_node_index = DepNodeIndex :: new ( self . data . len ( ) ) ;
1067
- self . data . push ( DepNodeData {
1042
+ let dep_node_index = DepNodeIndex :: new ( self . nodes ) ;
1043
+ self . nodes += 1 ;
1044
+ self . serializer . serialize ( DepNodeData {
1068
1045
node : dep_node,
1069
1046
edges,
1070
1047
fingerprint
@@ -1088,7 +1065,7 @@ impl DepGraphData {
1088
1065
if task_deps. read_set . insert ( source) {
1089
1066
task_deps. reads . push ( source) ;
1090
1067
1091
- #[ cfg( debug_assertions) ]
1068
+ /* #[cfg(debug_assertions)]
1092
1069
{
1093
1070
if let Some(target) = task_deps.node {
1094
1071
let graph = self.current.lock();
@@ -1101,7 +1078,7 @@ impl DepGraphData {
1101
1078
}
1102
1079
}
1103
1080
}
1104
- }
1081
+ }*/
1105
1082
} else if cfg ! ( debug_assertions) {
1106
1083
self . current . lock ( ) . total_duplicate_read_count += 1 ;
1107
1084
}
@@ -1112,6 +1089,7 @@ impl DepGraphData {
1112
1089
1113
1090
pub struct TaskDeps {
1114
1091
#[ cfg( debug_assertions) ]
1092
+ #[ allow( dead_code) ]
1115
1093
node : Option < DepNode > ,
1116
1094
reads : SmallVec < [ DepNodeIndex ; 8 ] > ,
1117
1095
read_set : FxHashSet < DepNodeIndex > ,
0 commit comments