Skip to content

Commit 6b94bc3

Browse files
committed
Add an arena for import directives
1 parent 064f17c commit 6b94bc3

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
707707
}
708708
}
709709

710-
module_.unresolved_imports
711-
.borrow_mut()
712-
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
710+
let directive =
711+
ImportDirective::new(module_path, subclass, span, id, is_public, shadowable);
712+
let directive = self.resolver.arenas.alloc_import_directive(directive);
713+
module_.unresolved_imports.borrow_mut().push(directive);
713714
self.unresolved_imports += 1;
714715
}
715716
}

src/librustc_resolve/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ pub struct ModuleS<'a> {
812812
extern_crate_id: Option<NodeId>,
813813

814814
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
815-
unresolved_imports: RefCell<Vec<ImportDirective>>,
815+
unresolved_imports: RefCell<Vec<&'a ImportDirective>>,
816816

817817
// The module children of this node, including normal modules and anonymous modules.
818818
// Anonymous children are pseudo-modules that are implicitly created around items
@@ -1167,6 +1167,13 @@ pub struct Resolver<'a, 'tcx: 'a> {
11671167
pub struct ResolverArenas<'a> {
11681168
modules: arena::TypedArena<ModuleS<'a>>,
11691169
name_bindings: arena::TypedArena<NameBinding<'a>>,
1170+
import_directives: arena::TypedArena<ImportDirective>,
1171+
}
1172+
1173+
impl<'a> ResolverArenas<'a> {
1174+
fn alloc_import_directive(&'a self, import_directive: ImportDirective) -> &'a ImportDirective {
1175+
self.import_directives.alloc(import_directive)
1176+
}
11701177
}
11711178

11721179
#[derive(PartialEq)]
@@ -1234,6 +1241,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12341241
ResolverArenas {
12351242
modules: arena::TypedArena::new(),
12361243
name_bindings: arena::TypedArena::new(),
1244+
import_directives: arena::TypedArena::new(),
12371245
}
12381246
}
12391247

src/librustc_resolve/resolve_imports.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a> NameResolution<'a> {
172172
struct ImportResolvingError<'a> {
173173
/// Module where the error happened
174174
source_module: Module<'a>,
175-
import_directive: ImportDirective,
175+
import_directive: &'a ImportDirective,
176176
span: Span,
177177
help: String,
178178
}
@@ -249,7 +249,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
249249
}
250250

251251
let path = import_path_to_string(&e.import_directive.module_path,
252-
e.import_directive.subclass);
252+
&e.import_directive.subclass);
253253

254254
resolve_error(self.resolver,
255255
e.span,
@@ -608,7 +608,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
608608
}
609609
}
610610

611-
fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> String {
611+
fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) -> String {
612612
if names.is_empty() {
613613
import_directive_subclass_to_string(subclass)
614614
} else {
@@ -619,8 +619,8 @@ fn import_path_to_string(names: &[Name], subclass: ImportDirectiveSubclass) -> S
619619
}
620620
}
621621

622-
fn import_directive_subclass_to_string(subclass: ImportDirectiveSubclass) -> String {
623-
match subclass {
622+
fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> String {
623+
match *subclass {
624624
SingleImport { source, .. } => source.to_string(),
625625
GlobImport => "*".to_string(),
626626
}

0 commit comments

Comments
 (0)