@@ -2,17 +2,17 @@ use crate::interface::{Compiler, Result};
22use crate :: passes:: { self , BoxedResolver , ExpansionResult , BoxedGlobalCtxt , PluginInfo } ;
33
44use rustc_incremental:: DepGraphFuture ;
5- use rustc:: session:: config:: { OutputFilenames , OutputType } ;
5+ use rustc:: session:: config:: OutputFilenames ;
66use rustc:: util:: common:: { time, ErrorReported } ;
77use rustc:: hir;
88use rustc:: hir:: def_id:: LOCAL_CRATE ;
99use rustc:: ty:: steal:: Steal ;
1010use rustc:: dep_graph:: DepGraph ;
11+ use std:: any:: Any ;
1112use std:: cell:: { Ref , RefMut , RefCell } ;
13+ use std:: mem;
1214use std:: rc:: Rc ;
1315use std:: sync:: mpsc;
14- use std:: any:: Any ;
15- use std:: mem;
1616use syntax:: { self , ast} ;
1717
1818/// Represent the result of a query.
@@ -83,8 +83,7 @@ pub(crate) struct Queries {
8383 codegen_channel : Query < ( Steal < mpsc:: Sender < Box < dyn Any + Send > > > ,
8484 Steal < mpsc:: Receiver < Box < dyn Any + Send > > > ) > ,
8585 global_ctxt : Query < BoxedGlobalCtxt > ,
86- ongoing_codegen : Query < Box < dyn Any > > ,
87- link : Query < ( ) > ,
86+ codegen_and_link : Query < ( ) > ,
8887}
8988
9089impl Compiler {
@@ -114,29 +113,38 @@ impl Compiler {
114113 let crate_name = self . crate_name ( ) ?. peek ( ) . clone ( ) ;
115114 let krate = self . parse ( ) ?. take ( ) ;
116115
117- passes:: register_plugins (
118- self ,
116+ let result = passes:: register_plugins (
119117 self . session ( ) ,
120118 self . cstore ( ) ,
121119 krate,
122120 & 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
124131 } )
125132 }
126133
127134 pub fn crate_name ( & self ) -> Result < & Query < String > > {
128135 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 {
132137 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+ } )
140148 } )
141149 }
142150
@@ -194,7 +202,6 @@ impl Compiler {
194202
195203 pub fn prepare_outputs ( & self ) -> Result < & Query < OutputFilenames > > {
196204 self . queries . prepare_outputs . compute ( || {
197- self . lower_to_hir ( ) ?;
198205 let krate = self . expansion ( ) ?;
199206 let krate = krate. peek ( ) ;
200207 let crate_name = self . crate_name ( ) ?;
@@ -230,14 +237,14 @@ impl Compiler {
230237 } )
231238 }
232239
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 ( || {
235242 let rx = self . codegen_channel ( ) ?. peek ( ) . 1 . steal ( ) ;
236243 let outputs = self . prepare_outputs ( ) ?;
237- self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
244+ let ongoing_codegen = self . global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
238245 tcx. analysis ( LOCAL_CRATE ) . ok ( ) ;
239246
240- // Don't do code generation if there were any errors
247+ // Don't do code generation if there were any errors.
241248 self . session ( ) . compile_status ( ) ?;
242249
243250 Ok ( passes:: start_codegen (
@@ -246,46 +253,19 @@ impl Compiler {
246253 rx,
247254 & * outputs. peek ( )
248255 ) )
249- } )
250- } )
251- }
252-
253- pub fn link ( & self ) -> Result < & Query < ( ) > > {
254- self . queries . link . compute ( || {
255- let sess = self . session ( ) ;
256+ } ) ?;
256257
257- let ongoing_codegen = self . ongoing_codegen ( ) ?. take ( ) ;
258+ // Drop GlobalCtxt after starting codegen to free memory.
259+ mem:: drop ( self . global_ctxt ( ) ?. take ( ) ) ;
258260
259261 self . codegen_backend ( ) . join_codegen_and_link (
260262 ongoing_codegen,
261- sess ,
263+ self . session ( ) ,
262264 & * self . dep_graph ( ) ?. peek ( ) ,
263- & * self . prepare_outputs ( ) ? . peek ( ) ,
265+ & * outputs . peek ( ) ,
264266 ) . map_err ( |_| ErrorReported ) ?;
265267
266268 Ok ( ( ) )
267269 } )
268270 }
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- }
291271}
0 commit comments