Skip to content

Commit

Permalink
Refactor the per-module node map module_children into a per-resolve…
Browse files Browse the repository at this point in the history
…r map.
  • Loading branch information
jseyfried committed Apr 17, 2016
1 parent 5b12832 commit b01e630
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/librustc_resolve/lib.rs
Expand Up @@ -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>)>>,
Expand Down Expand Up @@ -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())),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),

Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b01e630

Please sign in to comment.