Skip to content

Commit 20b99d3

Browse files
committed
Start importing bindings from globs as soon as the glob path is known.
1 parent fb4710c commit 20b99d3

File tree

3 files changed

+232
-128
lines changed

3 files changed

+232
-128
lines changed

src/librustc_resolve/build_reduced_graph.rs

-8
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,6 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
295295
let module = self.new_extern_crate_module(parent_link, def, is_public, item.id);
296296
self.define(parent, name, TypeNS, (module, sp));
297297

298-
if is_public {
299-
let export = Export { name: name, def_id: def_id };
300-
if let Some(def_id) = parent.def_id() {
301-
let node_id = self.resolver.ast_map.as_local_node_id(def_id).unwrap();
302-
self.export_map.entry(node_id).or_insert(Vec::new()).push(export);
303-
}
304-
}
305-
306298
self.build_reduced_graph_for_external_crate(module);
307299
}
308300
parent

src/librustc_resolve/lib.rs

+6-43
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![cfg_attr(not(stage0), deny(warnings))]
1919

2020
#![feature(associated_consts)]
21+
#![feature(borrow_state)]
2122
#![feature(rustc_diagnostic_macros)]
2223
#![feature(rustc_private)]
2324
#![feature(staged_api)]
@@ -832,6 +833,9 @@ pub struct ModuleS<'a> {
832833

833834
shadowed_traits: RefCell<Vec<&'a NameBinding<'a>>>,
834835

836+
glob_importers: RefCell<Vec<(Module<'a>, &'a ImportDirective)>>,
837+
resolved_globs: RefCell<(Vec<Module<'a>> /* public */, Vec<Module<'a>> /* private */)>,
838+
835839
// The number of unresolved globs that this module exports.
836840
glob_count: Cell<usize>,
837841

@@ -866,6 +870,8 @@ impl<'a> ModuleS<'a> {
866870
unresolved_imports: RefCell::new(Vec::new()),
867871
module_children: RefCell::new(NodeMap()),
868872
shadowed_traits: RefCell::new(Vec::new()),
873+
glob_importers: RefCell::new(Vec::new()),
874+
resolved_globs: RefCell::new((Vec::new(), Vec::new())),
869875
glob_count: Cell::new(0),
870876
pub_count: Cell::new(0),
871877
pub_glob_count: Cell::new(0),
@@ -874,54 +880,11 @@ impl<'a> ModuleS<'a> {
874880
}
875881
}
876882

877-
fn resolve_name(&self, name: Name, ns: Namespace, allow_private_imports: bool)
878-
-> ResolveResult<&'a NameBinding<'a>> {
879-
let glob_count =
880-
if allow_private_imports { self.glob_count.get() } else { self.pub_glob_count.get() };
881-
882-
self.resolutions.borrow().get(&(name, ns)).cloned().unwrap_or_default().result(glob_count)
883-
.and_then(|binding| {
884-
let allowed = allow_private_imports || !binding.is_import() || binding.is_public();
885-
if allowed { Success(binding) } else { Failed(None) }
886-
})
887-
}
888-
889-
// Define the name or return the existing binding if there is a collision.
890-
fn try_define_child(&self, name: Name, ns: Namespace, binding: NameBinding<'a>)
891-
-> Result<(), &'a NameBinding<'a>> {
892-
let binding = self.arenas.alloc_name_binding(binding);
893-
let mut children = self.resolutions.borrow_mut();
894-
let resolution = children.entry((name, ns)).or_insert_with(Default::default);
895-
896-
// FIXME #31379: We can use methods from imported traits shadowed by non-import items
897-
if let Some(old_binding) = resolution.binding {
898-
if !old_binding.is_import() && binding.is_import() {
899-
if let Some(Def::Trait(_)) = binding.def() {
900-
self.shadowed_traits.borrow_mut().push(binding);
901-
}
902-
}
903-
}
904-
905-
resolution.try_define(binding)
906-
}
907-
908883
fn add_import_directive(&self, import_directive: ImportDirective) {
909884
let import_directive = self.arenas.alloc_import_directive(import_directive);
910885
self.unresolved_imports.borrow_mut().push(import_directive);
911886
}
912887

913-
fn increment_outstanding_references_for(&self, name: Name, ns: Namespace) {
914-
let mut children = self.resolutions.borrow_mut();
915-
children.entry((name, ns)).or_insert_with(Default::default).outstanding_references += 1;
916-
}
917-
918-
fn decrement_outstanding_references_for(&self, name: Name, ns: Namespace) {
919-
match self.resolutions.borrow_mut().get_mut(&(name, ns)).unwrap().outstanding_references {
920-
0 => panic!("No more outstanding references!"),
921-
ref mut outstanding_references => { *outstanding_references -= 1; }
922-
}
923-
}
924-
925888
fn for_each_child<F: FnMut(Name, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
926889
for (&(name, ns), name_resolution) in self.resolutions.borrow().iter() {
927890
name_resolution.binding.map(|binding| f(name, ns, binding));

0 commit comments

Comments
 (0)