提交 6b94bc34 编写于 作者: J Jeffrey Seyfried

Add an arena for import directives

上级 064f17c6
......@@ -707,9 +707,10 @@ fn build_import_directive(&mut self,
}
}
module_.unresolved_imports
.borrow_mut()
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
let directive =
ImportDirective::new(module_path, subclass, span, id, is_public, shadowable);
let directive = self.resolver.arenas.alloc_import_directive(directive);
module_.unresolved_imports.borrow_mut().push(directive);
self.unresolved_imports += 1;
}
}
......
......@@ -812,7 +812,7 @@ pub struct ModuleS<'a> {
extern_crate_id: Option<NodeId>,
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
unresolved_imports: RefCell<Vec<ImportDirective>>,
unresolved_imports: RefCell<Vec<&'a ImportDirective>>,
// The module children of this node, including normal modules and anonymous modules.
// Anonymous children are pseudo-modules that are implicitly created around items
......@@ -1167,6 +1167,13 @@ pub struct Resolver<'a, 'tcx: 'a> {
pub struct ResolverArenas<'a> {
modules: arena::TypedArena<ModuleS<'a>>,
name_bindings: arena::TypedArena<NameBinding<'a>>,
import_directives: arena::TypedArena<ImportDirective>,
}
impl<'a> ResolverArenas<'a> {
fn alloc_import_directive(&'a self, import_directive: ImportDirective) -> &'a ImportDirective {
self.import_directives.alloc(import_directive)
}
}
#[derive(PartialEq)]
......@@ -1234,6 +1241,7 @@ fn arenas() -> ResolverArenas<'a> {
ResolverArenas {
modules: arena::TypedArena::new(),
name_bindings: arena::TypedArena::new(),
import_directives: arena::TypedArena::new(),
}
}
......
......@@ -172,7 +172,7 @@ pub fn try_define(&mut self, binding: &'a NameBinding<'a>) -> Result<(), &'a Nam
struct ImportResolvingError<'a> {
/// Module where the error happened
source_module: Module<'a>,
import_directive: ImportDirective,
import_directive: &'a ImportDirective,
span: Span,
help: String,
}
......@@ -249,7 +249,7 @@ fn import_resolving_error(&self, e: ImportResolvingError<'b>) {
}
let path = import_path_to_string(&e.import_directive.module_path,
e.import_directive.subclass);
&e.import_directive.subclass);
resolve_error(self.resolver,
e.span,
......@@ -608,7 +608,7 @@ fn report_conflict(&mut self,
}
}
fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> String {
fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) -> String {
if names.is_empty() {
import_directive_subclass_to_string(subclass)
} else {
......@@ -619,8 +619,8 @@ fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> S
}
}
fn import_directive_subclass_to_string(subclass: ImportDirectiveSubclass) -> String {
match subclass {
fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> String {
match *subclass {
SingleImport { source, .. } => source.to_string(),
GlobImport => "*".to_string(),
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册