@@ -10,7 +10,9 @@ use rustc::ty::steal::Steal;
1010use rustc:: ty:: { AllArenas , GlobalCtxt , ResolverOutputs } ;
1111use rustc:: util:: common:: ErrorReported ;
1212use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
13+ use rustc_data_structures:: sync:: future:: Future ;
1314use rustc_data_structures:: sync:: { Lrc , Once , WorkerLocal } ;
15+ use rustc_data_structures:: OnDrop ;
1416use rustc_hir:: def_id:: LOCAL_CRATE ;
1517use rustc_incremental:: DepGraphFuture ;
1618use rustc_lint:: LintStore ;
@@ -69,10 +71,12 @@ pub struct Queries<'tcx> {
6971 all_arenas : AllArenas ,
7072 arena : WorkerLocal < Arena < ' tcx > > ,
7173
72- dep_graph_future : Query < Option < DepGraphFuture > > ,
7374 parse : Query < ast:: Crate > ,
7475 crate_name : Query < String > ,
75- register_plugins : Query < ( ast:: Crate , Lrc < LintStore > ) > ,
76+ register_plugins : Query < (
77+ Steal < ( ast:: Crate , Lrc < LintStore > ) > ,
78+ Steal < Future < ' static , Option < DepGraphFuture > > > ,
79+ ) > ,
7680 expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
7781 dep_graph : Query < DepGraph > ,
7882 lower_to_hir : Query < ( & ' tcx map:: Forest < ' tcx > , Steal < ResolverOutputs > ) > ,
@@ -88,7 +92,6 @@ impl<'tcx> Queries<'tcx> {
8892 gcx : Once :: new ( ) ,
8993 all_arenas : AllArenas :: new ( ) ,
9094 arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
91- dep_graph_future : Default :: default ( ) ,
9295 parse : Default :: default ( ) ,
9396 crate_name : Default :: default ( ) ,
9497 register_plugins : Default :: default ( ) ,
@@ -108,16 +111,6 @@ impl<'tcx> Queries<'tcx> {
108111 & self . compiler . codegen_backend ( )
109112 }
110113
111- pub fn dep_graph_future ( & self ) -> Result < & Query < Option < DepGraphFuture > > > {
112- self . dep_graph_future . compute ( || {
113- Ok ( self
114- . session ( )
115- . opts
116- . build_dep_graph ( )
117- . then ( || rustc_incremental:: load_dep_graph ( self . session ( ) ) ) )
118- } )
119- }
120-
121114 pub fn parse ( & self ) -> Result < & Query < ast:: Crate > > {
122115 self . parse . compute ( || {
123116 passes:: parse ( self . session ( ) , & self . compiler . input ) . map_err ( |mut parse_error| {
@@ -127,28 +120,27 @@ impl<'tcx> Queries<'tcx> {
127120 } )
128121 }
129122
130- pub fn register_plugins ( & self ) -> Result < & Query < ( ast:: Crate , Lrc < LintStore > ) > > {
123+ pub fn register_plugins (
124+ & self ,
125+ ) -> Result <
126+ & Query < (
127+ Steal < ( ast:: Crate , Lrc < LintStore > ) > ,
128+ Steal < Future < ' static , Option < DepGraphFuture > > > ,
129+ ) > ,
130+ > {
131131 self . register_plugins . compute ( || {
132132 let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
133133 let krate = self . parse ( ) ?. take ( ) ;
134134
135135 let empty: & ( dyn Fn ( & Session , & mut LintStore ) + Sync + Send ) = & |_, _| { } ;
136- let result = passes:: register_plugins (
136+ let ( krate , lint_store , future ) = passes:: register_plugins (
137137 self . session ( ) ,
138138 & * self . codegen_backend ( ) . metadata_loader ( ) ,
139139 self . compiler . register_lints . as_ref ( ) . map ( |p| & * * p) . unwrap_or_else ( || empty) ,
140140 krate,
141- & crate_name,
141+ crate_name,
142142 ) ;
143-
144- // Compute the dependency graph (in the background). We want to do
145- // this as early as possible, to give the DepGraph maximum time to
146- // load before dep_graph() is called, but it also can't happen
147- // until after rustc_incremental::prepare_session_directory() is
148- // called, which happens within passes::register_plugins().
149- self . dep_graph_future ( ) . ok ( ) ;
150-
151- result
143+ Ok ( ( Steal :: new ( ( krate, lint_store) ) , Steal :: new ( future) ) )
152144 } )
153145 }
154146
@@ -174,7 +166,7 @@ impl<'tcx> Queries<'tcx> {
174166 ) -> Result < & Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > > {
175167 self . expansion . compute ( || {
176168 let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
177- let ( krate, lint_store) = self . register_plugins ( ) ?. take ( ) ;
169+ let ( krate, lint_store) = self . register_plugins ( ) ?. peek ( ) . 0 . steal ( ) ;
178170 let _timer = self . session ( ) . timer ( "configure_and_expand" ) ;
179171 passes:: configure_and_expand (
180172 self . session ( ) . clone ( ) ,
@@ -191,7 +183,8 @@ impl<'tcx> Queries<'tcx> {
191183
192184 pub fn dep_graph ( & self ) -> Result < & Query < DepGraph > > {
193185 self . dep_graph . compute ( || {
194- Ok ( match self . dep_graph_future ( ) ?. take ( ) {
186+ let future = self . register_plugins ( ) ?. peek ( ) . 1 . steal ( ) . join ( ) ;
187+ Ok ( match future {
195188 None => DepGraph :: new_disabled ( ) ,
196189 Some ( future) => {
197190 let ( prev_graph, prev_work_products) =
@@ -336,6 +329,15 @@ impl Compiler {
336329 {
337330 let mut _timer = None ;
338331 let queries = Queries :: new ( & self ) ;
332+
333+ // Join the dep graph future if has started, but haven't been stolen yet.
334+ let _join_dep_graph_future = OnDrop ( || {
335+ let result = queries. register_plugins . result . borrow_mut ( ) . take ( ) ;
336+ result. map ( |result| {
337+ result. map ( |result| result. 1 . into_inner ( ) . map ( |future| future. join ( ) ) )
338+ } ) ;
339+ } ) ;
340+
339341 let ret = f ( & queries) ;
340342
341343 if self . session ( ) . opts . debugging_opts . query_stats {
0 commit comments