def_collector and crate reader operate on AST instead of HIR

And move extern crate reading earlier in the driver
This commit is contained in:
Nick Cameron 2016-04-14 14:51:21 +12:00
parent 6af7acab1c
commit 84c3f898f9
5 changed files with 112 additions and 150 deletions

View file

@ -122,32 +122,22 @@ pub fn compile_input(sess: &Session,
let expanded_crate = assign_node_ids(sess, expanded_crate);
let dep_graph = DepGraph::new(sess.opts.build_dep_graph);
// TODO
// time(sess.time_passes(),
// "external crate/lib resolution",
// || LocalCrateReader::new(sess, &cstore, &defs, &id).read_crates());
// Collect defintions for def ids.
let defs = time(sess.time_passes(),
"collecting defs",
|| hir_map::collect_definitions(&expanded_crate));
// TODO
panic!();
// TODO CrateMap result
// let resolve::CrateMap {
// def_map,
// freevars,
// export_map,
// trait_map,
// glob_map,
// } = time(sess.time_passes(),
// "name resolution",
// || resolve::resolve_crate(sess, &hir_map, control.make_glob_map));
time(sess.time_passes(),
"external crate/lib resolution",
|| LocalCrateReader::new(sess, &cstore, &defs, &expanded_crate, &id)
.read_crates(&dep_graph));
// Lower ast -> hir.
let lcx = LoweringContext::new(sess, Some(&expanded_crate));
let dep_graph = DepGraph::new(sess.opts.build_dep_graph());
let mut hir_forest = time(sess.time_passes(),
"lowering ast -> hir",
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate),
dep_graph));
let hir_forest = &mut time(sess.time_passes(),
"lowering ast -> hir",
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate),
dep_graph));
// Discard MTWT tables that aren't required past lowering to HIR.
if !sess.opts.debugging_opts.keep_mtwt_tables &&
@ -156,10 +146,6 @@ pub fn compile_input(sess: &Session,
}
let arenas = ty::CtxtArenas::new();
// Collect defintions for def ids.
let defs = time(sess.time_passes(),
"collecting defs",
move || hir_map::collect_defs(hir_forest));
// Construct the HIR map
let hir_map = time(sess.time_passes(),
@ -201,10 +187,10 @@ pub fn compile_input(sess: &Session,
};
phase_3_run_analysis_passes(sess,
&cstore,
hir_map,
&arenas,
&id,
control.make_glob_map,
|tcx, mir_map, analysis, result| {
{
// Eventually, we will want to track plugins.
@ -759,10 +745,10 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
/// 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,
hir_map: hir_map::Map<'tcx>,
arenas: &'tcx ty::CtxtArenas<'tcx>,
name: &str,
make_glob_map: resolve::MakeGlobMap,
f: F)
-> Result<R, usize>
where F: FnOnce(&TyCtxt<'tcx>, Option<MirMap<'tcx>>, ty::CrateAnalysis, CompileResult) -> R
@ -787,6 +773,16 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
})
})?;
let resolve::CrateMap {
def_map,
freevars,
export_map,
trait_map,
glob_map,
} = time(sess.time_passes(),
"name resolution",
|| resolve::resolve_crate(sess, &hir_map, make_glob_map));
let mut analysis = ty::CrateAnalysis {
export_map: export_map,
access_levels: AccessLevels::default(),

View file

@ -179,7 +179,6 @@ impl PpSourceMode {
}
fn call_with_pp_support_hir<'tcx, A, B, F>(&self,
sess: &'tcx Session,
cstore: &CStore,
ast_map: &hir_map::Map<'tcx>,
arenas: &'tcx ty::CtxtArenas<'tcx>,
id: &str,
@ -206,7 +205,6 @@ impl PpSourceMode {
}
PpmTyped => {
abort_on_err(driver::phase_3_run_analysis_passes(sess,
cstore,
ast_map.clone(),
arenas,
id,
@ -737,9 +735,9 @@ pub fn pretty_print_input(sess: Session,
let dep_graph = DepGraph::new(false);
let _ignore = dep_graph.in_ignore();
let ast_map = if compute_ast_map {
let defs = hir_map::collect_definitions(&krate);
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
let defs = hir_map::collect_defs(hir_forest);
let map = hir_map::map_crate(hir_forest, defs);
let map = hir_map::map_crate(&mut hir_forest, defs);
Some(map)
} else {
None
@ -778,7 +776,6 @@ pub fn pretty_print_input(sess: Session,
(PpmHir(s), None) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(&sess,
cstore,
&ast_map.unwrap(),
&arenas,
&id,
@ -800,7 +797,6 @@ pub fn pretty_print_input(sess: Session,
(PpmHir(s), Some(uii)) => {
let out: &mut Write = &mut out;
s.call_with_pp_support_hir(&sess,
cstore,
&ast_map.unwrap(),
&arenas,
&id,
@ -841,7 +837,6 @@ pub fn pretty_print_input(sess: Session,
None
};
abort_on_err(driver::phase_3_run_analysis_passes(&sess,
&cstore,
ast_map,
&arenas,
&id,
@ -888,7 +883,6 @@ pub fn pretty_print_input(sess: Session,
Some(code) => {
let variants = gather_flowgraph_variants(&sess);
abort_on_err(driver::phase_3_run_analysis_passes(&sess,
&cstore,
ast_map,
&arenas,
&id,