Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"force nonzeroing move optimization on"),
keep_mtwt_tables: bool = (false, parse_bool,
"don't clear the resolution tables after analysis"),
keep_ast: bool = (false, parse_bool,
"keep the AST after lowering it to HIR"),
}

pub fn default_lib_output() -> CrateType {
Expand Down
56 changes: 31 additions & 25 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub fn compile_input(sess: Session,
}

let arenas = ty::CtxtArenas::new();
let ast_map = make_map(&sess, &mut hir_forest);
let hir_map = make_map(&sess, &mut hir_forest);

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

Expand All @@ -130,9 +130,9 @@ pub fn compile_input(sess: Session,
CompileState::state_after_write_deps(input,
&sess,
outdir,
&ast_map,
&hir_map,
&expanded_crate,
&ast_map.krate(),
&hir_map.krate(),
&id[..],
&lcx));

Expand All @@ -144,9 +144,17 @@ pub fn compile_input(sess: Session,
"early lint checks",
|| lint::check_ast_crate(&sess, &expanded_crate));

let opt_crate = if sess.opts.debugging_opts.keep_ast ||
sess.opts.debugging_opts.save_analysis {
Some(&expanded_crate)
} else {
drop(expanded_crate);
None
};

phase_3_run_analysis_passes(&sess,
&cstore,
ast_map,
hir_map,
&arenas,
&id,
control.make_glob_map,
Expand All @@ -157,7 +165,7 @@ pub fn compile_input(sess: Session,
CompileState::state_after_analysis(input,
&tcx.sess,
outdir,
&expanded_crate,
opt_crate,
tcx.map.krate(),
&analysis,
&mir_map,
Expand Down Expand Up @@ -341,15 +349,15 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
fn state_after_write_deps(input: &'a Input,
session: &'a Session,
out_dir: &'a Option<PathBuf>,
ast_map: &'a hir_map::Map<'ast>,
hir_map: &'a hir_map::Map<'ast>,
krate: &'a ast::Crate,
hir_crate: &'a hir::Crate,
crate_name: &'a str,
lcx: &'a LoweringContext<'a>)
-> CompileState<'a, 'ast, 'tcx> {
CompileState {
crate_name: Some(crate_name),
ast_map: Some(ast_map),
ast_map: Some(hir_map),
krate: Some(krate),
hir_crate: Some(hir_crate),
lcx: Some(lcx),
Expand All @@ -360,7 +368,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
fn state_after_analysis(input: &'a Input,
session: &'a Session,
out_dir: &'a Option<PathBuf>,
krate: &'a ast::Crate,
krate: Option<&'a ast::Crate>,
hir_crate: &'a hir::Crate,
analysis: &'a ty::CrateAnalysis,
mir_map: &'a MirMap<'tcx>,
Expand All @@ -372,7 +380,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
analysis: Some(analysis),
mir_map: Some(mir_map),
tcx: Some(tcx),
krate: Some(krate),
krate: krate,
hir_crate: Some(hir_crate),
lcx: Some(lcx),
crate_name: Some(crate_name),
Expand Down Expand Up @@ -670,22 +678,20 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
}

pub fn make_map<'ast>(sess: &Session,
forest: &'ast mut front::map::Forest)
-> front::map::Map<'ast> {
// Construct the 'ast'-map
let map = time(sess.time_passes(),
"indexing hir",
move || front::map::map_crate(forest));

map
forest: &'ast mut hir_map::Forest)
-> hir_map::Map<'ast> {
// Construct the HIR map
time(sess.time_passes(),
"indexing hir",
move || hir_map::map_crate(forest))
}

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

time(time_passes,
"external crate/lib resolution",
|| LocalCrateReader::new(sess, cstore, &ast_map).read_crates(krate));
|| LocalCrateReader::new(sess, cstore, &hir_map).read_crates(krate));

let lang_items = time(time_passes,
"language item collection",
|| middle::lang_items::collect_language_items(&sess, &ast_map));
|| middle::lang_items::collect_language_items(&sess, &hir_map));

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

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

time(time_passes,
"looking for entry point",
|| middle::entry::find_entry_point(sess, &ast_map));
|| middle::entry::find_entry_point(sess, &hir_map));

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

time(time_passes,
"static item recursion checking",
|| middle::check_static_recursion::check_crate(sess, krate, &def_map.borrow(), &ast_map));
|| middle::check_static_recursion::check_crate(sess, krate, &def_map.borrow(), &hir_map));

ty::ctxt::create_and_enter(sess,
arenas,
def_map,
named_region_map,
ast_map,
hir_map,
freevars,
region_map,
lang_items,
Expand Down