@@ -31,7 +31,6 @@ use rustc_incremental;
31
31
use rustc_resolve:: { MakeGlobMap , Resolver } ;
32
32
use rustc_metadata:: creader:: CrateLoader ;
33
33
use rustc_metadata:: cstore:: { self , CStore } ;
34
- use rustc_trans as trans;
35
34
use rustc_trans_utils:: trans_crate:: TransCrate ;
36
35
use rustc_typeck as typeck;
37
36
use rustc_privacy;
@@ -40,7 +39,6 @@ use rustc_plugin as plugin;
40
39
use rustc_passes:: { self , ast_validation, loops, consts, static_recursion, hir_stats} ;
41
40
use rustc_const_eval:: { self , check_match} ;
42
41
use super :: Compilation ;
43
- use :: DefaultTransCrate ;
44
42
45
43
use serialize:: json;
46
44
@@ -68,16 +66,15 @@ use pretty::ReplaceBodyWithLoop;
68
66
69
67
use profile;
70
68
71
- pub fn compile_input ( sess : & Session ,
69
+ pub fn compile_input ( trans : Box < TransCrate > ,
70
+ sess : & Session ,
72
71
cstore : & CStore ,
73
72
input_path : & Option < PathBuf > ,
74
73
input : & Input ,
75
74
outdir : & Option < PathBuf > ,
76
75
output : & Option < PathBuf > ,
77
76
addl_plugins : Option < Vec < String > > ,
78
77
control : & CompileController ) -> CompileResult {
79
- use rustc:: session:: config:: CrateType ;
80
-
81
78
macro_rules! controller_entry_point {
82
79
( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
83
80
let state = & mut $make_state;
@@ -94,30 +91,14 @@ pub fn compile_input(sess: &Session,
94
91
} }
95
92
}
96
93
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
-
113
94
if sess. profile_queries ( ) {
114
95
profile:: begin ( ) ;
115
96
}
116
97
117
98
// We need nested scopes here, because the intermediate results can keep
118
99
// large chunks of memory alive and we want to free them as soon as
119
100
// possible to keep the peak memory usage low
120
- let ( outputs, trans , dep_graph) = {
101
+ let ( outputs, ongoing_trans , dep_graph) = {
121
102
let krate = match phase_1_parse_input ( control, sess, input) {
122
103
Ok ( krate) => krate,
123
104
Err ( mut parse_error) => {
@@ -217,7 +198,8 @@ pub fn compile_input(sess: &Session,
217
198
None
218
199
} ;
219
200
220
- phase_3_run_analysis_passes ( control,
201
+ phase_3_run_analysis_passes ( & * trans,
202
+ control,
221
203
sess,
222
204
cstore,
223
205
hir_map,
@@ -254,7 +236,7 @@ pub fn compile_input(sess: &Session,
254
236
tcx. print_debug_stats ( ) ;
255
237
}
256
238
257
- let trans = phase_4_translate_to_llvm :: < DefaultTransCrate > ( tcx, rx) ;
239
+ let ongoing_trans = phase_4_translate_to_llvm ( & * trans , tcx, rx) ;
258
240
259
241
if log_enabled ! ( :: log:: Level :: Info ) {
260
242
println ! ( "Post-trans" ) ;
@@ -268,33 +250,15 @@ pub fn compile_input(sess: &Session,
268
250
}
269
251
}
270
252
271
- Ok ( ( outputs. clone ( ) , trans , tcx. dep_graph . clone ( ) ) )
253
+ Ok ( ( outputs. clone ( ) , ongoing_trans , tcx. dep_graph . clone ( ) ) )
272
254
} ) ??
273
255
} ;
274
256
275
257
if sess. opts . debugging_opts . print_type_sizes {
276
258
sess. code_stats . borrow ( ) . print_type_sizes ( ) ;
277
259
}
278
260
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) ?;
298
262
299
263
if sess. opts . debugging_opts . perf_stats {
300
264
sess. print_perf_stats ( ) ;
@@ -340,7 +304,6 @@ pub struct CompileController<'a> {
340
304
pub after_expand : PhaseController < ' a > ,
341
305
pub after_hir_lowering : PhaseController < ' a > ,
342
306
pub after_analysis : PhaseController < ' a > ,
343
- pub after_llvm : PhaseController < ' a > ,
344
307
pub compilation_done : PhaseController < ' a > ,
345
308
346
309
// FIXME we probably want to group the below options together and offer a
@@ -366,7 +329,6 @@ impl<'a> CompileController<'a> {
366
329
after_expand : PhaseController :: basic ( ) ,
367
330
after_hir_lowering : PhaseController :: basic ( ) ,
368
331
after_analysis : PhaseController :: basic ( ) ,
369
- after_llvm : PhaseController :: basic ( ) ,
370
332
compilation_done : PhaseController :: basic ( ) ,
371
333
make_glob_map : MakeGlobMap :: No ,
372
334
keep_ast : false ,
@@ -415,7 +377,6 @@ pub struct CompileState<'a, 'tcx: 'a> {
415
377
pub resolutions : Option < & ' a Resolutions > ,
416
378
pub analysis : Option < & ' a ty:: CrateAnalysis > ,
417
379
pub tcx : Option < TyCtxt < ' a , ' tcx , ' tcx > > ,
418
- pub trans : Option < & ' a trans:: CrateTranslation > ,
419
380
}
420
381
421
382
impl < ' a , ' tcx > CompileState < ' a , ' tcx > {
@@ -440,7 +401,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
440
401
resolutions : None ,
441
402
analysis : None ,
442
403
tcx : None ,
443
- trans : None ,
444
404
}
445
405
}
446
406
@@ -528,19 +488,6 @@ impl<'a, 'tcx> CompileState<'a, 'tcx> {
528
488
}
529
489
}
530
490
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
-
544
491
fn state_when_compilation_done ( input : & ' a Input ,
545
492
session : & ' tcx Session ,
546
493
out_dir : & ' a Option < PathBuf > ,
@@ -933,7 +880,6 @@ pub fn default_provide(providers: &mut ty::maps::Providers) {
933
880
reachable:: provide ( providers) ;
934
881
resolve_lifetime:: provide ( providers) ;
935
882
rustc_privacy:: provide ( providers) ;
936
- DefaultTransCrate :: provide ( providers) ;
937
883
typeck:: provide ( providers) ;
938
884
ty:: provide ( providers) ;
939
885
traits:: provide ( providers) ;
@@ -947,13 +893,13 @@ pub fn default_provide(providers: &mut ty::maps::Providers) {
947
893
948
894
pub fn default_provide_extern ( providers : & mut ty:: maps:: Providers ) {
949
895
cstore:: provide_extern ( providers) ;
950
- DefaultTransCrate :: provide_extern ( providers) ;
951
896
}
952
897
953
898
/// Run the resolution, typechecking, region checking and other
954
899
/// miscellaneous analysis passes on the crate. Return various
955
900
/// 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 ,
957
903
sess : & ' tcx Session ,
958
904
cstore : & ' tcx CrateStore ,
959
905
hir_map : hir_map:: Map < ' tcx > ,
@@ -1006,10 +952,12 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
1006
952
1007
953
let mut local_providers = ty:: maps:: Providers :: default ( ) ;
1008
954
default_provide ( & mut local_providers) ;
955
+ trans. provide ( & mut local_providers) ;
1009
956
( control. provide ) ( & mut local_providers) ;
1010
957
1011
958
let mut extern_providers = local_providers;
1012
959
default_provide_extern ( & mut extern_providers) ;
960
+ trans. provide_extern ( & mut extern_providers) ;
1013
961
( control. provide_extern ) ( & mut extern_providers) ;
1014
962
1015
963
let ( tx, rx) = mpsc:: channel ( ) ;
@@ -1101,9 +1049,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
1101
1049
1102
1050
/// Run the translation phase to LLVM, after which the AST and analysis can
1103
1051
/// 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 > ,
1105
1054
rx : mpsc:: Receiver < Box < Any + Send > > )
1106
- -> < Trans as TransCrate > :: OngoingCrateTranslation {
1055
+ -> Box < Any > {
1107
1056
let time_passes = tcx. sess . time_passes ( ) ;
1108
1057
1109
1058
time ( time_passes,
@@ -1112,7 +1061,7 @@ pub fn phase_4_translate_to_llvm<'a, 'tcx, Trans: TransCrate>(tcx: TyCtxt<'a, 't
1112
1061
1113
1062
let translation =
1114
1063
time ( time_passes, "translation" , move || {
1115
- Trans :: trans_crate ( tcx, rx)
1064
+ trans . trans_crate ( tcx, rx)
1116
1065
} ) ;
1117
1066
if tcx. sess . profile_queries ( ) {
1118
1067
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
1121
1070
translation
1122
1071
}
1123
1072
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
-
1143
1073
fn escape_dep_filename ( filename : & FileName ) -> String {
1144
1074
// Apparently clang and gcc *only* escape spaces:
1145
1075
// http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
0 commit comments