1
Fork 0

Replace the field imports in Module with unresolved_imports and refactor away resolved_import_count

This commit is contained in:
Jeffrey Seyfried 2016-02-17 22:45:05 +00:00
parent 845ad1b4ed
commit 5ad84f1301
3 changed files with 16 additions and 56 deletions

View file

@ -19,7 +19,7 @@ use resolve_imports::ImportDirectiveSubclass::{self, SingleImport, GlobImport};
use Module; use Module;
use Namespace::{self, TypeNS, ValueNS}; use Namespace::{self, TypeNS, ValueNS};
use {NameBinding, NameBindingKind}; use {NameBinding, NameBindingKind};
use {names_to_string, module_to_string}; use module_to_string;
use ParentLink::{ModuleParentLink, BlockParentLink}; use ParentLink::{ModuleParentLink, BlockParentLink};
use Resolver; use Resolver;
use resolve_imports::Shadowable; use resolve_imports::Shadowable;
@ -682,7 +682,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
id: NodeId, id: NodeId,
is_public: bool, is_public: bool,
shadowable: Shadowable) { shadowable: Shadowable) {
module_.imports module_.unresolved_imports
.borrow_mut() .borrow_mut()
.push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable)); .push(ImportDirective::new(module_path, subclass, span, id, is_public, shadowable));
self.unresolved_imports += 1; self.unresolved_imports += 1;
@ -696,9 +696,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
match subclass { match subclass {
SingleImport(target, _) => { SingleImport(target, _) => {
debug!("(building import directive) building import directive: {}::{}",
names_to_string(&module_.imports.borrow().last().unwrap().module_path),
target);
module_.increment_outstanding_references_for(target, ValueNS); module_.increment_outstanding_references_for(target, ValueNS);
module_.increment_outstanding_references_for(target, TypeNS); module_.increment_outstanding_references_for(target, TypeNS);
} }

View file

@ -18,7 +18,6 @@
#![cfg_attr(not(stage0), deny(warnings))] #![cfg_attr(not(stage0), deny(warnings))]
#![feature(associated_consts)] #![feature(associated_consts)]
#![feature(borrow_state)]
#![feature(rustc_diagnostic_macros)] #![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(staged_api)] #![feature(staged_api)]
@ -799,7 +798,7 @@ pub struct ModuleS<'a> {
is_extern_crate: bool, is_extern_crate: bool,
resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>, resolutions: RefCell<HashMap<(Name, Namespace), NameResolution<'a>>>,
imports: RefCell<Vec<ImportDirective>>, unresolved_imports: RefCell<Vec<ImportDirective>>,
// The module children of this node, including normal modules and anonymous modules. // The module children of this node, including normal modules and anonymous modules.
// Anonymous children are pseudo-modules that are implicitly created around items // Anonymous children are pseudo-modules that are implicitly created around items
@ -828,9 +827,6 @@ pub struct ModuleS<'a> {
// The number of unresolved pub glob imports in this module // The number of unresolved pub glob imports in this module
pub_glob_count: Cell<usize>, pub_glob_count: Cell<usize>,
// The index of the import we're resolving.
resolved_import_count: Cell<usize>,
// Whether this module is populated. If not populated, any attempt to // Whether this module is populated. If not populated, any attempt to
// 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.
@ -847,13 +843,12 @@ impl<'a> ModuleS<'a> {
is_public: is_public, is_public: is_public,
is_extern_crate: false, is_extern_crate: false,
resolutions: RefCell::new(HashMap::new()), resolutions: RefCell::new(HashMap::new()),
imports: RefCell::new(Vec::new()), unresolved_imports: RefCell::new(Vec::new()),
module_children: RefCell::new(NodeMap()), module_children: RefCell::new(NodeMap()),
shadowed_traits: RefCell::new(Vec::new()), shadowed_traits: RefCell::new(Vec::new()),
glob_count: Cell::new(0), glob_count: Cell::new(0),
pub_count: Cell::new(0), pub_count: Cell::new(0),
pub_glob_count: Cell::new(0), pub_glob_count: Cell::new(0),
resolved_import_count: Cell::new(0),
populated: Cell::new(!external), populated: Cell::new(!external),
} }
} }
@ -924,15 +919,6 @@ impl<'a> ModuleS<'a> {
} }
} }
fn all_imports_resolved(&self) -> bool {
if self.imports.borrow_state() == ::std::cell::BorrowState::Writing {
// it is currently being resolved ! so nope
false
} else {
self.imports.borrow().len() == self.resolved_import_count.get()
}
}
pub fn inc_glob_count(&self) { pub fn inc_glob_count(&self) {
self.glob_count.set(self.glob_count.get() + 1); self.glob_count.set(self.glob_count.get() + 1);
} }
@ -1622,13 +1608,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
} }
fn report_unresolved_imports(&mut self, module_: Module<'a>) { fn report_unresolved_imports(&mut self, module_: Module<'a>) {
let index = module_.resolved_import_count.get(); for import in module_.unresolved_imports.borrow().iter() {
let imports = module_.imports.borrow(); resolve_error(self, import.span, ResolutionError::UnresolvedImport(None));
let import_count = imports.len(); break;
if index != import_count {
resolve_error(self,
(*imports)[index].span,
ResolutionError::UnresolvedImport(None));
} }
// Descend into children and anonymous children. // Descend into children and anonymous children.

View file

@ -252,47 +252,28 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
fn resolve_imports_for_module(&mut self, fn resolve_imports_for_module(&mut self,
module: Module<'b>, module: Module<'b>,
errors: &mut Vec<ImportResolvingError<'b>>) { errors: &mut Vec<ImportResolvingError<'b>>) {
if module.all_imports_resolved() { let mut imports = Vec::new();
debug!("(resolving imports for module) all imports resolved for {}", let mut unresolved_imports = module.unresolved_imports.borrow_mut();
module_to_string(&module)); ::std::mem::swap(&mut imports, &mut unresolved_imports);
return;
}
let mut imports = module.imports.borrow_mut(); for import_directive in imports {
let import_count = imports.len(); match self.resolve_import_for_module(module, &import_directive) {
let mut indeterminate_imports = Vec::new(); Failed(err) => {
while module.resolved_import_count.get() + indeterminate_imports.len() < import_count {
let import_index = module.resolved_import_count.get();
match self.resolve_import_for_module(module, &imports[import_index]) {
ResolveResult::Failed(err) => {
let import_directive = &imports[import_index];
let (span, help) = match err { let (span, help) = match err {
Some((span, msg)) => (span, format!(". {}", msg)), Some((span, msg)) => (span, format!(". {}", msg)),
None => (import_directive.span, String::new()), None => (import_directive.span, String::new()),
}; };
errors.push(ImportResolvingError { errors.push(ImportResolvingError {
source_module: module, source_module: module,
import_directive: import_directive.clone(), import_directive: import_directive,
span: span, span: span,
help: help, help: help,
}); });
module.resolved_import_count.set(module.resolved_import_count.get() + 1);
continue;
}
ResolveResult::Indeterminate => {}
ResolveResult::Success(()) => {
// count success
module.resolved_import_count
.set(module.resolved_import_count.get() + 1);
continue;
} }
Indeterminate => unresolved_imports.push(import_directive),
Success(()) => {}
} }
// This resolution was not successful, keep it for later
indeterminate_imports.push(imports.swap_remove(import_index));
} }
imports.extend(indeterminate_imports);
} }
/// Attempts to resolve the given import. The return value indicates /// Attempts to resolve the given import. The return value indicates