Add an arena for import directives

This commit is contained in:
Jeffrey Seyfried 2016-02-15 02:22:59 +00:00
parent 064f17c6a3
commit 6b94bc345c
3 changed files with 18 additions and 9 deletions

View File

@ -707,9 +707,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
}
}
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;
}
}

View File

@ -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 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ResolverArenas {
modules: arena::TypedArena::new(),
name_bindings: arena::TypedArena::new(),
import_directives: arena::TypedArena::new(),
}
}

View File

@ -172,7 +172,7 @@ impl<'a> NameResolution<'a> {
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 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
}
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 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
}
}
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(),
}