提交 b01e6300 编写于 作者: J Jeffrey Seyfried

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

上级 5b128320
......@@ -260,7 +260,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
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 @@ fn build_reduced_graph_for_block(&mut self, block: &Block, parent: &mut Module<'
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;
}
}
......
......@@ -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 @@ fn new(parent_link: ParentLink<'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 @@ fn new(session: &'a Session,
freevars_seen: NodeMap(),
export_map: NodeMap(),
trait_map: NodeMap(),
module_map: NodeMap(),
used_imports: HashSet::new(),
used_crates: HashSet::new(),
......@@ -1578,7 +1578,8 @@ fn resolve_name_in_module(&mut self,
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 @@ fn resolve_block(&mut self, block: &Block) {
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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册