Skip to content

Commit 389e8e3

Browse files
Delete the AST after lowering
1 parent 93a6559 commit 389e8e3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
622622
"force nonzeroing move optimization on"),
623623
keep_mtwt_tables: bool = (false, parse_bool,
624624
"don't clear the resolution tables after analysis"),
625+
keep_ast: bool = (false, parse_bool,
626+
"keep the AST after lowering it to HIR"),
625627
}
626628

627629
pub fn default_lib_output() -> CrateType {

src/librustc_driver/driver.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ pub fn compile_input(sess: Session,
144144
"early lint checks",
145145
|| lint::check_ast_crate(&sess, &expanded_crate));
146146

147+
let opt_crate = if sess.opts.debugging_opts.keep_ast ||
148+
sess.opts.debugging_opts.save_analysis {
149+
Some(&expanded_crate)
150+
} else {
151+
drop(expanded_crate);
152+
None
153+
};
154+
147155
phase_3_run_analysis_passes(&sess,
148156
&cstore,
149157
hir_map,
@@ -157,7 +165,7 @@ pub fn compile_input(sess: Session,
157165
CompileState::state_after_analysis(input,
158166
&tcx.sess,
159167
outdir,
160-
&expanded_crate,
168+
opt_crate,
161169
tcx.map.krate(),
162170
&analysis,
163171
&mir_map,
@@ -360,7 +368,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
360368
fn state_after_analysis(input: &'a Input,
361369
session: &'a Session,
362370
out_dir: &'a Option<PathBuf>,
363-
krate: &'a ast::Crate,
371+
krate: Option<&'a ast::Crate>,
364372
hir_crate: &'a hir::Crate,
365373
analysis: &'a ty::CrateAnalysis,
366374
mir_map: &'a MirMap<'tcx>,
@@ -372,7 +380,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
372380
analysis: Some(analysis),
373381
mir_map: Some(mir_map),
374382
tcx: Some(tcx),
375-
krate: Some(krate),
383+
krate: krate,
376384
hir_crate: Some(hir_crate),
377385
lcx: Some(lcx),
378386
crate_name: Some(crate_name),

0 commit comments

Comments
 (0)