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