@@ -31,7 +31,6 @@ use rustc_incremental;
3131use rustc_resolve:: { MakeGlobMap , Resolver } ;
3232use rustc_metadata:: creader:: CrateLoader ;
3333use rustc_metadata:: cstore:: { self , CStore } ;
34- use rustc_trans as trans;
3534use rustc_trans_utils:: trans_crate:: TransCrate ;
3635use rustc_typeck as typeck;
3736use rustc_privacy;
@@ -40,7 +39,6 @@ use rustc_plugin as plugin;
4039use rustc_passes:: { self , ast_validation, loops, consts, static_recursion, hir_stats} ;
4140use rustc_const_eval:: { self , check_match} ;
4241use super :: Compilation ;
43- use :: DefaultTransCrate ;
4442
4543use serialize:: json;
4644
@@ -68,16 +66,15 @@ use pretty::ReplaceBodyWithLoop;
6866
6967use profile;
7068
71- pub fn compile_input ( sess : & Session ,
69+ pub fn compile_input ( trans : Box < TransCrate > ,
70+ sess : & Session ,
7271 cstore : & CStore ,
7372 input_path : & Option < PathBuf > ,
7473 input : & Input ,
7574 outdir : & Option < PathBuf > ,
7675 output : & Option < PathBuf > ,
7776 addl_plugins : Option < Vec < String > > ,
7877 control : & CompileController ) -> CompileResult {
79- use rustc:: session:: config:: CrateType ;
80-
8178 macro_rules! controller_entry_point {
8279 ( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
8380 let state = & mut $make_state;
@@ -94,30 +91,14 @@ pub fn compile_input(sess: &Session,
9491 } }
9592 }
9693
97- if cfg ! ( not( feature="llvm" ) ) {
98- for cty in sess. opts . crate_types . iter ( ) {
99- match * cty {
100- CrateType :: CrateTypeRlib | CrateType :: CrateTypeDylib |
101- CrateType :: CrateTypeExecutable => { } ,
102- _ => {
103- sess. parse_sess . span_diagnostic . warn (
104- & format ! ( "LLVM unsupported, so output type {} is not supported" , cty)
105- ) ;
106- } ,
107- }
108- }
109-
110- sess. abort_if_errors ( ) ;
111- }
112-
11394 if sess. profile_queries ( ) {
11495 profile:: begin ( ) ;
11596 }
11697
11798 // We need nested scopes here, because the intermediate results can keep
11899 // large chunks of memory alive and we want to free them as soon as
119100 // possible to keep the peak memory usage low
120- let ( outputs, trans , dep_graph) = {
101+ let ( outputs, ongoing_trans , dep_graph) = {
121102 let krate = match phase_1_parse_input ( control, sess, input) {
122103 Ok ( krate) => krate,
123104 Err ( mut parse_error) => {
@@ -217,7 +198,8 @@ pub fn compile_input(sess: &Session,
217198 None
218199 } ;
219200
220- phase_3_run_analysis_passes ( control,
201+ phase_3_run_analysis_passes ( & * trans,
202+ control,
221203 sess,
222204 cstore,
223205 hir_map,
@@ -254,7 +236,7 @@ pub fn compile_input(sess: &Session,
254236 tcx. print_debug_stats ( ) ;
255237 }
256238
257- let trans = phase_4_translate_to_llvm :: < DefaultTransCrate > ( tcx, rx) ;
239+ let ongoing_trans = phase_4_translate_to_llvm ( & * trans , tcx, rx) ;
258240
259241 if log_enabled ! ( :: log:: Level :: Info ) {
260242 println ! ( "Post-trans" ) ;
@@ -268,33 +250,15 @@ pub fn compile_input(sess: &Session,
268250 }
269251 }
270252
271- Ok ( ( outputs. clone ( ) , trans , tcx. dep_graph . clone ( ) ) )
253+ Ok ( ( outputs. clone ( ) , ongoing_trans , tcx. dep_graph . clone ( ) ) )
272254 } ) ??
273255 } ;
274256
275257 if sess. opts . debugging_opts . print_type_sizes {
276258 sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
277259 }
278260
279- let ( phase5_result, trans) =
280- phase_5_run_llvm_passes :: < DefaultTransCrate > ( sess, & dep_graph, trans) ;
281-
282- controller_entry_point ! ( after_llvm,
283- sess,
284- CompileState :: state_after_llvm( input, sess, outdir, output, & trans) ,
285- phase5_result) ;
286- phase5_result?;
287-
288- // Run the linker on any artifacts that resulted from the LLVM run.
289- // This should produce either a finished executable or library.
290- time ( sess. time_passes ( ) , "linking" , || {
291- DefaultTransCrate :: link_binary ( sess, & trans, & outputs)
292- } ) ;
293-
294- // Now that we won't touch anything in the incremental compilation directory
295- // any more, we can finalize it (which involves renaming it)
296- #[ cfg( feature="llvm" ) ]
297- rustc_incremental:: finalize_session_directory ( sess, trans. link . crate_hash ) ;
261+ trans. join_trans_and_link ( ongoing_trans, sess, & dep_graph, & outputs) ?;
298262
299263 if sess. opts . debugging_opts . perf_stats {
300264 sess. print_perf_stats ( ) ;
@@ -340,7 +304,6 @@ pub struct CompileController<'a> {
340304 pub after_expand : PhaseController < ' a > ,
341305 pub after_hir_lowering : PhaseController < ' a > ,
342306 pub after_analysis : PhaseController < ' a > ,
343- pub after_llvm : PhaseController < ' a > ,
344307 pub compilation_done : PhaseController < ' a > ,
345308
346309 // FIXME we probably want to group the below options together and offer a
@@ -366,7 +329,6 @@ impl<'a> CompileController<'a> {
366329 after_expand : PhaseController :: basic ( ) ,
367330 after_hir_lowering : PhaseController :: basic ( ) ,
368331 after_analysis : PhaseController :: basic ( ) ,
369- after_llvm : PhaseController :: basic ( ) ,
370332 compilation_done : PhaseController :: basic ( ) ,
371333 make_glob_map : MakeGlobMap :: No ,
372334 keep_ast : false ,
@@ -415,7 +377,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
415377 pub resolutions : Option < & ' a Resolutions > ,
416378 pub analysis : Option < & ' a ty:: CrateAnalysis > ,
417379 pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
418- pub trans : Option < & ' a trans:: CrateTranslation > ,
419380}
420381
421382impl < ' a , ' tcx > CompileState < ' a , ' tcx > {
@@ -440,7 +401,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
440401 resolutions : None ,
441402 analysis : None ,
442403 tcx : None ,
443- trans : None ,
444404 }
445405 }
446406
@@ -528,19 +488,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
528488 }
529489 }
530490
531- fn state_after_llvm ( input : & ' a Input ,
532- session : & ' tcx Session ,
533- out_dir : & ' a Option < PathBuf > ,
534- out_file : & ' a Option < PathBuf > ,
535- trans : & ' a trans:: CrateTranslation )
536- -> Self {
537- CompileState {
538- trans : Some ( trans) ,
539- out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
540- ..CompileState :: empty ( input, session, out_dir)
541- }
542- }
543-
544491 fn state_when_compilation_done ( input : & ' a Input ,
545492 session : & ' tcx Session ,
546493 out_dir : & ' a Option < PathBuf > ,
@@ -933,7 +880,6 @@ pub fn default_provide(providers: &mut ty::maps::Providers) {
933880 reachable:: provide ( providers) ;
934881 resolve_lifetime:: provide ( providers) ;
935882 rustc_privacy:: provide ( providers) ;
936- DefaultTransCrate :: provide ( providers) ;
937883 typeck:: provide ( providers) ;
938884 ty:: provide ( providers) ;
939885 traits:: provide ( providers) ;
@@ -947,13 +893,13 @@ pub fn default_provide(providers: &mut ty::maps::Providers) {
947893
948894pub fn default_provide_extern ( providers : & mut ty:: maps:: Providers ) {
949895 cstore:: provide_extern ( providers) ;
950- DefaultTransCrate :: provide_extern ( providers) ;
951896}
952897
953898/// Run the resolution, typechecking, region checking and other
954899/// miscellaneous analysis passes on the crate. Return various
955900/// structures carrying the results of the analysis.
956- pub fn phase_3_run_analysis_passes < ' tcx , F , R > ( control : & CompileController ,
901+ pub fn phase_3_run_analysis_passes < ' tcx , F , R > ( trans : & TransCrate ,
902+ control : & CompileController ,
957903 sess : & ' tcx Session ,
958904 cstore : & ' tcx CrateStore ,
959905 hir_map : hir_map:: Map < ' tcx > ,
@@ -1006,10 +952,12 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
1006952
1007953 let mut local_providers = ty:: maps:: Providers :: default ( ) ;
1008954 default_provide ( & mut local_providers) ;
955+ trans. provide ( & mut local_providers) ;
1009956 ( control. provide ) ( & mut local_providers) ;
1010957
1011958 let mut extern_providers = local_providers;
1012959 default_provide_extern ( & mut extern_providers) ;
960+ trans. provide_extern ( & mut extern_providers) ;
1013961 ( control. provide_extern ) ( & mut extern_providers) ;
1014962
1015963 let ( tx, rx) = mpsc:: channel ( ) ;
@@ -1101,9 +1049,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
11011049
11021050/// Run the translation phase to LLVM, after which the AST and analysis can
11031051/// be discarded.
1104- pub fn phase_4_translate_to_llvm < ' a , ' tcx , Trans : TransCrate > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
1052+ pub fn phase_4_translate_to_llvm < ' a , ' tcx > ( trans : & TransCrate ,
1053+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
11051054 rx : mpsc:: Receiver < Box < Any + Send > > )
1106- -> < Trans as TransCrate > :: OngoingCrateTranslation {
1055+ -> Box < Any > {
11071056 let time_passes = tcx. sess . time_passes ( ) ;
11081057
11091058 time ( time_passes,
@@ -1112,7 +1061,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx, Trans: TransCrate>(tcx: TyCtxt<'a, 't
11121061
11131062 let translation =
11141063 time ( time_passes, "translation" , move || {
1115- Trans :: trans_crate ( tcx, rx)
1064+ trans . trans_crate ( tcx, rx)
11161065 } ) ;
11171066 if tcx. sess . profile_queries ( ) {
11181067 profile:: dump ( "profile_queries" . to_string ( ) )
@@ -1121,25 +1070,6 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx, Trans: TransCrate>(tcx: TyCtxt<'a, 't
11211070 translation
11221071}
11231072
1124- /// Run LLVM itself, producing a bitcode file, assembly file or object file
1125- /// as a side effect.
1126- pub fn phase_5_run_llvm_passes < Trans : TransCrate > ( sess : & Session ,
1127- dep_graph : & DepGraph ,
1128- trans : <Trans as TransCrate >:: OngoingCrateTranslation )
1129- -> ( CompileResult , <Trans as TransCrate >:: TranslatedCrate ) {
1130- let trans = Trans :: join_trans ( trans, sess, dep_graph) ;
1131-
1132- if sess. opts . debugging_opts . incremental_info {
1133- Trans :: dump_incremental_data ( & trans) ;
1134- }
1135-
1136- time ( sess. time_passes ( ) ,
1137- "serialize work products" ,
1138- move || rustc_incremental:: save_work_products ( sess, dep_graph) ) ;
1139-
1140- ( sess. compile_status ( ) , trans)
1141- }
1142-
11431073fn escape_dep_filename ( filename : & FileName ) -> String {
11441074 // Apparently clang and gcc *only* escape spaces:
11451075 // http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
0 commit comments