groundwork: refactor the interface that resolve
exposes to driver
This commit is contained in:
parent
36a4eb9940
commit
ec0c150152
@ -8,7 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use rustc::dep_graph::DepGraph;
|
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use rustc::hir::{map as hir_map, FreevarMap, TraitMap};
|
use rustc::hir::{map as hir_map, FreevarMap, TraitMap};
|
||||||
use rustc::hir::def::DefMap;
|
use rustc::hir::def::DefMap;
|
||||||
@ -27,7 +26,7 @@ use rustc::util::nodemap::NodeSet;
|
|||||||
use rustc_back::sha2::{Sha256, Digest};
|
use rustc_back::sha2::{Sha256, Digest};
|
||||||
use rustc_borrowck as borrowck;
|
use rustc_borrowck as borrowck;
|
||||||
use rustc_incremental;
|
use rustc_incremental;
|
||||||
use rustc_resolve as resolve;
|
use rustc_resolve::{MakeGlobMap, Resolver};
|
||||||
use rustc_metadata::macro_import;
|
use rustc_metadata::macro_import;
|
||||||
use rustc_metadata::creader::read_local_crates;
|
use rustc_metadata::creader::read_local_crates;
|
||||||
use rustc_metadata::cstore::CStore;
|
use rustc_metadata::cstore::CStore;
|
||||||
@ -291,7 +290,7 @@ pub struct CompileController<'a> {
|
|||||||
pub after_analysis: PhaseController<'a>,
|
pub after_analysis: PhaseController<'a>,
|
||||||
pub after_llvm: PhaseController<'a>,
|
pub after_llvm: PhaseController<'a>,
|
||||||
|
|
||||||
pub make_glob_map: resolve::MakeGlobMap,
|
pub make_glob_map: MakeGlobMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CompileController<'a> {
|
impl<'a> CompileController<'a> {
|
||||||
@ -303,7 +302,7 @@ impl<'a> CompileController<'a> {
|
|||||||
after_hir_lowering: PhaseController::basic(),
|
after_hir_lowering: PhaseController::basic(),
|
||||||
after_analysis: PhaseController::basic(),
|
after_analysis: PhaseController::basic(),
|
||||||
after_llvm: PhaseController::basic(),
|
after_llvm: PhaseController::basic(),
|
||||||
make_glob_map: resolve::MakeGlobMap::No,
|
make_glob_map: MakeGlobMap::No,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -562,7 +561,7 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
|
|||||||
mut krate: ast::Crate,
|
mut krate: ast::Crate,
|
||||||
crate_name: &'a str,
|
crate_name: &'a str,
|
||||||
addl_plugins: Option<Vec<String>>,
|
addl_plugins: Option<Vec<String>>,
|
||||||
make_glob_map: resolve::MakeGlobMap)
|
make_glob_map: MakeGlobMap)
|
||||||
-> Result<ExpansionResult<'a>, usize> {
|
-> Result<ExpansionResult<'a>, usize> {
|
||||||
let time_passes = sess.time_passes();
|
let time_passes = sess.time_passes();
|
||||||
|
|
||||||
@ -728,7 +727,7 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
|
|||||||
krate = assign_node_ids(sess, krate);
|
krate = assign_node_ids(sess, krate);
|
||||||
|
|
||||||
// Collect defintions for def ids.
|
// Collect defintions for def ids.
|
||||||
let mut defs =
|
let defs =
|
||||||
time(sess.time_passes(), "collecting defs", || hir_map::collect_definitions(&krate));
|
time(sess.time_passes(), "collecting defs", || hir_map::collect_definitions(&krate));
|
||||||
|
|
||||||
time(sess.time_passes(),
|
time(sess.time_passes(),
|
||||||
@ -743,8 +742,17 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
|
|||||||
"AST validation",
|
"AST validation",
|
||||||
|| ast_validation::check_crate(sess, &krate));
|
|| ast_validation::check_crate(sess, &krate));
|
||||||
|
|
||||||
let (analysis, resolutions, hir_forest) =
|
let resolver_arenas = Resolver::arenas();
|
||||||
lower_and_resolve(sess, crate_name, &mut defs, &krate, &sess.dep_graph, make_glob_map);
|
let mut resolver = Resolver::new(sess, defs, make_glob_map, &resolver_arenas);
|
||||||
|
|
||||||
|
time(sess.time_passes(), "name resolution", || {
|
||||||
|
resolver.resolve_crate(&krate);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Lower ast -> hir.
|
||||||
|
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {
|
||||||
|
hir_map::Forest::new(lower_crate(sess, &krate, &mut resolver), &sess.dep_graph)
|
||||||
|
});
|
||||||
|
|
||||||
// Discard MTWT tables that aren't required past lowering to HIR.
|
// Discard MTWT tables that aren't required past lowering to HIR.
|
||||||
if !keep_mtwt_tables(sess) {
|
if !keep_mtwt_tables(sess) {
|
||||||
@ -753,9 +761,20 @@ pub fn phase_2_configure_and_expand<'a>(sess: &Session,
|
|||||||
|
|
||||||
Ok(ExpansionResult {
|
Ok(ExpansionResult {
|
||||||
expanded_crate: krate,
|
expanded_crate: krate,
|
||||||
defs: defs,
|
defs: resolver.definitions,
|
||||||
analysis: analysis,
|
analysis: ty::CrateAnalysis {
|
||||||
resolutions: resolutions,
|
export_map: resolver.export_map,
|
||||||
|
access_levels: AccessLevels::default(),
|
||||||
|
reachable: NodeSet(),
|
||||||
|
name: crate_name,
|
||||||
|
glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None },
|
||||||
|
},
|
||||||
|
resolutions: Resolutions {
|
||||||
|
def_map: resolver.def_map,
|
||||||
|
freevars: resolver.freevars,
|
||||||
|
trait_map: resolver.trait_map,
|
||||||
|
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
|
||||||
|
},
|
||||||
hir_forest: hir_forest
|
hir_forest: hir_forest
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -807,38 +826,6 @@ pub fn assign_node_ids(sess: &Session, krate: ast::Crate) -> ast::Crate {
|
|||||||
krate
|
krate
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lower_and_resolve<'a>(sess: &Session,
|
|
||||||
id: &'a str,
|
|
||||||
defs: &mut hir_map::Definitions,
|
|
||||||
krate: &ast::Crate,
|
|
||||||
dep_graph: &DepGraph,
|
|
||||||
make_glob_map: resolve::MakeGlobMap)
|
|
||||||
-> (ty::CrateAnalysis<'a>, Resolutions, hir_map::Forest) {
|
|
||||||
resolve::with_resolver(sess, defs, make_glob_map, |mut resolver| {
|
|
||||||
time(sess.time_passes(), "name resolution", || {
|
|
||||||
resolve::resolve_crate(&mut resolver, krate);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Lower ast -> hir.
|
|
||||||
let hir_forest = time(sess.time_passes(), "lowering ast -> hir", || {
|
|
||||||
hir_map::Forest::new(lower_crate(sess, krate, &mut resolver), dep_graph)
|
|
||||||
});
|
|
||||||
|
|
||||||
(ty::CrateAnalysis {
|
|
||||||
export_map: resolver.export_map,
|
|
||||||
access_levels: AccessLevels::default(),
|
|
||||||
reachable: NodeSet(),
|
|
||||||
name: &id,
|
|
||||||
glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None },
|
|
||||||
}, Resolutions {
|
|
||||||
def_map: resolver.def_map,
|
|
||||||
freevars: resolver.freevars,
|
|
||||||
trait_map: resolver.trait_map,
|
|
||||||
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
|
|
||||||
}, hir_forest)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run the resolution, typechecking, region checking and other
|
/// Run the resolution, typechecking, region checking and other
|
||||||
/// miscellaneous analysis passes on the crate. Return various
|
/// miscellaneous analysis passes on the crate. Return various
|
||||||
/// structures carrying the results of the analysis.
|
/// structures carrying the results of the analysis.
|
||||||
|
@ -925,7 +925,7 @@ impl PrimitiveTypeTable {
|
|||||||
pub struct Resolver<'a> {
|
pub struct Resolver<'a> {
|
||||||
session: &'a Session,
|
session: &'a Session,
|
||||||
|
|
||||||
definitions: &'a mut Definitions,
|
pub definitions: Definitions,
|
||||||
|
|
||||||
graph_root: Module<'a>,
|
graph_root: Module<'a>,
|
||||||
|
|
||||||
@ -1001,7 +1001,7 @@ pub struct Resolver<'a> {
|
|||||||
arenas: &'a ResolverArenas<'a>,
|
arenas: &'a ResolverArenas<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ResolverArenas<'a> {
|
pub struct ResolverArenas<'a> {
|
||||||
modules: arena::TypedArena<ModuleS<'a>>,
|
modules: arena::TypedArena<ModuleS<'a>>,
|
||||||
local_modules: RefCell<Vec<Module<'a>>>,
|
local_modules: RefCell<Vec<Module<'a>>>,
|
||||||
name_bindings: arena::TypedArena<NameBinding<'a>>,
|
name_bindings: arena::TypedArena<NameBinding<'a>>,
|
||||||
@ -1079,7 +1079,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn definitions(&mut self) -> Option<&mut Definitions> {
|
fn definitions(&mut self) -> Option<&mut Definitions> {
|
||||||
Some(self.definitions)
|
Some(&mut self.definitions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1100,11 +1100,11 @@ impl Named for hir::PathSegment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Resolver<'a> {
|
impl<'a> Resolver<'a> {
|
||||||
fn new(session: &'a Session,
|
pub fn new(session: &'a Session,
|
||||||
definitions: &'a mut Definitions,
|
definitions: Definitions,
|
||||||
make_glob_map: MakeGlobMap,
|
make_glob_map: MakeGlobMap,
|
||||||
arenas: &'a ResolverArenas<'a>)
|
arenas: &'a ResolverArenas<'a>)
|
||||||
-> Resolver<'a> {
|
-> Resolver<'a> {
|
||||||
let root_def_id = definitions.local_def_id(CRATE_NODE_ID);
|
let root_def_id = definitions.local_def_id(CRATE_NODE_ID);
|
||||||
let graph_root =
|
let graph_root =
|
||||||
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
|
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
|
||||||
@ -1158,7 +1158,7 @@ impl<'a> Resolver<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn arenas() -> ResolverArenas<'a> {
|
pub fn arenas() -> ResolverArenas<'a> {
|
||||||
ResolverArenas {
|
ResolverArenas {
|
||||||
modules: arena::TypedArena::new(),
|
modules: arena::TypedArena::new(),
|
||||||
local_modules: RefCell::new(Vec::new()),
|
local_modules: RefCell::new(Vec::new()),
|
||||||
@ -1168,6 +1168,27 @@ impl<'a> Resolver<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Entry point to crate resolution.
|
||||||
|
pub fn resolve_crate(&mut self, krate: &Crate) {
|
||||||
|
// Currently, we ignore the name resolution data structures for
|
||||||
|
// the purposes of dependency tracking. Instead we will run name
|
||||||
|
// resolution and include its output in the hash of each item,
|
||||||
|
// much like we do for macro expansion. In other words, the hash
|
||||||
|
// reflects not just its contents but the results of name
|
||||||
|
// resolution on those contents. Hopefully we'll push this back at
|
||||||
|
// some point.
|
||||||
|
let _ignore = self.session.dep_graph.in_ignore();
|
||||||
|
|
||||||
|
self.build_reduced_graph(krate);
|
||||||
|
resolve_imports::resolve_imports(self);
|
||||||
|
|
||||||
|
self.current_module = self.graph_root;
|
||||||
|
visit::walk_crate(self, krate);
|
||||||
|
|
||||||
|
check_unused::check_crate(self, krate);
|
||||||
|
self.report_privacy_errors();
|
||||||
|
}
|
||||||
|
|
||||||
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
|
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
|
||||||
-> Module<'a> {
|
-> Module<'a> {
|
||||||
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
|
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
|
||||||
@ -1568,12 +1589,6 @@ impl<'a> Resolver<'a> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_crate(&mut self, krate: &Crate) {
|
|
||||||
debug!("(resolving crate) starting");
|
|
||||||
self.current_module = self.graph_root;
|
|
||||||
visit::walk_crate(self, krate);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn resolve_item(&mut self, item: &Item) {
|
fn resolve_item(&mut self, item: &Item) {
|
||||||
let name = item.ident.name;
|
let name = item.ident.name;
|
||||||
|
|
||||||
@ -3455,34 +3470,4 @@ pub enum MakeGlobMap {
|
|||||||
No,
|
No,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Entry point to crate resolution.
|
|
||||||
pub fn resolve_crate<'a, 'b>(resolver: &'b mut Resolver<'a>, krate: &'b Crate) {
|
|
||||||
// Currently, we ignore the name resolution data structures for
|
|
||||||
// the purposes of dependency tracking. Instead we will run name
|
|
||||||
// resolution and include its output in the hash of each item,
|
|
||||||
// much like we do for macro expansion. In other words, the hash
|
|
||||||
// reflects not just its contents but the results of name
|
|
||||||
// resolution on those contents. Hopefully we'll push this back at
|
|
||||||
// some point.
|
|
||||||
let _ignore = resolver.session.dep_graph.in_ignore();
|
|
||||||
|
|
||||||
resolver.build_reduced_graph(krate);
|
|
||||||
resolve_imports::resolve_imports(resolver);
|
|
||||||
resolver.resolve_crate(krate);
|
|
||||||
|
|
||||||
check_unused::check_crate(resolver, krate);
|
|
||||||
resolver.report_privacy_errors();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_resolver<'a, T, F>(session: &'a Session,
|
|
||||||
definitions: &'a mut Definitions,
|
|
||||||
make_glob_map: MakeGlobMap,
|
|
||||||
f: F) -> T
|
|
||||||
where F: for<'b> FnOnce(Resolver<'b>) -> T,
|
|
||||||
{
|
|
||||||
let arenas = Resolver::arenas();
|
|
||||||
let resolver = Resolver::new(session, definitions, make_glob_map, &arenas);
|
|
||||||
f(resolver)
|
|
||||||
}
|
|
||||||
|
|
||||||
__build_diagnostic_array! { librustc_resolve, DIAGNOSTICS }
|
__build_diagnostic_array! { librustc_resolve, DIAGNOSTICS }
|
||||||
|
Loading…
Reference in New Issue
Block a user