From 1c86e475ca4ea7b2ed134d5d0bce66fde597d528 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sun, 10 Mar 2019 17:03:05 +0100 Subject: [PATCH] Drop expanded AST later if in save_analysis mode --- src/librustc_driver/lib.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 2b75a607f168..c7b6f37fe29d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -342,14 +342,12 @@ pub fn run_compiler( } if sess.opts.debugging_opts.save_analysis { - let expanded_crate = compiler.expansion()?.take().0; - + let expanded_crate = &compiler.expansion()?.peek().0; let crate_name = compiler.crate_name()?.peek().clone(); compiler.global_ctxt()?.peek_mut().enter(|tcx| { let result = tcx.analysis(LOCAL_CRATE); time(sess, "save analysis", || { - // FIXME: Should this run even with analysis errors? save::process_crate( tcx, &expanded_crate, @@ -361,17 +359,24 @@ pub fn run_compiler( }); result + // AST will be dropped *after* the `after_analysis` callback + // (needed by the RLS) })?; } else { // Drop AST after creating GlobalCtxt to free memory mem::drop(compiler.expansion()?.take()); } + compiler.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?; if !callbacks.after_analysis(compiler) { return sess.compile_status(); } + if sess.opts.debugging_opts.save_analysis { + mem::drop(compiler.expansion()?.take()); + } + compiler.ongoing_codegen()?; // Drop GlobalCtxt after starting codegen to free memory