@@ -409,12 +409,19 @@ pub fn stop_after_phase_5(sess: Session) -> bool {
409
409
pub fn compile_input ( sess : Session , cfg : ast:: CrateConfig , input : & input ,
410
410
outdir : & Option < Path > , output : & Option < Path > ) {
411
411
let outputs = build_output_filenames ( input, outdir, output, [ ] , sess) ;
412
- let crate = phase_1_parse_input ( sess, cfg. clone ( ) , input) ;
413
- if stop_after_phase_1 ( sess) { return ; }
414
- let expanded_crate = phase_2_configure_and_expand ( sess, cfg, crate ) ;
415
- let analysis = phase_3_run_analysis_passes ( sess, expanded_crate) ;
416
- if stop_after_phase_3 ( sess) { return ; }
417
- let trans = phase_4_translate_to_llvm ( sess, expanded_crate, & analysis, outputs) ;
412
+ // We need nested scopes here, because the intermediate results can keep
413
+ // large chunks of memory alive and we want to free them as soon as
414
+ // possible to keep the peak memory usage low
415
+ let trans = {
416
+ let expanded_crate = {
417
+ let crate = phase_1_parse_input ( sess, cfg. clone ( ) , input) ;
418
+ if stop_after_phase_1 ( sess) { return ; }
419
+ phase_2_configure_and_expand ( sess, cfg, crate )
420
+ } ;
421
+ let analysis = phase_3_run_analysis_passes ( sess, expanded_crate) ;
422
+ if stop_after_phase_3 ( sess) { return ; }
423
+ phase_4_translate_to_llvm ( sess, expanded_crate, & analysis, outputs)
424
+ } ;
418
425
phase_5_run_llvm_passes ( sess, & trans, outputs) ;
419
426
if stop_after_phase_5 ( sess) { return ; }
420
427
phase_6_link_output ( sess, & trans, outputs) ;
0 commit comments