@@ -20,6 +20,32 @@ use super::safe::DepGraphSafe;
20
20
use super :: serialized:: { SerializedDepGraph , SerializedDepNodeIndex } ;
21
21
use super :: prev:: PreviousDepGraph ;
22
22
23
+ pub type WorkProductMap = FxHashMap < WorkProductId , WorkProduct > ;
24
+
25
+ pub enum LoadResult < T > {
26
+ Ok { data : T } ,
27
+ DataOutOfDate ,
28
+ Error { message : String } ,
29
+ }
30
+
31
+ /// Either a result that has already be computed or a
32
+ /// handle that will let us wait until it is computed
33
+ /// by a background thread.
34
+ pub enum MaybeAsync < T > {
35
+ Sync ( T ) ,
36
+ Async ( std:: thread:: JoinHandle < T > )
37
+ }
38
+ impl < T > MaybeAsync < T > {
39
+ pub fn open ( self ) -> std:: thread:: Result < T > {
40
+ match self {
41
+ MaybeAsync :: Sync ( result) => Ok ( result) ,
42
+ MaybeAsync :: Async ( handle) => handle. join ( )
43
+ }
44
+ }
45
+ }
46
+
47
+ pub type DepGraphFuture = MaybeAsync < LoadResult < ( PreviousDepGraph , WorkProductMap ) > > ;
48
+
23
49
#[ derive( Clone ) ]
24
50
pub struct DepGraph {
25
51
data : Option < Lrc < DepGraphData > > ,
@@ -30,7 +56,7 @@ newtype_index! {
30
56
}
31
57
32
58
impl DepNodeIndex {
33
- const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
59
+ pub ( crate ) const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
34
60
}
35
61
36
62
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
@@ -94,17 +120,29 @@ impl DepGraph {
94
120
prev_work_products : FxHashMap < WorkProductId , WorkProduct > ) -> DepGraph {
95
121
let prev_graph_node_count = prev_graph. node_count ( ) ;
96
122
123
+ let mut data = DepGraphData {
124
+ previous_work_products : prev_work_products,
125
+ dep_node_debug : Default :: default ( ) ,
126
+ current : Lock :: new ( CurrentDepGraph :: new ( prev_graph_node_count) ) ,
127
+ emitted_diagnostics : Default :: default ( ) ,
128
+ emitted_diagnostics_cond_var : Condvar :: new ( ) ,
129
+ previous : prev_graph,
130
+ colors : DepNodeColorMap :: new ( prev_graph_node_count) ,
131
+ loaded_from_cache : Default :: default ( ) ,
132
+ } ;
133
+
134
+ let non_incr_dep_node = DepNode :: new_no_params ( DepKind :: NonIncremental ) ;
135
+
136
+ // Allocate the NonIncremental node
137
+ data. current . get_mut ( ) . alloc_node ( non_incr_dep_node, smallvec ! [ ] , Fingerprint :: ZERO ) ;
138
+
139
+ data. previous . node_to_index_opt ( & non_incr_dep_node) . map ( |prev_index| {
140
+ // Color previous NonIncremental node as red
141
+ data. colors . insert ( prev_index, DepNodeColor :: Red ) ;
142
+ } ) ;
143
+
97
144
DepGraph {
98
- data : Some ( Lrc :: new ( DepGraphData {
99
- previous_work_products : prev_work_products,
100
- dep_node_debug : Default :: default ( ) ,
101
- current : Lock :: new ( CurrentDepGraph :: new ( prev_graph_node_count) ) ,
102
- emitted_diagnostics : Default :: default ( ) ,
103
- emitted_diagnostics_cond_var : Condvar :: new ( ) ,
104
- previous : prev_graph,
105
- colors : DepNodeColorMap :: new ( prev_graph_node_count) ,
106
- loaded_from_cache : Default :: default ( ) ,
107
- } ) ) ,
145
+ data : Some ( Lrc :: new ( data) ) ,
108
146
}
109
147
}
110
148
@@ -135,18 +173,21 @@ impl DepGraph {
135
173
DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
136
174
}
137
175
138
- pub fn assert_ignored ( & self )
139
- {
140
- if let Some ( ..) = self . data {
141
- ty:: tls:: with_context_opt ( |icx| {
142
- let icx = if let Some ( icx) = icx { icx } else { return } ;
143
- assert ! ( icx. task_deps. is_none( ) , "expected no task dependency tracking" ) ;
144
- } )
145
- }
176
+ pub fn assert_ignored ( ) {
177
+ ty:: tls:: with_context_opt ( |icx| {
178
+ let icx = if let Some ( icx) = icx { icx } else { return } ;
179
+ assert ! ( icx. task_deps. is_none( ) , "expected no task dependency tracking" ) ;
180
+ } )
146
181
}
147
182
148
183
pub fn with_ignore < OP , R > ( & self , op : OP ) -> R
149
184
where OP : FnOnce ( ) -> R
185
+ {
186
+ Self :: ignore_deps ( op)
187
+ }
188
+
189
+ pub fn ignore_deps < OP , R > ( op : OP ) -> R
190
+ where OP : FnOnce ( ) -> R
150
191
{
151
192
ty:: tls:: with_context ( |icx| {
152
193
let icx = ty:: tls:: ImplicitCtxt {
@@ -394,6 +435,16 @@ impl DepGraph {
394
435
hash_result)
395
436
}
396
437
438
+ #[ inline]
439
+ pub fn read_non_incr ( tcx : TyCtxt < ' _ > ) {
440
+ // Avoid loading the `dep_graph` here if we don't need to track dependencies.
441
+ // We want to load the `dep_graph` in the background.
442
+ if ty:: tls:: with_context ( |icx| icx. task_deps . is_none ( ) ) {
443
+ return ;
444
+ }
445
+ tcx. dep_graph ( ) . read ( DepNode :: new_no_params ( DepKind :: NonIncremental ) ) ;
446
+ }
447
+
397
448
#[ inline]
398
449
pub fn read ( & self , v : DepNode ) {
399
450
if let Some ( ref data) = self . data {
0 commit comments