@@ -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 ) ]
@@ -95,17 +121,29 @@ impl DepGraph {
95121 prev_work_products : FxHashMap < WorkProductId , WorkProduct > ) -> DepGraph {
96122 let prev_graph_node_count = prev_graph. node_count ( ) ;
97123
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+
98145 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) ) ,
109147 }
110148 }
111149
@@ -136,18 +174,21 @@ impl DepGraph {
136174 DepGraphQuery :: new ( & nodes[ ..] , & edges[ ..] )
137175 }
138176
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+ } )
147182 }
148183
149184 pub fn with_ignore < OP , R > ( & self , op : OP ) -> R
150185 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
151192 {
152193 ty:: tls:: with_context ( |icx| {
153194 let icx = ty:: tls:: ImplicitCtxt {
@@ -395,6 +436,16 @@ impl DepGraph {
395436 hash_result)
396437 }
397438
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+
398449 #[ inline]
399450 pub fn read ( & self , v : DepNode ) {
400451 if let Some ( ref data) = self . data {
0 commit comments