Skip to content

Commit 3150ddd

Browse files
committed
Auto merge of #30558 - jonas-schievink:delete-ast, r=nrc
Or more specifically, after running early lints. Closes #28142
2 parents 5b838c5 + 389e8e3 commit 3150ddd

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

src/librustc/session/config.rs

+2
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

+31-25
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn compile_input(sess: Session,
121121
}
122122

123123
let arenas = ty::CtxtArenas::new();
124-
let ast_map = make_map(&sess, &mut hir_forest);
124+
let hir_map = make_map(&sess, &mut hir_forest);
125125

126126
write_out_deps(&sess, &outputs, &id);
127127

@@ -130,9 +130,9 @@ pub fn compile_input(sess: Session,
130130
CompileState::state_after_write_deps(input,
131131
&sess,
132132
outdir,
133-
&ast_map,
133+
&hir_map,
134134
&expanded_crate,
135-
&ast_map.krate(),
135+
&hir_map.krate(),
136136
&id[..],
137137
&lcx));
138138

@@ -144,9 +144,17 @@ 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,
149-
ast_map,
157+
hir_map,
150158
&arenas,
151159
&id,
152160
control.make_glob_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,
@@ -341,15 +349,15 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
341349
fn state_after_write_deps(input: &'a Input,
342350
session: &'a Session,
343351
out_dir: &'a Option<PathBuf>,
344-
ast_map: &'a hir_map::Map<'ast>,
352+
hir_map: &'a hir_map::Map<'ast>,
345353
krate: &'a ast::Crate,
346354
hir_crate: &'a hir::Crate,
347355
crate_name: &'a str,
348356
lcx: &'a LoweringContext<'a>)
349357
-> CompileState<'a, 'ast, 'tcx> {
350358
CompileState {
351359
crate_name: Some(crate_name),
352-
ast_map: Some(ast_map),
360+
ast_map: Some(hir_map),
353361
krate: Some(krate),
354362
hir_crate: Some(hir_crate),
355363
lcx: Some(lcx),
@@ -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),
@@ -670,22 +678,20 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
670678
}
671679

672680
pub fn make_map<'ast>(sess: &Session,
673-
forest: &'ast mut front::map::Forest)
674-
-> front::map::Map<'ast> {
675-
// Construct the 'ast'-map
676-
let map = time(sess.time_passes(),
677-
"indexing hir",
678-
move || front::map::map_crate(forest));
679-
680-
map
681+
forest: &'ast mut hir_map::Forest)
682+
-> hir_map::Map<'ast> {
683+
// Construct the HIR map
684+
time(sess.time_passes(),
685+
"indexing hir",
686+
move || hir_map::map_crate(forest))
681687
}
682688

683689
/// Run the resolution, typechecking, region checking and other
684690
/// miscellaneous analysis passes on the crate. Return various
685691
/// structures carrying the results of the analysis.
686692
pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
687693
cstore: &CStore,
688-
ast_map: front::map::Map<'tcx>,
694+
hir_map: hir_map::Map<'tcx>,
689695
arenas: &'tcx ty::CtxtArenas<'tcx>,
690696
name: &str,
691697
make_glob_map: resolve::MakeGlobMap,
@@ -694,15 +700,15 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
694700
where F: for<'a> FnOnce(&'a ty::ctxt<'tcx>, MirMap<'tcx>, ty::CrateAnalysis) -> R
695701
{
696702
let time_passes = sess.time_passes();
697-
let krate = ast_map.krate();
703+
let krate = hir_map.krate();
698704

699705
time(time_passes,
700706
"external crate/lib resolution",
701-
|| LocalCrateReader::new(sess, cstore, &ast_map).read_crates(krate));
707+
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates(krate));
702708

703709
let lang_items = time(time_passes,
704710
"language item collection",
705-
|| middle::lang_items::collect_language_items(&sess, &ast_map));
711+
|| middle::lang_items::collect_language_items(&sess, &hir_map));
706712

707713
let resolve::CrateMap {
708714
def_map,
@@ -713,15 +719,15 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
713719
glob_map,
714720
} = time(time_passes,
715721
"resolution",
716-
|| resolve::resolve_crate(sess, &ast_map, make_glob_map));
722+
|| resolve::resolve_crate(sess, &hir_map, make_glob_map));
717723

718724
let named_region_map = time(time_passes,
719725
"lifetime resolution",
720726
|| middle::resolve_lifetime::krate(sess, krate, &def_map.borrow()));
721727

722728
time(time_passes,
723729
"looking for entry point",
724-
|| middle::entry::find_entry_point(sess, &ast_map));
730+
|| middle::entry::find_entry_point(sess, &hir_map));
725731

726732
sess.plugin_registrar_fn.set(time(time_passes, "looking for plugin registrar", || {
727733
plugin::build::find_plugin_registrar(sess.diagnostic(), krate)
@@ -737,13 +743,13 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
737743

738744
time(time_passes,
739745
"static item recursion checking",
740-
|| middle::check_static_recursion::check_crate(sess, krate, &def_map.borrow(), &ast_map));
746+
|| middle::check_static_recursion::check_crate(sess, krate, &def_map.borrow(), &hir_map));
741747

742748
ty::ctxt::create_and_enter(sess,
743749
arenas,
744750
def_map,
745751
named_region_map,
746-
ast_map,
752+
hir_map,
747753
freevars,
748754
region_map,
749755
lang_items,

0 commit comments

Comments
 (0)