@@ -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 ) ]
@@ -95,17 +121,29 @@ impl DepGraph {
95
121
prev_work_products : FxHashMap < WorkProductId , WorkProduct > ) -> DepGraph {
96
122
let prev_graph_node_count = prev_graph. node_count ( ) ;
97
123
124
+ let mut data = DepGraphData {
125
+ previous_work_products : prev_work_products,
126
+ dep_node_debug : Default :: default ( ) ,
127
+ current : Lock :: new ( CurrentDepGraph :: new ( prev_graph_node_count) ) ,
128
+ emitted_diagnostics : Default :: default ( ) ,
129
+ emitted_diagnostics_cond_var : Condvar :: new ( ) ,
130
+ previous : prev_graph,
131
+ colors : DepNodeColorMap :: new ( prev_graph_node_count) ,
132
+ loaded_from_cache : Default :: default ( ) ,
133
+ } ;
134
+
135
+ let non_incr_dep_node = DepNode :: new_no_params ( DepKind :: NonIncremental ) ;
136
+
137
+ // Allocate the NonIncremental node
138
+ data. current . get_mut ( ) . alloc_node ( non_incr_dep_node, smallvec ! [ ] , Fingerprint :: ZERO ) ;
139
+
140
+ data. previous . node_to_index_opt ( & non_incr_dep_node) . map ( |prev_index| {
141
+ // Color previous NonIncremental node as red
142
+ data. colors . insert ( prev_index, DepNodeColor :: Red ) ;
143
+ } ) ;
144
+
98
145
DepGraph {
99
- data : Some ( Lrc :: new ( DepGraphData {
100
- previous_work_products : prev_work_products,
101
- dep_node_debug : Default :: default ( ) ,
102
- current : Lock :: new ( CurrentDepGraph :: new ( prev_graph_node_count) ) ,
103
- emitted_diagnostics : Default :: default ( ) ,
104
- emitted_diagnostics_cond_var : Condvar :: new ( ) ,
105
- previous : prev_graph,
106
- colors : DepNodeColorMap :: new ( prev_graph_node_count) ,
107
- loaded_from_cache : Default :: default ( ) ,
108
- } ) ) ,
146
+ data : Some ( Lrc :: new ( data) ) ,
109
147
}
110
148
}
111
149
@@ -136,18 +174,21 @@ impl DepGraph {
136
174
DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
137
175
}
138
176
139
- pub fn assert_ignored ( & self )
140
- {
141
- if let Some ( ..) = self . data {
142
- ty:: tls:: with_context_opt ( |icx| {
143
- let icx = if let Some ( icx) = icx { icx } else { return } ;
144
- assert ! ( icx. task_deps. is_none( ) , "expected no task dependency tracking" ) ;
145
- } )
146
- }
177
+ pub fn assert_ignored ( ) {
178
+ ty:: tls:: with_context_opt ( |icx| {
179
+ let icx = if let Some ( icx) = icx { icx } else { return } ;
180
+ assert ! ( icx. task_deps. is_none( ) , "expected no task dependency tracking" ) ;
181
+ } )
147
182
}
148
183
149
184
pub fn with_ignore < OP , R > ( & self , op : OP ) -> R
150
185
where OP : FnOnce ( ) -> R
186
+ {
187
+ Self :: ignore_deps ( op)
188
+ }
189
+
190
+ pub fn ignore_deps < OP , R > ( op : OP ) -> R
191
+ where OP : FnOnce ( ) -> R
151
192
{
152
193
ty:: tls:: with_context ( |icx| {
153
194
let icx = ty:: tls:: ImplicitCtxt {
@@ -395,6 +436,16 @@ impl DepGraph {
395
436
hash_result)
396
437
}
397
438
439
+ #[ inline]
440
+ pub fn read_non_incr ( tcx : TyCtxt < ' _ , ' _ , ' _ > ) {
441
+ // Avoid loading the `dep_graph` here if we don't need to track dependencies.
442
+ // We want to load the `dep_graph` in the background.
443
+ if ty:: tls:: with_context ( |icx| icx. task_deps . is_none ( ) ) {
444
+ return ;
445
+ }
446
+ tcx. dep_graph ( ) . read ( DepNode :: new_no_params ( DepKind :: NonIncremental ) ) ;
447
+ }
448
+
398
449
#[ inline]
399
450
pub fn read ( & self , v : DepNode ) {
400
451
if let Some ( ref data) = self . data {
0 commit comments