Separate def collection and hir map making even further
This commit is contained in:
parent
d6bcc04c52
commit
6af7acab1c
@ -18,16 +18,14 @@ use syntax::ast::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
|
||||
/// Creates def ids for nodes in the HIR.
|
||||
pub struct DefCollector<'ast> {
|
||||
pub krate: &'ast Crate,
|
||||
pub map: &'ast [MapEntry<'ast>],
|
||||
pub definitions: Definitions,
|
||||
pub parent_def: Option<DefIndex>,
|
||||
}
|
||||
|
||||
impl<'ast> DefCollector<'ast> {
|
||||
pub fn root(krate: &'ast Crate, map: &'ast [MapEntry<'ast>]) -> DefCollector<'ast> {
|
||||
pub fn root(krate: &'ast Crate) -> DefCollector<'ast> {
|
||||
let mut collector = DefCollector {
|
||||
krate: krate,
|
||||
map: map,
|
||||
definitions: Definitions::new(),
|
||||
parent_def: None,
|
||||
};
|
||||
@ -43,12 +41,10 @@ impl<'ast> DefCollector<'ast> {
|
||||
parent_node: NodeId,
|
||||
parent_def_path: DefPath,
|
||||
parent_def_id: DefId,
|
||||
map: &'ast [MapEntry<'ast>],
|
||||
definitions: Definitions)
|
||||
-> DefCollector<'ast> {
|
||||
let mut collector = DefCollector {
|
||||
krate: krate,
|
||||
map: map,
|
||||
parent_def: None,
|
||||
definitions: definitions,
|
||||
};
|
||||
|
@ -782,19 +782,16 @@ impl<F: FoldOps> Folder for IdAndSpanUpdater<F> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_crate<'ast>(forest: &'ast mut Forest) -> Map<'ast> {
|
||||
let (map, definitions) = {
|
||||
let mut collector = NodeCollector::root(&forest.krate);
|
||||
intravisit::walk_crate(&mut collector, &forest.krate);
|
||||
pub fn collect_definitions<'ast>(forest: &'ast mut Forest) -> Definitions {
|
||||
let mut def_collector = DefCollector::root(&forest.krate);
|
||||
intravisit::walk_crate(&mut def_collector, &forest.krate);
|
||||
def_collector.definitions
|
||||
}
|
||||
|
||||
let definitions = {
|
||||
let mut def_collector = DefCollector::root(&forest.krate, &collector.map);
|
||||
intravisit::walk_crate(&mut def_collector, &forest.krate);
|
||||
def_collector.definitions
|
||||
};
|
||||
|
||||
(collector.map, definitions)
|
||||
};
|
||||
pub fn map_crate<'ast>(forest: &'ast mut Forest, definitions: Definitions) -> Map<'ast> {
|
||||
let mut collector = NodeCollector::root(&forest.krate);
|
||||
intravisit::walk_crate(&mut collector, &forest.krate);
|
||||
let map = collector.map;
|
||||
|
||||
if log_enabled!(::log::DEBUG) {
|
||||
// This only makes sense for ordered stores; note the
|
||||
@ -843,28 +840,24 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
|
||||
};
|
||||
|
||||
let ii = map.forest.inlined_items.alloc(ii);
|
||||
|
||||
let ii_parent_id = fld.new_id(DUMMY_NODE_ID);
|
||||
|
||||
let defs = mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new());
|
||||
let mut def_collector = DefCollector::extend(map.krate(),
|
||||
ii_parent_id,
|
||||
parent_def_path.clone(),
|
||||
parent_def_id,
|
||||
defs);
|
||||
ii.visit(&mut def_collector);
|
||||
*map.definitions.borrow_mut() = def_collector.definitions;
|
||||
|
||||
let mut collector = NodeCollector::extend(map.krate(),
|
||||
ii,
|
||||
ii_parent_id,
|
||||
parent_def_path.clone(),
|
||||
parent_def_path,
|
||||
parent_def_id,
|
||||
mem::replace(&mut *map.map.borrow_mut(), vec![]));
|
||||
ii.visit(&mut collector);
|
||||
|
||||
{
|
||||
let defs = mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new());
|
||||
let mut def_collector = DefCollector::extend(map.krate(),
|
||||
ii_parent_id,
|
||||
parent_def_path,
|
||||
parent_def_id,
|
||||
&collector.map,
|
||||
defs);
|
||||
ii.visit(&mut def_collector);
|
||||
*map.definitions.borrow_mut() = def_collector.definitions;
|
||||
}
|
||||
|
||||
*map.map.borrow_mut() = collector.map;
|
||||
|
||||
ii
|
||||
|
@ -156,7 +156,16 @@ pub fn compile_input(sess: &Session,
|
||||
}
|
||||
|
||||
let arenas = ty::CtxtArenas::new();
|
||||
let hir_map = make_map(sess, &mut hir_forest);
|
||||
// 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(),
|
||||
"indexing hir",
|
||||
move || hir_map::map_crate(hir_forest, defs));
|
||||
|
||||
|
||||
write_out_deps(sess, &outputs, &id);
|
||||
|
||||
@ -746,15 +755,6 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
|
||||
krate
|
||||
}
|
||||
|
||||
pub fn make_map<'ast>(sess: &Session,
|
||||
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.
|
||||
|
@ -738,7 +738,8 @@ pub fn pretty_print_input(sess: Session,
|
||||
let _ignore = dep_graph.in_ignore();
|
||||
let ast_map = if compute_ast_map {
|
||||
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
|
||||
let map = driver::make_map(&sess, &mut hir_forest);
|
||||
let defs = hir_map::collect_defs(hir_forest);
|
||||
let map = hir_map::map_crate(hir_forest, defs);
|
||||
Some(map)
|
||||
} else {
|
||||
None
|
||||
|
Loading…
x
Reference in New Issue
Block a user