Refactor no_implicit_prelude: Cell<bool>
-> no_implicit_prelude: bool
.
This commit is contained in:
parent
85bfd82be6
commit
272cf4e61d
@ -643,7 +643,8 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
|
||||
macro_import::MacroLoader::new(sess, &cstore, crate_name, krate.config.clone());
|
||||
|
||||
let resolver_arenas = Resolver::arenas();
|
||||
let mut resolver = Resolver::new(sess, make_glob_map, &mut macro_loader, &resolver_arenas);
|
||||
let mut resolver =
|
||||
Resolver::new(sess, &krate, make_glob_map, &mut macro_loader, &resolver_arenas);
|
||||
syntax_ext::register_builtins(&mut resolver, sess.features.borrow().quote);
|
||||
|
||||
krate = time(time_passes, "expansion", || {
|
||||
|
@ -14,7 +14,7 @@
|
||||
//! any imports resolved.
|
||||
|
||||
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport};
|
||||
use {Module, ModuleKind};
|
||||
use {Module, ModuleS, ModuleKind};
|
||||
use Namespace::{self, TypeNS, ValueNS};
|
||||
use {NameBinding, NameBindingKind, ToNameBinding};
|
||||
use Resolver;
|
||||
@ -55,8 +55,6 @@ impl<'a> ToNameBinding<'a> for (Def, Span, ty::Visibility) {
|
||||
impl<'b> Resolver<'b> {
|
||||
/// Constructs the reduced graph for the entire crate.
|
||||
pub fn build_reduced_graph(&mut self, krate: &Crate) {
|
||||
let no_implicit_prelude = attr::contains_name(&krate.attrs, "no_implicit_prelude");
|
||||
self.graph_root.no_implicit_prelude.set(no_implicit_prelude);
|
||||
visit::walk_crate(&mut BuildReducedGraphVisitor { resolver: self }, krate);
|
||||
}
|
||||
|
||||
@ -195,8 +193,11 @@ impl<'b> Resolver<'b> {
|
||||
krate: crate_id,
|
||||
index: CRATE_DEF_INDEX,
|
||||
};
|
||||
let def = Def::Mod(def_id);
|
||||
let module = self.new_extern_crate_module(parent, name, def, item.id);
|
||||
let module = self.arenas.alloc_module(ModuleS {
|
||||
extern_crate_id: Some(item.id),
|
||||
populated: Cell::new(false),
|
||||
..ModuleS::new(Some(parent), ModuleKind::Def(Def::Mod(def_id), name))
|
||||
});
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
|
||||
self.populate_module_if_necessary(module);
|
||||
@ -205,10 +206,12 @@ impl<'b> Resolver<'b> {
|
||||
|
||||
ItemKind::Mod(..) => {
|
||||
let def = Def::Mod(self.definitions.local_def_id(item.id));
|
||||
let module = self.new_module(parent, ModuleKind::Def(def, name), Some(item.id));
|
||||
module.no_implicit_prelude.set({
|
||||
parent.no_implicit_prelude.get() ||
|
||||
let module = self.arenas.alloc_module(ModuleS {
|
||||
no_implicit_prelude: parent.no_implicit_prelude || {
|
||||
attr::contains_name(&item.attrs, "no_implicit_prelude")
|
||||
},
|
||||
normal_ancestor_id: Some(item.id),
|
||||
..ModuleS::new(Some(parent), ModuleKind::Def(def, name))
|
||||
});
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
self.module_map.insert(item.id, module);
|
||||
@ -241,8 +244,8 @@ impl<'b> Resolver<'b> {
|
||||
}
|
||||
|
||||
ItemKind::Enum(ref enum_definition, _) => {
|
||||
let kind = ModuleKind::Def(Def::Enum(self.definitions.local_def_id(item.id)), name);
|
||||
let module = self.new_module(parent, kind, parent.normal_ancestor_id);
|
||||
let def = Def::Enum(self.definitions.local_def_id(item.id));
|
||||
let module = self.new_module(parent, ModuleKind::Def(def, name), true);
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
|
||||
for variant in &(*enum_definition).variants {
|
||||
@ -293,8 +296,8 @@ impl<'b> Resolver<'b> {
|
||||
let def_id = self.definitions.local_def_id(item.id);
|
||||
|
||||
// Add all the items within to a new module.
|
||||
let kind = ModuleKind::Def(Def::Trait(def_id), name);
|
||||
let module = self.new_module(parent, kind, parent.normal_ancestor_id);
|
||||
let module =
|
||||
self.new_module(parent, ModuleKind::Def(Def::Trait(def_id), name), true);
|
||||
self.define(parent, name, TypeNS, (module, sp, vis));
|
||||
self.current_module = module;
|
||||
}
|
||||
@ -348,8 +351,7 @@ impl<'b> Resolver<'b> {
|
||||
{}",
|
||||
block_id);
|
||||
|
||||
let new_module =
|
||||
self.new_module(parent, ModuleKind::Block(block_id), parent.normal_ancestor_id);
|
||||
let new_module = self.new_module(parent, ModuleKind::Block(block_id), true);
|
||||
self.module_map.insert(block_id, new_module);
|
||||
self.current_module = new_module; // Descend into the block.
|
||||
}
|
||||
@ -377,7 +379,7 @@ impl<'b> Resolver<'b> {
|
||||
Def::Mod(_) | Def::Enum(..) => {
|
||||
debug!("(building reduced graph for external crate) building module {} {:?}",
|
||||
name, vis);
|
||||
let module = self.new_module(parent, ModuleKind::Def(def, name), None);
|
||||
let module = self.new_module(parent, ModuleKind::Def(def, name), false);
|
||||
let _ = self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
|
||||
}
|
||||
Def::Variant(variant_id) => {
|
||||
@ -420,7 +422,7 @@ impl<'b> Resolver<'b> {
|
||||
self.trait_item_map.insert((trait_item_name, def_id), false);
|
||||
}
|
||||
|
||||
let module = self.new_module(parent, ModuleKind::Def(def, name), None);
|
||||
let module = self.new_module(parent, ModuleKind::Def(def, name), false);
|
||||
let _ = self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
|
||||
}
|
||||
Def::TyAlias(..) | Def::AssociatedTy(..) => {
|
||||
|
@ -60,6 +60,7 @@ use syntax::parse::token::{self, keywords};
|
||||
use syntax::util::lev_distance::find_best_match_for_name;
|
||||
|
||||
use syntax::visit::{self, FnKind, Visitor};
|
||||
use syntax::attr;
|
||||
use syntax::ast::{Arm, BindingMode, Block, Crate, Expr, ExprKind};
|
||||
use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, Generics};
|
||||
use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
|
||||
@ -771,7 +772,7 @@ pub struct ModuleS<'a> {
|
||||
|
||||
resolutions: RefCell<FnvHashMap<(Name, Namespace), &'a RefCell<NameResolution<'a>>>>,
|
||||
|
||||
no_implicit_prelude: Cell<bool>,
|
||||
no_implicit_prelude: bool,
|
||||
|
||||
glob_importers: RefCell<Vec<&'a ImportDirective<'a>>>,
|
||||
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
|
||||
@ -788,19 +789,18 @@ pub struct ModuleS<'a> {
|
||||
pub type Module<'a> = &'a ModuleS<'a>;
|
||||
|
||||
impl<'a> ModuleS<'a> {
|
||||
fn new(parent: Option<Module<'a>>, kind: ModuleKind, normal_ancestor_id: Option<NodeId>)
|
||||
-> Self {
|
||||
fn new(parent: Option<Module<'a>>, kind: ModuleKind) -> Self {
|
||||
ModuleS {
|
||||
parent: parent,
|
||||
kind: kind,
|
||||
normal_ancestor_id: normal_ancestor_id,
|
||||
normal_ancestor_id: None,
|
||||
extern_crate_id: None,
|
||||
resolutions: RefCell::new(FnvHashMap()),
|
||||
no_implicit_prelude: Cell::new(false),
|
||||
no_implicit_prelude: false,
|
||||
glob_importers: RefCell::new(Vec::new()),
|
||||
globs: RefCell::new((Vec::new())),
|
||||
traits: RefCell::new(None),
|
||||
populated: Cell::new(normal_ancestor_id.is_some()),
|
||||
populated: Cell::new(true),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1170,14 +1170,17 @@ impl Named for hir::PathSegment {
|
||||
|
||||
impl<'a> Resolver<'a> {
|
||||
pub fn new(session: &'a Session,
|
||||
krate: &Crate,
|
||||
make_glob_map: MakeGlobMap,
|
||||
macro_loader: &'a mut MacroLoader,
|
||||
arenas: &'a ResolverArenas<'a>)
|
||||
-> Resolver<'a> {
|
||||
let graph_root_kind =
|
||||
ModuleKind::Def(Def::Mod(DefId::local(CRATE_DEF_INDEX)), keywords::Invalid.name());
|
||||
let graph_root =
|
||||
arenas.alloc_module(ModuleS::new(None, graph_root_kind, Some(CRATE_NODE_ID)));
|
||||
let root_def = Def::Mod(DefId::local(CRATE_DEF_INDEX));
|
||||
let graph_root = arenas.alloc_module(ModuleS {
|
||||
normal_ancestor_id: Some(CRATE_NODE_ID),
|
||||
no_implicit_prelude: attr::contains_name(&krate.attrs, "no_implicit_prelude"),
|
||||
..ModuleS::new(None, ModuleKind::Def(root_def, keywords::Invalid.name()))
|
||||
});
|
||||
let mut module_map = NodeMap();
|
||||
module_map.insert(CRATE_NODE_ID, graph_root);
|
||||
|
||||
@ -1259,17 +1262,12 @@ impl<'a> Resolver<'a> {
|
||||
self.report_errors();
|
||||
}
|
||||
|
||||
fn new_module(&self, parent: Module<'a>, kind: ModuleKind, normal_ancestor_id: Option<NodeId>)
|
||||
-> Module<'a> {
|
||||
self.arenas.alloc_module(ModuleS::new(Some(parent), kind, normal_ancestor_id))
|
||||
}
|
||||
|
||||
fn new_extern_crate_module(&self, parent: Module<'a>, name: Name, def: Def, node_id: NodeId)
|
||||
-> Module<'a> {
|
||||
let mut module = ModuleS::new(Some(parent), ModuleKind::Def(def, name), Some(node_id));
|
||||
module.extern_crate_id = Some(node_id);
|
||||
module.populated.set(false);
|
||||
self.arenas.modules.alloc(module)
|
||||
fn new_module(&self, parent: Module<'a>, kind: ModuleKind, local: bool) -> Module<'a> {
|
||||
self.arenas.alloc_module(ModuleS {
|
||||
normal_ancestor_id: if local { self.current_module.normal_ancestor_id } else { None },
|
||||
populated: Cell::new(local),
|
||||
..ModuleS::new(Some(parent), kind)
|
||||
})
|
||||
}
|
||||
|
||||
fn get_ribs<'b>(&'b mut self, ns: Namespace) -> &'b mut Vec<Rib<'a>> {
|
||||
@ -1509,7 +1507,7 @@ impl<'a> Resolver<'a> {
|
||||
}
|
||||
|
||||
if let ModuleKind::Block(..) = module.kind { // We can see through blocks
|
||||
} else if !module.no_implicit_prelude.get() {
|
||||
} else if !module.no_implicit_prelude {
|
||||
return self.prelude.and_then(|prelude| {
|
||||
self.resolve_name_in_module(prelude, name, ns, false, None).success()
|
||||
}).map(LexicalScopeBinding::Item)
|
||||
@ -3156,7 +3154,7 @@ impl<'a> Resolver<'a> {
|
||||
if let ModuleKind::Block(..) = search_module.kind {
|
||||
search_module = search_module.parent.unwrap();
|
||||
} else {
|
||||
if !search_module.no_implicit_prelude.get() {
|
||||
if !search_module.no_implicit_prelude {
|
||||
self.prelude.map(|prelude| search_in_module(self, prelude));
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user