Refactor away the field arenas
of ModuleS
.
This commit is contained in:
parent
bfc98f59a4
commit
75c3fd89d4
2 changed files with 15 additions and 21 deletions
|
@ -765,17 +765,12 @@ pub struct ModuleS<'a> {
|
||||||
// access the children must be preceded with a
|
// access the children must be preceded with a
|
||||||
// `populate_module_if_necessary` call.
|
// `populate_module_if_necessary` call.
|
||||||
populated: Cell<bool>,
|
populated: Cell<bool>,
|
||||||
|
|
||||||
arenas: &'a ResolverArenas<'a>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Module<'a> = &'a ModuleS<'a>;
|
pub type Module<'a> = &'a ModuleS<'a>;
|
||||||
|
|
||||||
impl<'a> ModuleS<'a> {
|
impl<'a> ModuleS<'a> {
|
||||||
fn new(parent_link: ParentLink<'a>,
|
fn new(parent_link: ParentLink<'a>, def: Option<Def>, external: bool) -> Self {
|
||||||
def: Option<Def>,
|
|
||||||
external: bool,
|
|
||||||
arenas: &'a ResolverArenas<'a>) -> Self {
|
|
||||||
ModuleS {
|
ModuleS {
|
||||||
parent_link: parent_link,
|
parent_link: parent_link,
|
||||||
def: def,
|
def: def,
|
||||||
|
@ -786,7 +781,6 @@ impl<'a> ModuleS<'a> {
|
||||||
globs: RefCell::new((Vec::new())),
|
globs: RefCell::new((Vec::new())),
|
||||||
traits: RefCell::new(None),
|
traits: RefCell::new(None),
|
||||||
populated: Cell::new(!external),
|
populated: Cell::new(!external),
|
||||||
arenas: arenas
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1136,7 +1130,7 @@ impl<'a> Resolver<'a> {
|
||||||
-> Resolver<'a> {
|
-> Resolver<'a> {
|
||||||
let root_def_id = DefId::local(CRATE_DEF_INDEX);
|
let root_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||||
let graph_root =
|
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 graph_root = arenas.alloc_module(graph_root);
|
||||||
let mut module_map = NodeMap();
|
let mut module_map = NodeMap();
|
||||||
module_map.insert(CRATE_NODE_ID, graph_root);
|
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)
|
fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
|
||||||
-> Module<'a> {
|
-> 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)
|
fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
|
||||||
-> Module<'a> {
|
-> 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);
|
module.extern_crate_id = Some(local_node_id);
|
||||||
self.arenas.modules.alloc(module)
|
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> {
|
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.
|
/// Attempts to resolve the supplied name in the given module for the given namespace.
|
||||||
/// If successful, returns the binding corresponding to the name.
|
/// If successful, returns the binding corresponding to the name.
|
||||||
pub fn resolve_name_in_module(&mut self,
|
pub fn resolve_name_in_module(&mut self,
|
||||||
|
@ -154,7 +153,7 @@ impl<'a> Resolver<'a> {
|
||||||
-> ResolveResult<&'a NameBinding<'a>> {
|
-> ResolveResult<&'a NameBinding<'a>> {
|
||||||
self.populate_module_if_necessary(module);
|
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() {
|
let resolution = match resolution.borrow_state() {
|
||||||
::std::cell::BorrowState::Unused => resolution.borrow_mut(),
|
::std::cell::BorrowState::Unused => resolution.borrow_mut(),
|
||||||
_ => return Failed(None), // This happens when there is a cycle of imports
|
_ => return Failed(None), // This happens when there is a cycle of imports
|
||||||
|
@ -240,8 +239,9 @@ impl<'a> Resolver<'a> {
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
vis: ty::Visibility) {
|
vis: ty::Visibility) {
|
||||||
|
let current_module = self.current_module;
|
||||||
let directive = self.arenas.alloc_import_directive(ImportDirective {
|
let directive = self.arenas.alloc_import_directive(ImportDirective {
|
||||||
parent: self.current_module,
|
parent: current_module,
|
||||||
module_path: module_path,
|
module_path: module_path,
|
||||||
target_module: Cell::new(None),
|
target_module: Cell::new(None),
|
||||||
subclass: subclass,
|
subclass: subclass,
|
||||||
|
@ -254,7 +254,7 @@ impl<'a> Resolver<'a> {
|
||||||
match directive.subclass {
|
match directive.subclass {
|
||||||
SingleImport { target, .. } => {
|
SingleImport { target, .. } => {
|
||||||
for &ns in &[ValueNS, TypeNS] {
|
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);
|
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,
|
// 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.
|
// during which the resolution might end up getting re-defined via a glob cycle.
|
||||||
let (new_binding, t) = {
|
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 was_known = resolution.binding().is_some();
|
||||||
|
|
||||||
let t = f(self, resolution);
|
let t = f(self, resolution);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue