Drop expanded AST later if in save_analysis mode

This commit is contained in:
Igor Matuszewski 2019-03-10 17:03:05 +01:00
parent 913ad6d1f0
commit 1c86e475ca

View File

@ -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