Refactor away the field arenas
of ModuleS
.
This commit is contained in:
parent
bfc98f59a4
commit
75c3fd89d4
@ -765,17 +765,12 @@ pub struct ModuleS<'a> {
|
||||
// access the children must be preceded with a
|
||||
// `populate_module_if_necessary` call.
|
||||
populated: Cell<bool>,
|
||||
|
||||
arenas: &'a ResolverArenas<'a>,
|
||||
}
|
||||
|
||||
pub type Module<'a> = &'a ModuleS<'a>;
|
||||
|
||||
impl<'a> ModuleS<'a> {
|
||||
fn new(parent_link: ParentLink<'a>,
|
||||
def: Option<Def>,
|
||||
external: bool,
|
||||
arenas: &'a ResolverArenas<'a>) -> Self {
|
||||
fn new(parent_link: ParentLink<'a>, def: Option<Def>, external: bool) -> Self {
|
||||
ModuleS {
|
||||
parent_link: parent_link,
|
||||
def: def,
|
||||
@ -786,7 +781,6 @@ impl<'a> ModuleS<'a> {
|
||||
globs: RefCell::new((Vec::new())),
|
||||
traits: RefCell::new(None),
|
||||
populated: Cell::new(!external),
|
||||
arenas: arenas
|
||||
}
|
||||
}
|
||||
|
||||
@ -1136,7 +1130,7 @@ impl<'a> Resolver<'a> {
|
||||
-> Resolver<'a> {
|
||||
let root_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||
let graph_root =
|
||||
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
|
||||
ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false);
|
||||
let graph_root = arenas.alloc_module(graph_root);
|
||||
let mut module_map = NodeMap();
|
||||
module_map.insert(CRATE_NODE_ID, graph_root);
|
||||
@ -1211,12 +1205,12 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
|
||||
-> Module<'a> {
|
||||
self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
|
||||
self.arenas.alloc_module(ModuleS::new(parent_link, def, external))
|
||||
}
|
||||
|
||||
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
|
||||
-> Module<'a> {
|
||||
let mut module = ModuleS::new(parent_link, Some(def), false, self.arenas);
|
||||
let mut module = ModuleS::new(parent_link, Some(def), false);
|
||||
module.extern_crate_id = Some(local_node_id);
|
||||
self.arenas.modules.alloc(module)
|
||||
}
|
||||
|
@ -135,14 +135,13 @@ impl<'a> NameResolution<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ::ModuleS<'a> {
|
||||
fn resolution(&self, name: Name, ns: Namespace) -> &'a RefCell<NameResolution<'a>> {
|
||||
*self.resolutions.borrow_mut().entry((name, ns))
|
||||
.or_insert_with(|| self.arenas.alloc_name_resolution())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Resolver<'a> {
|
||||
fn resolution(&self, module: Module<'a>, name: Name, ns: Namespace)
|
||||
-> &'a RefCell<NameResolution<'a>> {
|
||||
*module.resolutions.borrow_mut().entry((name, ns))
|
||||
.or_insert_with(|| self.arenas.alloc_name_resolution())
|
||||
}
|
||||
|
||||
/// Attempts to resolve the supplied name in the given module for the given namespace.
|
||||
/// If successful, returns the binding corresponding to the name.
|
||||
pub fn resolve_name_in_module(&mut self,
|
||||
@ -154,7 +153,7 @@ impl<'a> Resolver<'a> {
|
||||
-> ResolveResult<&'a NameBinding<'a>> {
|
||||
self.populate_module_if_necessary(module);
|
||||
|
||||
let resolution = module.resolution(name, ns);
|
||||
let resolution = self.resolution(module, name, ns);
|
||||
let resolution = match resolution.borrow_state() {
|
||||
::std::cell::BorrowState::Unused => resolution.borrow_mut(),
|
||||
_ => return Failed(None), // This happens when there is a cycle of imports
|
||||
@ -240,8 +239,9 @@ impl<'a> Resolver<'a> {
|
||||
span: Span,
|
||||
id: NodeId,
|
||||
vis: ty::Visibility) {
|
||||
let current_module = self.current_module;
|
||||
let directive = self.arenas.alloc_import_directive(ImportDirective {
|
||||
parent: self.current_module,
|
||||
parent: current_module,
|
||||
module_path: module_path,
|
||||
target_module: Cell::new(None),
|
||||
subclass: subclass,
|
||||
@ -254,7 +254,7 @@ impl<'a> Resolver<'a> {
|
||||
match directive.subclass {
|
||||
SingleImport { target, .. } => {
|
||||
for &ns in &[ValueNS, TypeNS] {
|
||||
let mut resolution = self.current_module.resolution(target, ns).borrow_mut();
|
||||
let mut resolution = self.resolution(current_module, target, ns).borrow_mut();
|
||||
resolution.single_imports.add_directive(directive);
|
||||
}
|
||||
}
|
||||
@ -311,7 +311,7 @@ impl<'a> Resolver<'a> {
|
||||
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
|
||||
// during which the resolution might end up getting re-defined via a glob cycle.
|
||||
let (new_binding, t) = {
|
||||
let mut resolution = &mut *module.resolution(name, ns).borrow_mut();
|
||||
let mut resolution = &mut *self.resolution(module, name, ns).borrow_mut();
|
||||
let was_known = resolution.binding().is_some();
|
||||
|
||||
let t = f(self, resolution);
|
||||
|
Loading…
Reference in New Issue
Block a user