diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-04-17 20:41:57 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-04-17 23:48:13 +0000 |
| commit | b01e63009fdae72b2bb2ca1892ef55eede8d80dc (patch) | |
| tree | 20b6cf646378d342832f793ef04886b3627d1ca6 | |
| parent | 5b12832012c4d92296889d03737f0705ac2d5698 (diff) | |
| download | rust-b01e63009fdae72b2bb2ca1892ef55eede8d80dc.tar.gz rust-b01e63009fdae72b2bb2ca1892ef55eede8d80dc.zip | |
Refactor the per-module node map `module_children` into a per-resolver map.
| -rw-r--r-- | src/librustc_resolve/build_reduced_graph.rs | 4 | ||||
| -rw-r--r-- | src/librustc_resolve/lib.rs | 40 |
2 files changed, 22 insertions, 22 deletions
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 51d00266b71..effc751c507 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -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; } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index cf302886f11..d5e0d35950f 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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"); |
