@@ -20,6 +20,32 @@ use super::safe::DepGraphSafe;
2020use super :: serialized:: { SerializedDepGraph , SerializedDepNodeIndex } ;
2121use super :: prev:: PreviousDepGraph ;
2222
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+
2349#[ derive( Clone ) ]
2450pub struct DepGraph {
2551 data : Option < Lrc < DepGraphData > > ,
@@ -30,7 +56,7 @@ newtype_index! {
3056}
3157
3258impl DepNodeIndex {
33- const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
59+ pub ( crate ) const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
3460}
3561
3662#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
@@ -94,17 +120,29 @@ impl DepGraph {
94120 prev_work_products : FxHashMap < WorkProductId , WorkProduct > ) -> DepGraph {
95121 let prev_graph_node_count = prev_graph. node_count ( ) ;
96122
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+
97144 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) ) ,
108146 }
109147 }
110148
@@ -135,18 +173,21 @@ impl DepGraph {
135173 DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
136174 }
137175
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+ } )
146181 }
147182
148183 pub fn with_ignore < OP , R > ( & self , op : OP ) -> R
149184 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
150191 {
151192 ty:: tls:: with_context ( |icx| {
152193 let icx = ty:: tls:: ImplicitCtxt {
@@ -394,6 +435,16 @@ impl DepGraph {
394435 hash_result)
395436 }
396437
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+
397448 #[ inline]
398449 pub fn read ( & self , v : DepNode ) {
399450 if let Some ( ref data) = self . data {
0 commit comments