Skip to content

Commit 6af7aca

Browse files
committed
Separate def collection and hir map making even further
1 parent d6bcc04 commit 6af7aca

File tree

4 files changed

+33
-43
lines changed

4 files changed

+33
-43
lines changed

src/librustc/hir/map/def_collector.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ use syntax::ast::{NodeId, CRATE_NODE_ID, DUMMY_NODE_ID};
1818
/// Creates def ids for nodes in the HIR.
1919
pub struct DefCollector<'ast> {
2020
pub krate: &'ast Crate,
21-
pub map: &'ast [MapEntry<'ast>],
2221
pub definitions: Definitions,
2322
pub parent_def: Option<DefIndex>,
2423
}
2524

2625
impl<'ast> DefCollector<'ast> {
27-
pub fn root(krate: &'ast Crate, map: &'ast [MapEntry<'ast>]) -> DefCollector<'ast> {
26+
pub fn root(krate: &'ast Crate) -> DefCollector<'ast> {
2827
let mut collector = DefCollector {
2928
krate: krate,
30-
map: map,
3129
definitions: Definitions::new(),
3230
parent_def: None,
3331
};
@@ -43,12 +41,10 @@ impl<'ast> DefCollector<'ast> {
4341
parent_node: NodeId,
4442
parent_def_path: DefPath,
4543
parent_def_id: DefId,
46-
map: &'ast [MapEntry<'ast>],
4744
definitions: Definitions)
4845
-> DefCollector<'ast> {
4946
let mut collector = DefCollector {
5047
krate: krate,
51-
map: map,
5248
parent_def: None,
5349
definitions: definitions,
5450
};

src/librustc/hir/map/mod.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -782,19 +782,16 @@ impl<F: FoldOps> Folder for IdAndSpanUpdater<F> {
782782
}
783783
}
784784

785-
pub fn map_crate<'ast>(forest: &'ast mut Forest) -> Map<'ast> {
786-
let (map, definitions) = {
787-
let mut collector = NodeCollector::root(&forest.krate);
788-
intravisit::walk_crate(&mut collector, &forest.krate);
789-
790-
let definitions = {
791-
let mut def_collector = DefCollector::root(&forest.krate, &collector.map);
792-
intravisit::walk_crate(&mut def_collector, &forest.krate);
793-
def_collector.definitions
794-
};
785+
pub fn collect_definitions<'ast>(forest: &'ast mut Forest) -> Definitions {
786+
let mut def_collector = DefCollector::root(&forest.krate);
787+
intravisit::walk_crate(&mut def_collector, &forest.krate);
788+
def_collector.definitions
789+
}
795790

796-
(collector.map, definitions)
797-
};
791+
pub fn map_crate<'ast>(forest: &'ast mut Forest, definitions: Definitions) -> Map<'ast> {
792+
let mut collector = NodeCollector::root(&forest.krate);
793+
intravisit::walk_crate(&mut collector, &forest.krate);
794+
let map = collector.map;
798795

799796
if log_enabled!(::log::DEBUG) {
800797
// This only makes sense for ordered stores; note the
@@ -843,28 +840,24 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
843840
};
844841

845842
let ii = map.forest.inlined_items.alloc(ii);
846-
847843
let ii_parent_id = fld.new_id(DUMMY_NODE_ID);
844+
845+
let defs = mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new());
846+
let mut def_collector = DefCollector::extend(map.krate(),
847+
ii_parent_id,
848+
parent_def_path.clone(),
849+
parent_def_id,
850+
defs);
851+
ii.visit(&mut def_collector);
852+
*map.definitions.borrow_mut() = def_collector.definitions;
853+
848854
let mut collector = NodeCollector::extend(map.krate(),
849855
ii,
850856
ii_parent_id,
851-
parent_def_path.clone(),
857+
parent_def_path,
852858
parent_def_id,
853859
mem::replace(&mut *map.map.borrow_mut(), vec![]));
854860
ii.visit(&mut collector);
855-
856-
{
857-
let defs = mem::replace(&mut *map.definitions.borrow_mut(), Definitions::new());
858-
let mut def_collector = DefCollector::extend(map.krate(),
859-
ii_parent_id,
860-
parent_def_path,
861-
parent_def_id,
862-
&collector.map,
863-
defs);
864-
ii.visit(&mut def_collector);
865-
*map.definitions.borrow_mut() = def_collector.definitions;
866-
}
867-
868861
*map.map.borrow_mut() = collector.map;
869862

870863
ii

src/librustc_driver/driver.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,16 @@ pub fn compile_input(sess: &Session,
156156
}
157157

158158
let arenas = ty::CtxtArenas::new();
159-
let hir_map = make_map(sess, &mut hir_forest);
159+
// Collect defintions for def ids.
160+
let defs = time(sess.time_passes(),
161+
"collecting defs",
162+
move || hir_map::collect_defs(hir_forest));
163+
164+
// Construct the HIR map
165+
let hir_map = time(sess.time_passes(),
166+
"indexing hir",
167+
move || hir_map::map_crate(hir_forest, defs));
168+
160169

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

@@ -746,15 +755,6 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
746755
krate
747756
}
748757

749-
pub fn make_map<'ast>(sess: &Session,
750-
forest: &'ast mut hir_map::Forest)
751-
-> hir_map::Map<'ast> {
752-
// Construct the HIR map
753-
time(sess.time_passes(),
754-
"indexing hir",
755-
move || hir_map::map_crate(forest))
756-
}
757-
758758
/// Run the resolution, typechecking, region checking and other
759759
/// miscellaneous analysis passes on the crate. Return various
760760
/// structures carrying the results of the analysis.

src/librustc_driver/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ pub fn pretty_print_input(sess: Session,
738738
let _ignore = dep_graph.in_ignore();
739739
let ast_map = if compute_ast_map {
740740
hir_forest = hir_map::Forest::new(lower_crate(&lcx, &krate), dep_graph.clone());
741-
let map = driver::make_map(&sess, &mut hir_forest);
741+
let defs = hir_map::collect_defs(hir_forest);
742+
let map = hir_map::map_crate(hir_forest, defs);
742743
Some(map)
743744
} else {
744745
None

0 commit comments

Comments
 (0)