@@ -70,7 +70,7 @@ pub fn compile_input(sess: &Session,
70
70
control : & CompileController ) -> CompileResult {
71
71
macro_rules! controller_entry_point {
72
72
( $point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => { {
73
- let state = $make_state;
73
+ let state = & mut $make_state;
74
74
let phase_result: & CompileResult = & $phase_result;
75
75
if phase_result. is_ok( ) || control. $point. run_callback_on_error {
76
76
( control. $point. callback) ( state) ;
@@ -95,17 +95,24 @@ pub fn compile_input(sess: &Session,
95
95
}
96
96
} ;
97
97
98
+ let mut compile_state = CompileState :: state_after_parse ( input,
99
+ sess,
100
+ outdir,
101
+ output,
102
+ krate,
103
+ & cstore) ;
98
104
controller_entry_point ! ( after_parse,
99
105
sess,
100
- CompileState :: state_after_parse ( input , sess , outdir , & krate ) ,
106
+ compile_state ,
101
107
Ok ( ( ) ) ) ;
108
+ let krate = compile_state. krate . unwrap ( ) ;
102
109
103
110
let outputs = build_output_filenames ( input, outdir, output, & krate. attrs , sess) ;
104
111
let id = link:: find_crate_name ( Some ( sess) , & krate. attrs , input) ;
105
112
let expanded_crate = phase_2_configure_and_expand ( sess,
106
113
& cstore,
107
114
krate,
108
- & id[ .. ] ,
115
+ & id,
109
116
addl_plugins) ?;
110
117
111
118
( outputs, expanded_crate, id)
@@ -116,8 +123,10 @@ pub fn compile_input(sess: &Session,
116
123
CompileState :: state_after_expand( input,
117
124
sess,
118
125
outdir,
126
+ output,
127
+ & cstore,
119
128
& expanded_crate,
120
- & id[ .. ] ) ,
129
+ & id) ,
121
130
Ok ( ( ) ) ) ;
122
131
123
132
let expanded_crate = assign_node_ids ( sess, expanded_crate) ;
@@ -162,10 +171,13 @@ pub fn compile_input(sess: &Session,
162
171
CompileState :: state_after_write_deps( input,
163
172
sess,
164
173
outdir,
174
+ output,
175
+ & arenas,
176
+ & cstore,
165
177
& hir_map,
166
178
& expanded_crate,
167
179
& hir_map. krate( ) ,
168
- & id[ .. ] ) ,
180
+ & id) ,
169
181
Ok ( ( ) ) ) ;
170
182
}
171
183
@@ -194,16 +206,17 @@ pub fn compile_input(sess: &Session,
194
206
// Eventually, we will want to track plugins.
195
207
let _ignore = tcx. dep_graph . in_ignore ( ) ;
196
208
197
- let state = CompileState :: state_after_analysis ( input,
198
- & tcx. sess ,
199
- outdir,
200
- opt_crate,
201
- tcx. map . krate ( ) ,
202
- & analysis,
203
- mir_map. as_ref ( ) ,
204
- tcx,
205
- & id) ;
206
- ( control. after_analysis . callback ) ( state) ;
209
+ let mut state = CompileState :: state_after_analysis ( input,
210
+ sess,
211
+ outdir,
212
+ output,
213
+ opt_crate,
214
+ tcx. map . krate ( ) ,
215
+ & analysis,
216
+ mir_map. as_ref ( ) ,
217
+ tcx,
218
+ & id) ;
219
+ ( control. after_analysis . callback ) ( & mut state) ;
207
220
208
221
if control. after_analysis . stop == Compilation :: Stop {
209
222
return result. and_then ( |_| Err ( 0usize ) ) ;
@@ -236,7 +249,7 @@ pub fn compile_input(sess: &Session,
236
249
237
250
controller_entry_point ! ( after_llvm,
238
251
sess,
239
- CompileState :: state_after_llvm( input, sess, outdir, & trans) ,
252
+ CompileState :: state_after_llvm( input, sess, outdir, output , & trans) ,
240
253
phase5_result) ;
241
254
phase5_result?;
242
255
@@ -311,7 +324,7 @@ pub struct PhaseController<'a> {
311
324
// If true then the compiler will try to run the callback even if the phase
312
325
// ends with an error. Note that this is not always possible.
313
326
pub run_callback_on_error : bool ,
314
- pub callback : Box < Fn ( CompileState ) -> ( ) + ' a > ,
327
+ pub callback : Box < Fn ( & mut CompileState ) + ' a > ,
315
328
}
316
329
317
330
impl < ' a > PhaseController < ' a > {
@@ -327,34 +340,38 @@ impl<'a> PhaseController<'a> {
327
340
/// State that is passed to a callback. What state is available depends on when
328
341
/// during compilation the callback is made. See the various constructor methods
329
342
/// (`state_*`) in the impl to see which data is provided for any given entry point.
330
- pub struct CompileState < ' a , ' ast : ' a , ' tcx : ' a > {
343
+ pub struct CompileState < ' a , ' b , ' ast : ' a , ' tcx : ' b > where ' ast : ' tcx {
331
344
pub input : & ' a Input ,
332
- pub session : & ' a Session ,
333
- pub cfg : Option < & ' a ast:: CrateConfig > ,
334
- pub krate : Option < & ' a ast :: Crate > ,
345
+ pub session : & ' ast Session ,
346
+ pub krate : Option < ast:: Crate > ,
347
+ pub cstore : Option < & ' a CStore > ,
335
348
pub crate_name : Option < & ' a str > ,
336
349
pub output_filenames : Option < & ' a OutputFilenames > ,
337
350
pub out_dir : Option < & ' a Path > ,
351
+ pub out_file : Option < & ' a Path > ,
352
+ pub arenas : Option < & ' ast ty:: CtxtArenas < ' ast > > ,
338
353
pub expanded_crate : Option < & ' a ast:: Crate > ,
339
354
pub hir_crate : Option < & ' a hir:: Crate > ,
340
355
pub ast_map : Option < & ' a hir_map:: Map < ' ast > > ,
341
- pub mir_map : Option < & ' a MirMap < ' tcx > > ,
356
+ pub mir_map : Option < & ' b MirMap < ' tcx > > ,
342
357
pub analysis : Option < & ' a ty:: CrateAnalysis < ' a > > ,
343
- pub tcx : Option < & ' a TyCtxt < ' tcx > > ,
358
+ pub tcx : Option < & ' b TyCtxt < ' tcx > > ,
344
359
pub trans : Option < & ' a trans:: CrateTranslation > ,
345
360
}
346
361
347
- impl < ' a , ' ast , ' tcx > CompileState < ' a , ' ast , ' tcx > {
362
+ impl < ' a , ' b , ' ast , ' tcx > CompileState < ' a , ' b , ' ast , ' tcx > {
348
363
fn empty ( input : & ' a Input ,
349
- session : & ' a Session ,
364
+ session : & ' ast Session ,
350
365
out_dir : & ' a Option < PathBuf > )
351
- -> CompileState < ' a , ' ast , ' tcx > {
366
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
352
367
CompileState {
353
368
input : input,
354
369
session : session,
355
370
out_dir : out_dir. as_ref ( ) . map ( |s| & * * s) ,
356
- cfg : None ,
371
+ out_file : None ,
372
+ arenas : None ,
357
373
krate : None ,
374
+ cstore : None ,
358
375
crate_name : None ,
359
376
output_filenames : None ,
360
377
expanded_crate : None ,
@@ -368,71 +385,95 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
368
385
}
369
386
370
387
fn state_after_parse ( input : & ' a Input ,
371
- session : & ' a Session ,
388
+ session : & ' ast Session ,
372
389
out_dir : & ' a Option < PathBuf > ,
373
- krate : & ' a ast:: Crate )
374
- -> CompileState < ' a , ' ast , ' tcx > {
375
- CompileState { krate : Some ( krate) , ..CompileState :: empty ( input, session, out_dir) }
390
+ out_file : & ' a Option < PathBuf > ,
391
+ krate : ast:: Crate ,
392
+ cstore : & ' a CStore )
393
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
394
+ CompileState {
395
+ krate : Some ( krate) ,
396
+ cstore : Some ( cstore) ,
397
+ out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
398
+ ..CompileState :: empty ( input, session, out_dir)
399
+ }
376
400
}
377
401
378
402
fn state_after_expand ( input : & ' a Input ,
379
- session : & ' a Session ,
403
+ session : & ' ast Session ,
380
404
out_dir : & ' a Option < PathBuf > ,
405
+ out_file : & ' a Option < PathBuf > ,
406
+ cstore : & ' a CStore ,
381
407
expanded_crate : & ' a ast:: Crate ,
382
408
crate_name : & ' a str )
383
- -> CompileState < ' a , ' ast , ' tcx > {
409
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
384
410
CompileState {
385
411
crate_name : Some ( crate_name) ,
412
+ cstore : Some ( cstore) ,
386
413
expanded_crate : Some ( expanded_crate) ,
414
+ out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
387
415
..CompileState :: empty ( input, session, out_dir)
388
416
}
389
417
}
390
418
391
419
fn state_after_write_deps ( input : & ' a Input ,
392
- session : & ' a Session ,
420
+ session : & ' ast Session ,
393
421
out_dir : & ' a Option < PathBuf > ,
422
+ out_file : & ' a Option < PathBuf > ,
423
+ arenas : & ' ast ty:: CtxtArenas < ' ast > ,
424
+ cstore : & ' a CStore ,
394
425
hir_map : & ' a hir_map:: Map < ' ast > ,
395
426
krate : & ' a ast:: Crate ,
396
427
hir_crate : & ' a hir:: Crate ,
397
428
crate_name : & ' a str )
398
- -> CompileState < ' a , ' ast , ' tcx > {
429
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
399
430
CompileState {
400
431
crate_name : Some ( crate_name) ,
432
+ arenas : Some ( arenas) ,
433
+ cstore : Some ( cstore) ,
401
434
ast_map : Some ( hir_map) ,
402
- krate : Some ( krate) ,
435
+ expanded_crate : Some ( krate) ,
403
436
hir_crate : Some ( hir_crate) ,
437
+ out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
404
438
..CompileState :: empty ( input, session, out_dir)
405
439
}
406
440
}
407
441
408
442
fn state_after_analysis ( input : & ' a Input ,
409
- session : & ' a Session ,
443
+ session : & ' ast Session ,
410
444
out_dir : & ' a Option < PathBuf > ,
445
+ out_file : & ' a Option < PathBuf > ,
411
446
krate : Option < & ' a ast:: Crate > ,
412
447
hir_crate : & ' a hir:: Crate ,
413
- analysis : & ' a ty:: CrateAnalysis ,
414
- mir_map : Option < & ' a MirMap < ' tcx > > ,
415
- tcx : & ' a TyCtxt < ' tcx > ,
448
+ analysis : & ' a ty:: CrateAnalysis < ' a > ,
449
+ mir_map : Option < & ' b MirMap < ' tcx > > ,
450
+ tcx : & ' b TyCtxt < ' tcx > ,
416
451
crate_name : & ' a str )
417
- -> CompileState < ' a , ' ast , ' tcx > {
452
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
418
453
CompileState {
419
454
analysis : Some ( analysis) ,
420
455
mir_map : mir_map,
421
456
tcx : Some ( tcx) ,
422
- krate : krate,
457
+ expanded_crate : krate,
423
458
hir_crate : Some ( hir_crate) ,
424
459
crate_name : Some ( crate_name) ,
460
+ out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
425
461
..CompileState :: empty ( input, session, out_dir)
426
462
}
427
463
}
428
464
429
465
430
466
fn state_after_llvm ( input : & ' a Input ,
431
- session : & ' a Session ,
467
+ session : & ' ast Session ,
432
468
out_dir : & ' a Option < PathBuf > ,
469
+ out_file : & ' a Option < PathBuf > ,
433
470
trans : & ' a trans:: CrateTranslation )
434
- -> CompileState < ' a , ' ast , ' tcx > {
435
- CompileState { trans : Some ( trans) , ..CompileState :: empty ( input, session, out_dir) }
471
+ -> CompileState < ' a , ' b , ' ast , ' tcx > {
472
+ CompileState {
473
+ trans : Some ( trans) ,
474
+ out_file : out_file. as_ref ( ) . map ( |s| & * * s) ,
475
+ ..CompileState :: empty ( input, session, out_dir)
476
+ }
436
477
}
437
478
}
438
479
@@ -798,16 +839,16 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
798
839
let index = stability:: Index :: new ( & hir_map) ;
799
840
800
841
TyCtxt :: create_and_enter ( sess,
801
- arenas,
802
- def_map,
803
- named_region_map,
804
- hir_map,
805
- freevars,
806
- region_map,
807
- lang_items,
808
- index,
809
- name,
810
- |tcx| {
842
+ arenas,
843
+ def_map,
844
+ named_region_map,
845
+ hir_map,
846
+ freevars,
847
+ region_map,
848
+ lang_items,
849
+ index,
850
+ name,
851
+ |tcx| {
811
852
time ( time_passes,
812
853
"load_dep_graph" ,
813
854
|| rustc_incremental:: load_dep_graph ( tcx) ) ;
0 commit comments