groundwork: create the Resolver
earlier in phase 2
This commit is contained in:
parent
ec0c150152
commit
e58963d3e4
@ -25,15 +25,15 @@ pub struct DefCollector<'ast> {
|
||||
// If we are walking HIR (c.f., AST), we need to keep a reference to the
|
||||
// crate.
|
||||
hir_crate: Option<&'ast hir::Crate>,
|
||||
pub definitions: Definitions,
|
||||
definitions: &'ast mut Definitions,
|
||||
parent_def: Option<DefIndex>,
|
||||
}
|
||||
|
||||
impl<'ast> DefCollector<'ast> {
|
||||
pub fn root() -> DefCollector<'ast> {
|
||||
pub fn root(definitions: &'ast mut Definitions) -> DefCollector<'ast> {
|
||||
let mut collector = DefCollector {
|
||||
hir_crate: None,
|
||||
definitions: Definitions::new(),
|
||||
definitions: definitions,
|
||||
parent_def: None,
|
||||
};
|
||||
let root = collector.create_def_with_parent(None, CRATE_NODE_ID, DefPathData::CrateRoot);
|
||||
@ -48,7 +48,7 @@ impl<'ast> DefCollector<'ast> {
|
||||
pub fn extend(parent_node: NodeId,
|
||||
parent_def_path: DefPath,
|
||||
parent_def_id: DefId,
|
||||
definitions: Definitions)
|
||||
definitions: &'ast mut Definitions)
|
||||
-> DefCollector<'ast> {
|
||||
let mut collector = DefCollector {
|
||||
hir_crate: None,
|
||||
|
@ -10,8 +10,9 @@
|
||||
|
||||
use middle::cstore::LOCAL_CRATE;
|
||||
use hir::def_id::{DefId, DefIndex};
|
||||
use hir::map::def_collector::DefCollector;
|
||||
use rustc_data_structures::fnv::FnvHashMap;
|
||||
use syntax::ast;
|
||||
use syntax::{ast, visit};
|
||||
use syntax::parse::token::InternedString;
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
@ -189,6 +190,11 @@ impl Definitions {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect(&mut self, krate: &ast::Crate) {
|
||||
let mut def_collector = DefCollector::root(self);
|
||||
visit::walk_crate(&mut def_collector, krate);
|
||||
}
|
||||
|
||||
/// Get the number of definitions.
|
||||
pub fn len(&self) -> usize {
|
||||
self.data.len()
|
||||
|
@ -24,7 +24,6 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
|
||||
use syntax::abi::Abi;
|
||||
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID, };
|
||||
use syntax::codemap::Spanned;
|
||||
use syntax::visit;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use hir::*;
|
||||
@ -780,12 +779,6 @@ impl<F: FoldOps> Folder for IdAndSpanUpdater<F> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn collect_definitions<'ast>(krate: &'ast ast::Crate) -> Definitions {
|
||||
let mut def_collector = DefCollector::root();
|
||||
visit::walk_crate(&mut def_collector, krate);
|
||||
def_collector.definitions
|
||||
}
|
||||
|
||||
pub fn map_crate<'ast>(forest: &'ast mut Forest,
|
||||
definitions: Definitions)
|
||||
-> Map<'ast> {
|
||||
@ -842,13 +835,12 @@ 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 defs = &mut *map.definitions.borrow_mut();
|
||||
let mut def_collector = DefCollector::extend(ii_parent_id,
|
||||
parent_def_path.clone(),
|
||||
parent_def_id,
|
||||
defs);
|
||||
def_collector.walk_item(ii, map.krate());
|
||||
*map.definitions.borrow_mut() = def_collector.definitions;
|
||||
|
||||
let mut collector = NodeCollector::extend(map.krate(),
|
||||
ii,
|
||||
|
@ -726,13 +726,16 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
|
||||
|
||||
krate = assign_node_ids(sess, krate);
|
||||
|
||||
// Collect defintions for def ids.
|
||||
let defs =
|
||||
time(sess.time_passes(), "collecting defs", || hir_map::collect_definitions(&krate));
|
||||
let resolver_arenas = Resolver::arenas();
|
||||
let mut resolver = Resolver::new(sess, make_glob_map, &resolver_arenas);
|
||||
|
||||
time(sess.time_passes(),
|
||||
"external crate/lib resolution",
|
||||
|| read_local_crates(sess, &cstore, &defs, &krate, crate_name, &sess.dep_graph));
|
||||
// Collect defintions for def ids.
|
||||
time(sess.time_passes(), "collecting defs", || resolver.definitions.collect(&krate));
|
||||
|
||||
time(sess.time_passes(), "external crate/lib resolution", || {
|
||||
let defs = &resolver.definitions;
|
||||
read_local_crates(sess, &cstore, defs, &krate, crate_name, &sess.dep_graph)
|
||||
});
|
||||
|
||||
time(sess.time_passes(),
|
||||
"early lint checks",
|
||||
@ -742,9 +745,6 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
|
||||
"AST validation",
|
||||
|| ast_validation::check_crate(sess, &krate));
|
||||
|
||||
let resolver_arenas = Resolver::arenas();
|
||||
let mut resolver = Resolver::new(sess, defs, make_glob_map, &resolver_arenas);
|
||||
|
||||
time(sess.time_passes(), "name resolution", || {
|
||||
resolver.resolve_crate(&krate);
|
||||
});
|
||||
|
@ -47,7 +47,7 @@ use rustc::hir::{self, PrimTy, TyBool, TyChar, TyFloat, TyInt, TyUint, TyStr};
|
||||
use rustc::session::Session;
|
||||
use rustc::lint;
|
||||
use rustc::hir::def::*;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::ty;
|
||||
use rustc::ty::subst::{ParamSpace, FnSpace, TypeSpace};
|
||||
use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap};
|
||||
@ -1100,12 +1100,9 @@ impl Named for hir::PathSegment {
|
||||
}
|
||||
|
||||
impl<'a> Resolver<'a> {
|
||||
pub fn new(session: &'a Session,
|
||||
definitions: Definitions,
|
||||
make_glob_map: MakeGlobMap,
|
||||
arenas: &'a ResolverArenas<'a>)
|
||||
pub fn new(session: &'a Session, make_glob_map: MakeGlobMap, arenas: &'a ResolverArenas<'a>)
|
||||
-> Resolver<'a> {
|
||||
let root_def_id = definitions.local_def_id(CRATE_NODE_ID);
|
||||
let root_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||
let graph_root =
|
||||
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
|
||||
let graph_root = arenas.alloc_module(graph_root);
|
||||
@ -1115,7 +1112,7 @@ impl<'a> Resolver<'a> {
|
||||
Resolver {
|
||||
session: session,
|
||||
|
||||
definitions: definitions,
|
||||
definitions: Definitions::new(),
|
||||
|
||||
// The outermost module has def ID 0; this is not reflected in the
|
||||
// AST.
|
||||
|
Loading…
Reference in New Issue
Block a user