diff options
| author | Björn Steinbrink <bsteinbr@gmail.com> | 2013-07-28 19:56:05 +0200 |
|---|---|---|
| committer | Björn Steinbrink <bsteinbr@gmail.com> | 2013-07-28 20:02:31 +0200 |
| commit | 075560a9f2f715ac0e599a13d26d1a910be36509 (patch) | |
| tree | 39e316c51ead89963fc57839067d3af5cd6943a1 | |
| parent | 293ec2c5820e8b5dc4394e2c11ad3d2e9cfb56eb (diff) | |
| download | rust-075560a9f2f715ac0e599a13d26d1a910be36509.tar.gz rust-075560a9f2f715ac0e599a13d26d1a910be36509.zip | |
Free intermediate translation results as soon as possible
This fixes the recently introduced peak memory usage regression by freeing the intermediate results as soon as they're not required anymore instead of keeping them around for the whole compilation process. Refs #8077
| -rw-r--r-- | src/librustc/driver/driver.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 65b78baba40..e81b6919bef 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -409,12 +409,19 @@ pub fn stop_after_phase_5(sess: Session) -> bool { pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input, outdir: &Option<Path>, output: &Option<Path>) { let outputs = build_output_filenames(input, outdir, output, [], sess); - let crate = phase_1_parse_input(sess, cfg.clone(), input); - if stop_after_phase_1(sess) { return; } - let expanded_crate = phase_2_configure_and_expand(sess, cfg, crate); - let analysis = phase_3_run_analysis_passes(sess, expanded_crate); - if stop_after_phase_3(sess) { return; } - let trans = phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs); + // We need nested scopes here, because the intermediate results can keep + // large chunks of memory alive and we want to free them as soon as + // possible to keep the peak memory usage low + let trans = { + let expanded_crate = { + let crate = phase_1_parse_input(sess, cfg.clone(), input); + if stop_after_phase_1(sess) { return; } + phase_2_configure_and_expand(sess, cfg, crate) + }; + let analysis = phase_3_run_analysis_passes(sess, expanded_crate); + if stop_after_phase_3(sess) { return; } + phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs) + }; phase_5_run_llvm_passes(sess, &trans, outputs); if stop_after_phase_5(sess) { return; } phase_6_link_output(sess, &trans, outputs); |
