@@ -10,7 +10,9 @@ use rustc::ty::steal::Steal;
10
10
use rustc:: ty:: { AllArenas , GlobalCtxt , ResolverOutputs } ;
11
11
use rustc:: util:: common:: ErrorReported ;
12
12
use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
13
+ use rustc_data_structures:: sync:: future:: Future ;
13
14
use rustc_data_structures:: sync:: { Lrc , Once , WorkerLocal } ;
15
+ use rustc_data_structures:: OnDrop ;
14
16
use rustc_hir:: def_id:: LOCAL_CRATE ;
15
17
use rustc_incremental:: DepGraphFuture ;
16
18
use rustc_lint:: LintStore ;
@@ -69,10 +71,12 @@ pub struct Queries<'tcx> {
69
71
all_arenas : AllArenas ,
70
72
arena : WorkerLocal < Arena < ' tcx > > ,
71
73
72
- dep_graph_future : Query < Option < DepGraphFuture > > ,
73
74
parse : Query < ast:: Crate > ,
74
75
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
+ ) > ,
76
80
expansion : Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > ,
77
81
dep_graph : Query < DepGraph > ,
78
82
lower_to_hir : Query < ( & ' tcx map:: Forest < ' tcx > , Steal < ResolverOutputs > ) > ,
@@ -88,7 +92,6 @@ impl<'tcx> Queries<'tcx> {
88
92
gcx : Once :: new ( ) ,
89
93
all_arenas : AllArenas :: new ( ) ,
90
94
arena : WorkerLocal :: new ( |_| Arena :: default ( ) ) ,
91
- dep_graph_future : Default :: default ( ) ,
92
95
parse : Default :: default ( ) ,
93
96
crate_name : Default :: default ( ) ,
94
97
register_plugins : Default :: default ( ) ,
@@ -108,16 +111,6 @@ impl<'tcx> Queries<'tcx> {
108
111
& self . compiler . codegen_backend ( )
109
112
}
110
113
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
-
121
114
pub fn parse ( & self ) -> Result < & Query < ast:: Crate > > {
122
115
self . parse . compute ( || {
123
116
passes:: parse ( self . session ( ) , & self . compiler . input ) . map_err ( |mut parse_error| {
@@ -127,28 +120,27 @@ impl<'tcx> Queries<'tcx> {
127
120
} )
128
121
}
129
122
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
+ > {
131
131
self . register_plugins . compute ( || {
132
132
let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
133
133
let krate = self . parse ( ) ?. take ( ) ;
134
134
135
135
let empty: & ( dyn Fn ( & Session , & mut LintStore ) + Sync + Send ) = & |_, _| { } ;
136
- let result = passes:: register_plugins (
136
+ let ( krate , lint_store , future ) = passes:: register_plugins (
137
137
self . session ( ) ,
138
138
& * self . codegen_backend ( ) . metadata_loader ( ) ,
139
139
self . compiler . register_lints . as_ref ( ) . map ( |p| & * * p) . unwrap_or_else ( || empty) ,
140
140
krate,
141
- & crate_name,
141
+ crate_name,
142
142
) ;
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) ) )
152
144
} )
153
145
}
154
146
@@ -174,7 +166,7 @@ impl<'tcx> Queries<'tcx> {
174
166
) -> Result < & Query < ( ast:: Crate , Steal < Rc < RefCell < BoxedResolver > > > , Lrc < LintStore > ) > > {
175
167
self . expansion . compute ( || {
176
168
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 ( ) ;
178
170
let _timer = self . session ( ) . timer ( "configure_and_expand" ) ;
179
171
passes:: configure_and_expand (
180
172
self . session ( ) . clone ( ) ,
@@ -191,7 +183,8 @@ impl<'tcx> Queries<'tcx> {
191
183
192
184
pub fn dep_graph ( & self ) -> Result < & Query < DepGraph > > {
193
185
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 {
195
188
None => DepGraph :: new_disabled ( ) ,
196
189
Some ( future) => {
197
190
let ( prev_graph, prev_work_products) =
@@ -336,6 +329,15 @@ impl Compiler {
336
329
{
337
330
let mut _timer = None ;
338
331
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
+
339
341
let ret = f ( & queries) ;
340
342
341
343
if self . session ( ) . opts . debugging_opts . query_stats {
0 commit comments