1
Fork 0

Refactor the per-module node map module_children into a per-resolver map.

This commit is contained in:
Jeffrey Seyfried 2016-04-17 20:41:57 +00:00
parent 5b12832012
commit b01e63009f
2 changed files with 22 additions and 22 deletions

View file

@ -260,7 +260,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
let def = Def::Mod(self.ast_map.local_def_id(item.id));
let module = self.new_module(parent_link, Some(def), false, vis);
self.define(parent, name, TypeNS, (module, sp));
parent.module_children.borrow_mut().insert(item.id, module);
self.module_map.insert(item.id, module);
*parent_ref = module;
}
@ -398,7 +398,7 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
let parent_link = BlockParentLink(parent, block_id);
let new_module = self.new_module(parent_link, None, false, parent.vis);
parent.module_children.borrow_mut().insert(block_id, new_module);
self.module_map.insert(block_id, new_module);
*parent = new_module;
}
}

View file

@ -827,22 +827,6 @@ pub struct ModuleS<'a> {
resolutions: RefCell<HashMap<(Name, Namespace), &'a RefCell<NameResolution<'a>>>>,
unresolved_imports: RefCell<Vec<&'a ImportDirective<'a>>>,
// The module children of this node, including normal modules and anonymous modules.
// Anonymous children are pseudo-modules that are implicitly created around items
// contained within blocks.
//
// For example, if we have this:
//
// fn f() {
// fn g() {
// ...
// }
// }
//
// There will be an anonymous module created around `g` with the ID of the
// entry block for `f`.
module_children: RefCell<NodeMap<Module<'a>>>,
prelude: RefCell<Option<Module<'a>>>,
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective<'a>)>>,
@ -871,7 +855,6 @@ impl<'a> ModuleS<'a> {
extern_crate_id: None,
resolutions: RefCell::new(HashMap::new()),
unresolved_imports: RefCell::new(Vec::new()),
module_children: RefCell::new(NodeMap()),
prelude: RefCell::new(None),
glob_importers: RefCell::new(Vec::new()),
globs: RefCell::new((Vec::new())),
@ -1078,6 +1061,22 @@ pub struct Resolver<'a, 'tcx: 'a> {
export_map: ExportMap,
trait_map: TraitMap,
// A map from nodes to modules, both normal (`mod`) modules and anonymous modules.
// Anonymous modules are pseudo-modules that are implicitly created around items
// contained within blocks.
//
// For example, if we have this:
//
// fn f() {
// fn g() {
// ...
// }
// }
//
// There will be an anonymous module created around `g` with the ID of the
// entry block for `f`.
module_map: NodeMap<Module<'a>>,
// Whether or not to print error messages. Can be set to true
// when getting additional info for error message suggestions,
// so as to avoid printing duplicate errors
@ -1179,6 +1178,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
freevars_seen: NodeMap(),
export_map: NodeMap(),
trait_map: NodeMap(),
module_map: NodeMap(),
used_imports: HashSet::new(),
used_crates: HashSet::new(),
@ -1578,7 +1578,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fn with_scope<F>(&mut self, id: NodeId, f: F)
where F: FnOnce(&mut Resolver)
{
if let Some(module) = self.current_module.module_children.borrow().get(&id) {
let module = self.module_map.get(&id).cloned(); // clones a reference
if let Some(module) = module {
// Move down in the graph.
let orig_module = ::std::mem::replace(&mut self.current_module, module);
self.value_ribs.push(Rib::new(ModuleRibKind(module)));
@ -2129,8 +2130,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
debug!("(resolving block) entering block");
// Move down in the graph, if there's an anonymous module rooted here.
let orig_module = self.current_module;
let anonymous_module =
orig_module.module_children.borrow().get(&block.id).map(|module| *module);
let anonymous_module = self.module_map.get(&block.id).cloned(); // clones a reference
if let Some(anonymous_module) = anonymous_module {
debug!("(resolving block) found anonymous module, moving down");