Avoid building multiple reduced graphs for a crate
that is referenced by multiple `extern crate` items.
This commit is contained in:
parent
b0e13dc5ba
commit
624a9b7311
2 changed files with 15 additions and 9 deletions
|
@ -24,7 +24,7 @@ use {resolve_error, resolve_struct_error, ResolutionError};
|
|||
|
||||
use rustc::middle::cstore::LoadedMacros;
|
||||
use rustc::hir::def::*;
|
||||
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId};
|
||||
use rustc::ty;
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
|
||||
|
@ -233,14 +233,7 @@ impl<'b> Resolver<'b> {
|
|||
// n.b. we don't need to look at the path option here, because cstore already did
|
||||
let crate_id = self.session.cstore.extern_mod_stmt_cnum(item.id);
|
||||
let module = if let Some(crate_id) = crate_id {
|
||||
let def_id = DefId {
|
||||
krate: crate_id,
|
||||
index: CRATE_DEF_INDEX,
|
||||
};
|
||||
let module = self.arenas.alloc_module(ModuleS {
|
||||
populated: Cell::new(false),
|
||||
..ModuleS::new(Some(parent), ModuleKind::Def(Def::Mod(def_id), name))
|
||||
});
|
||||
let module = self.get_extern_crate_root(crate_id);
|
||||
let binding = (module, sp, ty::Visibility::Public).to_name_binding();
|
||||
let binding = self.arenas.alloc_name_binding(binding);
|
||||
let directive = self.arenas.alloc_import_directive(ImportDirective {
|
||||
|
@ -504,6 +497,17 @@ impl<'b> Resolver<'b> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_extern_crate_root(&mut self, cnum: CrateNum) -> Module<'b> {
|
||||
let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
|
||||
let arenas = self.arenas;
|
||||
*self.extern_crate_roots.entry(cnum).or_insert_with(|| {
|
||||
arenas.alloc_module(ModuleS {
|
||||
populated: Cell::new(false),
|
||||
..ModuleS::new(None, ModuleKind::Def(Def::Mod(def_id), keywords::Invalid.name()))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Ensures that the reduced graph rooted at the given external module
|
||||
/// is built, building it if it is not.
|
||||
pub fn populate_module_if_necessary(&mut self, module: Module<'b>) {
|
||||
|
|
|
@ -1083,6 +1083,7 @@ pub struct Resolver<'a> {
|
|||
// There will be an anonymous module created around `g` with the ID of the
|
||||
// entry block for `f`.
|
||||
module_map: NodeMap<Module<'a>>,
|
||||
extern_crate_roots: FxHashMap<CrateNum, Module<'a>>,
|
||||
|
||||
// Whether or not to print error messages. Can be set to true
|
||||
// when getting additional info for error message suggestions,
|
||||
|
@ -1276,6 +1277,7 @@ impl<'a> Resolver<'a> {
|
|||
export_map: NodeMap(),
|
||||
trait_map: NodeMap(),
|
||||
module_map: module_map,
|
||||
extern_crate_roots: FxHashMap(),
|
||||
|
||||
emit_errors: true,
|
||||
make_glob_map: make_glob_map == MakeGlobMap::Yes,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue