Skip to content

Commit 5ad84f1

Browse files
committed
Replace the field imports in Module with unresolved_imports and refactor away resolved_import_count
1 parent 845ad1b commit 5ad84f1

File tree

3 files changed

+16
-56
lines changed

3 files changed

+16
-56
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
1919
use Module;
2020
use Namespace::{self, TypeNS, ValueNS};
2121
use {NameBinding, NameBindingKind};
22-
use {names_to_string, module_to_string};
22+
use module_to_string;
2323
use ParentLink::{ModuleParentLink, BlockParentLink};
2424
use Resolver;
2525
use resolve_imports::Shadowable;
@@ -682,7 +682,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
682682
id: NodeId,
683683
is_public: bool,
684684
shadowable: Shadowable) {
685-
module_.imports
685+
module_.unresolved_imports
686686
.borrow_mut()
687687
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
688688
self.unresolved_imports += 1;
@@ -696,9 +696,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
696696

697697
match subclass {
698698
SingleImport(target, _) => {
699-
debug!("(building import directive) building import directive: {}::{}",
700-
names_to_string(&module_.imports.borrow().last().unwrap().module_path),
701-
target);
702699
module_.increment_outstanding_references_for(target, ValueNS);
703700
module_.increment_outstanding_references_for(target, TypeNS);
704701
}

src/librustc_resolve/lib.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#![cfg_attr(not(stage0), deny(warnings))]
1919

2020
#![feature(associated_consts)]
21-
#![feature(borrow_state)]
2221
#![feature(rustc_diagnostic_macros)]
2322
#![feature(rustc_private)]
2423
#![feature(staged_api)]
@@ -799,7 +798,7 @@ pub struct ModuleS<'a> {
799798
is_extern_crate: bool,
800799

801800
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
802-
imports: RefCell<Vec<ImportDirective>>,
801+
unresolved_imports: RefCell<Vec<ImportDirective>>,
803802

804803
// The module children of this node, including normal modules and anonymous modules.
805804
// Anonymous children are pseudo-modules that are implicitly created around items
@@ -828,9 +827,6 @@ pub struct ModuleS<'a> {
828827
// The number of unresolved pub glob imports in this module
829828
pub_glob_count: Cell<usize>,
830829

831-
// The index of the import we're resolving.
832-
resolved_import_count: Cell<usize>,
833-
834830
// Whether this module is populated. If not populated, any attempt to
835831
// access the children must be preceded with a
836832
// `populate_module_if_necessary` call.
@@ -847,13 +843,12 @@ impl<'a> ModuleS<'a> {
847843
is_public: is_public,
848844
is_extern_crate: false,
849845
resolutions: RefCell::new(HashMap::new()),
850-
imports: RefCell::new(Vec::new()),
846+
unresolved_imports: RefCell::new(Vec::new()),
851847
module_children: RefCell::new(NodeMap()),
852848
shadowed_traits: RefCell::new(Vec::new()),
853849
glob_count: Cell::new(0),
854850
pub_count: Cell::new(0),
855851
pub_glob_count: Cell::new(0),
856-
resolved_import_count: Cell::new(0),
857852
populated: Cell::new(!external),
858853
}
859854
}
@@ -924,15 +919,6 @@ impl<'a> ModuleS<'a> {
924919
}
925920
}
926921

927-
fn all_imports_resolved(&self) -> bool {
928-
if self.imports.borrow_state() == ::std::cell::BorrowState::Writing {
929-
// it is currently being resolved ! so nope
930-
false
931-
} else {
932-
self.imports.borrow().len() == self.resolved_import_count.get()
933-
}
934-
}
935-
936922
pub fn inc_glob_count(&self) {
937923
self.glob_count.set(self.glob_count.get() + 1);
938924
}
@@ -1622,13 +1608,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16221608
}
16231609

16241610
fn report_unresolved_imports(&mut self, module_: Module<'a>) {
1625-
let index = module_.resolved_import_count.get();
1626-
let imports = module_.imports.borrow();
1627-
let import_count = imports.len();
1628-
if index != import_count {
1629-
resolve_error(self,
1630-
(*imports)[index].span,
1631-
ResolutionError::UnresolvedImport(None));
1611+
for import in module_.unresolved_imports.borrow().iter() {
1612+
resolve_error(self, import.span, ResolutionError::UnresolvedImport(None));
1613+
break;
16321614
}
16331615

16341616
// Descend into children and anonymous children.

src/librustc_resolve/resolve_imports.rs

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -252,47 +252,28 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
252252
fn resolve_imports_for_module(&mut self,
253253
module: Module<'b>,
254254
errors: &mut Vec<ImportResolvingError<'b>>) {
255-
if module.all_imports_resolved() {
256-
debug!("(resolving imports for module) all imports resolved for {}",
257-
module_to_string(&module));
258-
return;
259-
}
255+
let mut imports = Vec::new();
256+
let mut unresolved_imports = module.unresolved_imports.borrow_mut();
257+
::std::mem::swap(&mut imports, &mut unresolved_imports);
260258

261-
let mut imports = module.imports.borrow_mut();
262-
let import_count = imports.len();
263-
let mut indeterminate_imports = Vec::new();
264-
while module.resolved_import_count.get() + indeterminate_imports.len() < import_count {
265-
let import_index = module.resolved_import_count.get();
266-
match self.resolve_import_for_module(module, &imports[import_index]) {
267-
ResolveResult::Failed(err) => {
268-
let import_directive = &imports[import_index];
259+
for import_directive in imports {
260+
match self.resolve_import_for_module(module, &import_directive) {
261+
Failed(err) => {
269262
let (span, help) = match err {
270263
Some((span, msg)) => (span, format!(". {}", msg)),
271264
None => (import_directive.span, String::new()),
272265
};
273266
errors.push(ImportResolvingError {
274267
source_module: module,
275-
import_directive: import_directive.clone(),
268+
import_directive: import_directive,
276269
span: span,
277270
help: help,
278271
});
279-
module.resolved_import_count.set(module.resolved_import_count.get() + 1);
280-
continue;
281-
}
282-
ResolveResult::Indeterminate => {}
283-
ResolveResult::Success(()) => {
284-
// count success
285-
module.resolved_import_count
286-
.set(module.resolved_import_count.get() + 1);
287-
continue;
288272
}
273+
Indeterminate => unresolved_imports.push(import_directive),
274+
Success(()) => {}
289275
}
290-
// This resolution was not successful, keep it for later
291-
indeterminate_imports.push(imports.swap_remove(import_index));
292-
293276
}
294-
295-
imports.extend(indeterminate_imports);
296277
}
297278

298279
/// Attempts to resolve the given import. The return value indicates

0 commit comments

Comments
 (0)