@@ -2,17 +2,17 @@ use crate::interface::{Compiler, Result};
2
2
use crate :: passes:: { self , BoxedResolver , ExpansionResult , BoxedGlobalCtxt , PluginInfo } ;
3
3
4
4
use rustc_incremental:: DepGraphFuture ;
5
- use rustc:: session:: config:: { OutputFilenames , OutputType } ;
5
+ use rustc:: session:: config:: OutputFilenames ;
6
6
use rustc:: util:: common:: { time, ErrorReported } ;
7
7
use rustc:: hir;
8
8
use rustc:: hir:: def_id:: LOCAL_CRATE ;
9
9
use rustc:: ty:: steal:: Steal ;
10
10
use rustc:: dep_graph:: DepGraph ;
11
+ use std:: any:: Any ;
11
12
use std:: cell:: { Ref , RefMut , RefCell } ;
13
+ use std:: mem;
12
14
use std:: rc:: Rc ;
13
15
use std:: sync:: mpsc;
14
- use std:: any:: Any ;
15
- use std:: mem;
16
16
use syntax:: { self , ast} ;
17
17
18
18
/// Represent the result of a query.
@@ -83,8 +83,7 @@ pub(crate) struct Queries {
83
83
codegen_channel : Query < ( Steal < mpsc:: Sender < Box < dyn Any + Send > > > ,
84
84
Steal < mpsc:: Receiver < Box < dyn Any + Send > > > ) > ,
85
85
global_ctxt : Query < BoxedGlobalCtxt > ,
86
- ongoing_codegen : Query < Box < dyn Any > > ,
87
- link : Query < ( ) > ,
86
+ codegen_and_link : Query < ( ) > ,
88
87
}
89
88
90
89
impl Compiler {
@@ -114,29 +113,38 @@ impl Compiler {
114
113
let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
115
114
let krate = self . parse ( ) ?. take ( ) ;
116
115
117
- passes:: register_plugins (
118
- self ,
116
+ let result = passes:: register_plugins (
119
117
self . session ( ) ,
120
118
self . cstore ( ) ,
121
119
krate,
122
120
& crate_name,
123
- )
121
+ ) ;
122
+
123
+ // Compute the dependency graph (in the background). We want to do
124
+ // this as early as possible, to give the DepGraph maximum time to
125
+ // load before dep_graph() is called, but it also can't happen
126
+ // until after rustc_incremental::prepare_session_directory() is
127
+ // called, which happens within passes::register_plugins().
128
+ self . dep_graph_future ( ) . ok ( ) ;
129
+
130
+ result
124
131
} )
125
132
}
126
133
127
134
pub fn crate_name ( & self ) -> Result < & Query < String > > {
128
135
self . queries . crate_name . compute ( || {
129
- let parse_result = self . parse ( ) ?;
130
- let krate = parse_result. peek ( ) ;
131
- let result = match self . crate_name {
136
+ Ok ( match self . crate_name {
132
137
Some ( ref crate_name) => crate_name. clone ( ) ,
133
- None => rustc_codegen_utils:: link:: find_crate_name (
134
- Some ( self . session ( ) ) ,
135
- & krate. attrs ,
136
- & self . input
137
- ) ,
138
- } ;
139
- Ok ( result)
138
+ None => {
139
+ let parse_result = self . parse ( ) ?;
140
+ let krate = parse_result. peek ( ) ;
141
+ rustc_codegen_utils:: link:: find_crate_name (
142
+ Some ( self . session ( ) ) ,
143
+ & krate. attrs ,
144
+ & self . input
145
+ )
146
+ }
147
+ } )
140
148
} )
141
149
}
142
150
@@ -194,7 +202,6 @@ impl Compiler {
194
202
195
203
pub fn prepare_outputs ( & self ) -> Result < & Query < OutputFilenames > > {
196
204
self . queries . prepare_outputs . compute ( || {
197
- self . lower_to_hir ( ) ?;
198
205
let krate = self . expansion ( ) ?;
199
206
let krate = krate. peek ( ) ;
200
207
let crate_name = self . crate_name ( ) ?;
@@ -230,14 +237,14 @@ impl Compiler {
230
237
} )
231
238
}
232
239
233
- pub fn ongoing_codegen ( & self ) -> Result < & Query < Box < dyn Any > > > {
234
- self . queries . ongoing_codegen . compute ( || {
240
+ pub fn codegen_and_link ( & self ) -> Result < & Query < ( ) > > {
241
+ self . queries . codegen_and_link . compute ( || {
235
242
let rx = self . codegen_channel ( ) ?. peek ( ) . 1 . steal ( ) ;
236
243
let outputs = self . prepare_outputs ( ) ?;
237
- self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
244
+ let ongoing_codegen = self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
238
245
tcx. analysis ( LOCAL_CRATE ) . ok ( ) ;
239
246
240
- // Don't do code generation if there were any errors
247
+ // Don't do code generation if there were any errors.
241
248
self . session ( ) . compile_status ( ) ?;
242
249
243
250
Ok ( passes:: start_codegen (
@@ -246,46 +253,19 @@ impl Compiler {
246
253
rx,
247
254
& * outputs. peek ( )
248
255
) )
249
- } )
250
- } )
251
- }
252
-
253
- pub fn link ( & self ) -> Result < & Query < ( ) > > {
254
- self . queries . link . compute ( || {
255
- let sess = self . session ( ) ;
256
+ } ) ?;
256
257
257
- let ongoing_codegen = self . ongoing_codegen ( ) ?. take ( ) ;
258
+ // Drop GlobalCtxt after starting codegen to free memory.
259
+ mem:: drop ( self . global_ctxt ( ) ?. take ( ) ) ;
258
260
259
261
self . codegen_backend ( ) . join_codegen_and_link (
260
262
ongoing_codegen,
261
- sess ,
263
+ self . session ( ) ,
262
264
& * self . dep_graph ( ) ?. peek ( ) ,
263
- & * self . prepare_outputs ( ) ? . peek ( ) ,
265
+ & * outputs . peek ( ) ,
264
266
) . map_err ( |_| ErrorReported ) ?;
265
267
266
268
Ok ( ( ) )
267
269
} )
268
270
}
269
-
270
- pub fn compile ( & self ) -> Result < ( ) > {
271
- self . prepare_outputs ( ) ?;
272
-
273
- if self . session ( ) . opts . output_types . contains_key ( & OutputType :: DepInfo )
274
- && self . session ( ) . opts . output_types . len ( ) == 1
275
- {
276
- return Ok ( ( ) )
277
- }
278
-
279
- self . global_ctxt ( ) ?;
280
-
281
- // Drop AST after creating GlobalCtxt to free memory
282
- mem:: drop ( self . expansion ( ) ?. take ( ) ) ;
283
-
284
- self . ongoing_codegen ( ) ?;
285
-
286
- // Drop GlobalCtxt after starting codegen to free memory
287
- mem:: drop ( self . global_ctxt ( ) ?. take ( ) ) ;
288
-
289
- self . link ( ) . map ( |_| ( ) )
290
- }
291
271
}
0 commit comments