Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac89e03

Browse files
committedJul 30, 2019
Auto merge of #63149 - petrochenkov:lazypop2, r=<try>
resolve: Populate external modules in more automatic and lazy way So, resolve had this function `populate_module_if_necessary` for loading module children from other crates from metadata. I never really understood when it should've been called and when not. This PR removes the function and loads the module children automatically on the first access instead. r? @eddyb
2 parents f690098 + 2245577 commit ac89e03

File tree

6 files changed

+113
-132
lines changed

6 files changed

+113
-132
lines changed
 

‎src/librustc_resolve/build_reduced_graph.rs

Lines changed: 29 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ impl<'a> Resolver<'a> {
365365
self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })
366366
};
367367

368-
self.populate_module_if_necessary(module);
369368
if let Some(name) = self.session.parse_sess.injected_crate_name.try_get() {
370369
if name.as_str() == ident.name.as_str() {
371370
self.injected_crate = Some(module);
@@ -632,7 +631,7 @@ impl<'a> Resolver<'a> {
632631
}
633632

634633
/// Builds the reduced graph for a single item in an external crate.
635-
fn build_reduced_graph_for_external_crate_res(
634+
crate fn build_reduced_graph_for_external_crate_res(
636635
&mut self,
637636
parent: Module<'a>,
638637
child: Export<ast::NodeId>,
@@ -645,68 +644,53 @@ impl<'a> Resolver<'a> {
645644
let expansion = ExpnId::root(); // FIXME(jseyfried) intercrate hygiene
646645
match res {
647646
Res::Def(kind @ DefKind::Mod, def_id)
648-
| Res::Def(kind @ DefKind::Enum, def_id) => {
647+
| Res::Def(kind @ DefKind::Enum, def_id)
648+
| Res::Def(kind @ DefKind::Trait, def_id) => {
649649
let module = self.new_module(parent,
650650
ModuleKind::Def(kind, def_id, ident.name),
651651
def_id,
652652
expansion,
653653
span);
654654
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
655655
}
656-
Res::Def(DefKind::Variant, _)
656+
Res::Def(DefKind::Struct, _)
657+
| Res::Def(DefKind::Union, _)
658+
| Res::Def(DefKind::Variant, _)
657659
| Res::Def(DefKind::TyAlias, _)
658660
| Res::Def(DefKind::ForeignTy, _)
659661
| Res::Def(DefKind::Existential, _)
660662
| Res::Def(DefKind::TraitAlias, _)
663+
| Res::Def(DefKind::AssocTy, _)
664+
| Res::Def(DefKind::AssocExistential, _)
661665
| Res::PrimTy(..)
662666
| Res::ToolMod => {
663667
self.define(parent, ident, TypeNS, (res, vis, DUMMY_SP, expansion));
668+
669+
if let Res::Def(DefKind::Struct, def_id) | Res::Def(DefKind::Union, def_id) = res {
670+
// Record field names for error reporting.
671+
let field_names = self.cstore.struct_field_names_untracked(def_id);
672+
self.insert_field_names(def_id, field_names);
673+
}
664674
}
665675
Res::Def(DefKind::Fn, _)
676+
| Res::Def(DefKind::Method, _)
666677
| Res::Def(DefKind::Static, _)
667678
| Res::Def(DefKind::Const, _)
668-
| Res::Def(DefKind::Ctor(CtorOf::Variant, ..), _) => {
669-
self.define(parent, ident, ValueNS, (res, vis, DUMMY_SP, expansion));
670-
}
671-
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), def_id) => {
679+
| Res::Def(DefKind::AssocConst, _)
680+
| Res::Def(DefKind::Ctor(..), _) => {
672681
self.define(parent, ident, ValueNS, (res, vis, DUMMY_SP, expansion));
673682

674-
if let Some(struct_def_id) =
675-
self.cstore.def_key(def_id).parent
676-
.map(|index| DefId { krate: def_id.krate, index: index }) {
677-
self.struct_constructors.insert(struct_def_id, (res, vis));
678-
}
679-
}
680-
Res::Def(DefKind::Trait, def_id) => {
681-
let module_kind = ModuleKind::Def(DefKind::Trait, def_id, ident.name);
682-
let module = self.new_module(parent,
683-
module_kind,
684-
parent.normal_ancestor_id,
685-
expansion,
686-
span);
687-
self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion));
688-
689-
for child in self.cstore.item_children_untracked(def_id, self.session) {
690-
let res = child.res.map_id(|_| panic!("unexpected id"));
691-
let ns = if let Res::Def(DefKind::AssocTy, _) = res {
692-
TypeNS
693-
} else { ValueNS };
694-
self.define(module, child.ident, ns,
695-
(res, ty::Visibility::Public, DUMMY_SP, expansion));
696-
697-
if self.cstore.associated_item_cloned_untracked(child.res.def_id())
698-
.method_has_self_argument {
699-
self.has_self.insert(res.def_id());
683+
if let Res::Def(DefKind::Method, def_id) = res {
684+
let assoc_item = self.cstore.associated_item_cloned_untracked(def_id);
685+
if assoc_item.method_has_self_argument {
686+
self.has_self.insert(def_id);
687+
}
688+
} else if let Res::Def(DefKind::Ctor(CtorOf::Struct, ..), def_id) = res {
689+
let parent = self.cstore.def_key(def_id).parent;
690+
if let Some(struct_def_id) = parent.map(|index| DefId { index, ..def_id }) {
691+
self.struct_constructors.insert(struct_def_id, (res, vis));
700692
}
701693
}
702-
module.populated.set(true);
703-
}
704-
Res::Def(DefKind::Struct, def_id) | Res::Def(DefKind::Union, def_id) => {
705-
self.define(parent, ident, TypeNS, (res, vis, DUMMY_SP, expansion));
706-
707-
// Record field names for error reporting.
708-
let field_names = self.cstore.struct_field_names_untracked(def_id);
709-
self.insert_field_names(def_id, field_names);
710694
}
711695
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
712696
self.define(parent, ident, MacroNS, (res, vis, DUMMY_SP, expansion));
@@ -780,18 +764,6 @@ impl<'a> Resolver<'a> {
780764
Some(ext)
781765
}
782766

783-
/// Ensures that the reduced graph rooted at the given external module
784-
/// is built, building it if it is not.
785-
pub fn populate_module_if_necessary(&mut self, module: Module<'a>) {
786-
if module.populated.get() { return }
787-
let def_id = module.def_id().unwrap();
788-
for child in self.cstore.item_children_untracked(def_id, self.session) {
789-
let child = child.map_id(|_| panic!("unexpected id"));
790-
self.build_reduced_graph_for_external_crate_res(module, child);
791-
}
792-
module.populated.set(true)
793-
}
794-
795767
fn legacy_import_macro(&mut self,
796768
name: Name,
797769
binding: &'a NameBinding<'a>,
@@ -863,9 +835,9 @@ impl<'a> Resolver<'a> {
863835
if let Some(span) = import_all {
864836
let directive = macro_use_directive(span);
865837
self.potentially_unused_imports.push(directive);
866-
module.for_each_child(|ident, ns, binding| if ns == MacroNS {
867-
let imported_binding = self.import(binding, directive);
868-
self.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
838+
self.for_each_child(module, |this, ident, ns, binding| if ns == MacroNS {
839+
let imported_binding = this.import(binding, directive);
840+
this.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
869841
});
870842
} else {
871843
for ident in single_imports.iter().cloned() {

‎src/librustc_resolve/diagnostics.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,23 @@ fn add_typo_suggestion(
6565
false
6666
}
6767

68-
fn add_module_candidates(
69-
module: Module<'_>, names: &mut Vec<TypoSuggestion>, filter_fn: &impl Fn(Res) -> bool
70-
) {
71-
for (&(ident, _), resolution) in module.resolutions.borrow().iter() {
72-
if let Some(binding) = resolution.borrow().binding {
73-
let res = binding.res();
74-
if filter_fn(res) {
75-
names.push(TypoSuggestion::from_res(ident.name, res));
68+
impl<'a> Resolver<'a> {
69+
fn add_module_candidates(
70+
&mut self,
71+
module: Module<'a>,
72+
names: &mut Vec<TypoSuggestion>,
73+
filter_fn: &impl Fn(Res) -> bool,
74+
) {
75+
for (&(ident, _), resolution) in self.resolutions(module).borrow().iter() {
76+
if let Some(binding) = resolution.borrow().binding {
77+
let res = binding.res();
78+
if filter_fn(res) {
79+
names.push(TypoSuggestion::from_res(ident.name, res));
80+
}
7681
}
7782
}
7883
}
79-
}
8084

81-
impl<'a> Resolver<'a> {
8285
/// Handles error reporting for `smart_resolve_path_fragment` function.
8386
/// Creates base error and amends it with one short label and possibly some longer helps/notes.
8487
pub(crate) fn smart_resolve_report_errors(
@@ -593,10 +596,10 @@ impl<'a> Resolver<'a> {
593596
Scope::CrateRoot => {
594597
let root_ident = Ident::new(kw::PathRoot, ident.span);
595598
let root_module = this.resolve_crate_root(root_ident);
596-
add_module_candidates(root_module, &mut suggestions, filter_fn);
599+
this.add_module_candidates(root_module, &mut suggestions, filter_fn);
597600
}
598601
Scope::Module(module) => {
599-
add_module_candidates(module, &mut suggestions, filter_fn);
602+
this.add_module_candidates(module, &mut suggestions, filter_fn);
600603
}
601604
Scope::MacroUsePrelude => {
602605
suggestions.extend(this.macro_use_prelude.iter().filter_map(|(name, binding)| {
@@ -644,7 +647,7 @@ impl<'a> Resolver<'a> {
644647
Scope::StdLibPrelude => {
645648
if let Some(prelude) = this.prelude {
646649
let mut tmp_suggestions = Vec::new();
647-
add_module_candidates(prelude, &mut tmp_suggestions, filter_fn);
650+
this.add_module_candidates(prelude, &mut tmp_suggestions, filter_fn);
648651
suggestions.extend(tmp_suggestions.into_iter().filter(|s| {
649652
use_prelude || this.is_builtin_macro(s.res.opt_def_id())
650653
}));
@@ -694,7 +697,9 @@ impl<'a> Resolver<'a> {
694697
if path.len() == 1 {
695698
// Search in lexical scope.
696699
// Walk backwards up the ribs in scope and collect candidates.
697-
for rib in self.ribs[ns].iter().rev() {
700+
// Ribs have to be cloned to avoid borrowing the resolver.
701+
let ribs = self.ribs[ns].clone();
702+
for rib in ribs.iter().rev() {
698703
// Locals and type parameters
699704
for (ident, &res) in &rib.bindings {
700705
if filter_fn(res) {
@@ -704,7 +709,7 @@ impl<'a> Resolver<'a> {
704709
// Items in scope
705710
if let RibKind::ModuleRibKind(module) = rib.kind {
706711
// Items from this module
707-
add_module_candidates(module, &mut names, &filter_fn);
712+
self.add_module_candidates(module, &mut names, &filter_fn);
708713

709714
if let ModuleKind::Block(..) = module.kind {
710715
// We can see through blocks
@@ -732,7 +737,7 @@ impl<'a> Resolver<'a> {
732737
}));
733738

734739
if let Some(prelude) = self.prelude {
735-
add_module_candidates(prelude, &mut names, &filter_fn);
740+
self.add_module_candidates(prelude, &mut names, &filter_fn);
736741
}
737742
}
738743
break;
@@ -754,7 +759,7 @@ impl<'a> Resolver<'a> {
754759
mod_path, Some(TypeNS), false, span, CrateLint::No
755760
) {
756761
if let ModuleOrUniformRoot::Module(module) = module {
757-
add_module_candidates(module, &mut names, &filter_fn);
762+
self.add_module_candidates(module, &mut names, &filter_fn);
758763
}
759764
}
760765
}
@@ -792,11 +797,9 @@ impl<'a> Resolver<'a> {
792797
while let Some((in_module,
793798
path_segments,
794799
in_module_is_extern)) = worklist.pop() {
795-
self.populate_module_if_necessary(in_module);
796-
797800
// We have to visit module children in deterministic order to avoid
798801
// instabilities in reported imports (#43552).
799-
in_module.for_each_child_stable(|ident, ns, name_binding| {
802+
self.for_each_child_stable(in_module, |this, ident, ns, name_binding| {
800803
// avoid imports entirely
801804
if name_binding.is_import() && !name_binding.is_extern_crate() { return; }
802805
// avoid non-importable candidates as well
@@ -830,7 +833,7 @@ impl<'a> Resolver<'a> {
830833
// outside crate private modules => no need to check this)
831834
if !in_module_is_extern || name_binding.vis == ty::Visibility::Public {
832835
let did = match res {
833-
Res::Def(DefKind::Ctor(..), did) => self.parent(did),
836+
Res::Def(DefKind::Ctor(..), did) => this.parent(did),
834837
_ => res.opt_def_id(),
835838
};
836839
candidates.push(ImportSuggestion { did, path });
@@ -890,8 +893,6 @@ impl<'a> Resolver<'a> {
890893
krate: crate_id,
891894
index: CRATE_DEF_INDEX,
892895
});
893-
self.populate_module_if_necessary(&crate_root);
894-
895896
suggestions.extend(self.lookup_import_candidates_from_module(
896897
lookup_ident, namespace, crate_root, ident, &filter_fn));
897898
}
@@ -910,9 +911,7 @@ impl<'a> Resolver<'a> {
910911
// abort if the module is already found
911912
if result.is_some() { break; }
912913

913-
self.populate_module_if_necessary(in_module);
914-
915-
in_module.for_each_child_stable(|ident, _, name_binding| {
914+
self.for_each_child_stable(in_module, |_, ident, _, name_binding| {
916915
// abort if the module is already found or if name_binding is private external
917916
if result.is_some() || !name_binding.vis.is_visible_locally() {
918917
return
@@ -943,10 +942,8 @@ impl<'a> Resolver<'a> {
943942

944943
fn collect_enum_variants(&mut self, def_id: DefId) -> Option<Vec<Path>> {
945944
self.find_module(def_id).map(|(enum_module, enum_import_suggestion)| {
946-
self.populate_module_if_necessary(enum_module);
947-
948945
let mut variants = Vec::new();
949-
enum_module.for_each_child_stable(|ident, _, name_binding| {
946+
self.for_each_child_stable(enum_module, |_, ident, _, name_binding| {
950947
if let Res::Def(DefKind::Variant, _) = name_binding.res() {
951948
let mut segms = enum_import_suggestion.path.segments.clone();
952949
segms.push(ast::PathSegment::from_ident(ident));
@@ -1147,7 +1144,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
11471144
/// at the root of the crate instead of the module where it is defined
11481145
/// ```
11491146
pub(crate) fn check_for_module_export_macro(
1150-
&self,
1147+
&mut self,
11511148
directive: &'b ImportDirective<'b>,
11521149
module: ModuleOrUniformRoot<'b>,
11531150
ident: Ident,
@@ -1168,7 +1165,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
11681165
return None;
11691166
}
11701167

1171-
let resolutions = crate_module.resolutions.borrow();
1168+
let resolutions = self.resolutions(crate_module).borrow();
11721169
let resolution = resolutions.get(&(ident, MacroNS))?;
11731170
let binding = resolution.borrow().binding()?;
11741171
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = binding.res() {

‎src/librustc_resolve/lib.rs

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ enum RibKind<'a> {
10361036
///
10371037
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When
10381038
/// resolving, the name is looked up from inside out.
1039-
#[derive(Debug)]
1039+
#[derive(Clone, Debug)]
10401040
struct Rib<'a, R = Res> {
10411041
bindings: FxHashMap<Ident, R>,
10421042
kind: RibKind<'a>,
@@ -1157,6 +1157,8 @@ impl ModuleKind {
11571157
}
11581158
}
11591159

1160+
type Resolutions<'a> = RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>;
1161+
11601162
/// One node in the tree of modules.
11611163
pub struct ModuleData<'a> {
11621164
parent: Option<Module<'a>>,
@@ -1165,7 +1167,11 @@ pub struct ModuleData<'a> {
11651167
// The def id of the closest normal module (`mod`) ancestor (including this module).
11661168
normal_ancestor_id: DefId,
11671169

1168-
resolutions: RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>,
1170+
// Mapping between names and their (possibly in-progress) resolutions in this module.
1171+
// Resolutions in modules from other crates are not populated until accessed.
1172+
lazy_resolutions: Resolutions<'a>,
1173+
// True if this is a module from other crate that needs to be populated on access.
1174+
populate_on_access: Cell<bool>,
11691175
single_segment_macro_resolutions: RefCell<Vec<(Ident, MacroKind, ParentScope<'a>,
11701176
Option<&'a NameBinding<'a>>)>>,
11711177
multi_segment_macro_resolutions: RefCell<Vec<(Vec<Segment>, Span, MacroKind, ParentScope<'a>,
@@ -1183,11 +1189,6 @@ pub struct ModuleData<'a> {
11831189
// Used to memoize the traits in this module for faster searches through all traits in scope.
11841190
traits: RefCell<Option<Box<[(Ident, &'a NameBinding<'a>)]>>>,
11851191

1186-
// Whether this module is populated. If not populated, any attempt to
1187-
// access the children must be preceded with a
1188-
// `populate_module_if_necessary` call.
1189-
populated: Cell<bool>,
1190-
11911192
/// Span of the module itself. Used for error reporting.
11921193
span: Span,
11931194

@@ -1206,7 +1207,8 @@ impl<'a> ModuleData<'a> {
12061207
parent,
12071208
kind,
12081209
normal_ancestor_id,
1209-
resolutions: Default::default(),
1210+
lazy_resolutions: Default::default(),
1211+
populate_on_access: Cell::new(!normal_ancestor_id.is_local()),
12101212
single_segment_macro_resolutions: RefCell::new(Vec::new()),
12111213
multi_segment_macro_resolutions: RefCell::new(Vec::new()),
12121214
builtin_attrs: RefCell::new(Vec::new()),
@@ -1215,27 +1217,11 @@ impl<'a> ModuleData<'a> {
12151217
glob_importers: RefCell::new(Vec::new()),
12161218
globs: RefCell::new(Vec::new()),
12171219
traits: RefCell::new(None),
1218-
populated: Cell::new(normal_ancestor_id.is_local()),
12191220
span,
12201221
expansion,
12211222
}
12221223
}
12231224

1224-
fn for_each_child<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
1225-
for (&(ident, ns), name_resolution) in self.resolutions.borrow().iter() {
1226-
name_resolution.borrow().binding.map(|binding| f(ident, ns, binding));
1227-
}
1228-
}
1229-
1230-
fn for_each_child_stable<F: FnMut(Ident, Namespace, &'a NameBinding<'a>)>(&self, mut f: F) {
1231-
let resolutions = self.resolutions.borrow();
1232-
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
1233-
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.as_str(), ns));
1234-
for &(&(ident, ns), &resolution) in resolutions.iter() {
1235-
resolution.borrow().binding.map(|binding| f(ident, ns, binding));
1236-
}
1237-
}
1238-
12391225
fn res(&self) -> Option<Res> {
12401226
match self.kind {
12411227
ModuleKind::Def(kind, def_id, _) => Some(Res::Def(kind, def_id)),
@@ -1895,9 +1881,7 @@ impl<'a> Resolver<'a> {
18951881
seg.id = self.session.next_node_id();
18961882
seg
18971883
}
1898-
}
18991884

1900-
impl<'a> Resolver<'a> {
19011885
pub fn new(session: &'a Session,
19021886
cstore: &'a CStore,
19031887
krate: &Crate,
@@ -2102,6 +2086,43 @@ impl<'a> Resolver<'a> {
21022086
self.arenas.alloc_module(module)
21032087
}
21042088

2089+
fn resolutions(&mut self, module: Module<'a>) -> &'a Resolutions<'a> {
2090+
if module.populate_on_access.get() {
2091+
module.populate_on_access.set(false);
2092+
let def_id = module.def_id().expect("unpopulated module without a def-id");
2093+
for child in self.cstore.item_children_untracked(def_id, self.session) {
2094+
let child = child.map_id(|_| panic!("unexpected id"));
2095+
self.build_reduced_graph_for_external_crate_res(module, child);
2096+
}
2097+
}
2098+
&module.lazy_resolutions
2099+
}
2100+
2101+
fn resolution(&mut self, module: Module<'a>, ident: Ident, ns: Namespace)
2102+
-> &'a RefCell<NameResolution<'a>> {
2103+
*self.resolutions(module).borrow_mut().entry((ident.modern(), ns))
2104+
.or_insert_with(|| self.arenas.alloc_name_resolution())
2105+
}
2106+
2107+
fn for_each_child<F>(&mut self, module: Module<'a>, mut f: F)
2108+
where F: FnMut(&mut Resolver<'a>, Ident, Namespace, &'a NameBinding<'a>)
2109+
{
2110+
for (&(ident, ns), name_resolution) in self.resolutions(module).borrow().iter() {
2111+
name_resolution.borrow().binding.map(|binding| f(self, ident, ns, binding));
2112+
}
2113+
}
2114+
2115+
fn for_each_child_stable<F>(&mut self, module: Module<'a>, mut f: F)
2116+
where F: FnMut(&mut Resolver<'a>, Ident, Namespace, &'a NameBinding<'a>)
2117+
{
2118+
let resolutions = self.resolutions(module).borrow();
2119+
let mut resolutions = resolutions.iter().collect::<Vec<_>>();
2120+
resolutions.sort_by_cached_key(|&(&(ident, ns), _)| (ident.as_str(), ns));
2121+
for &(&(ident, ns), &resolution) in resolutions.iter() {
2122+
resolution.borrow().binding.map(|binding| f(self, ident, ns, binding));
2123+
}
2124+
}
2125+
21052126
fn record_use(&mut self, ident: Ident, ns: Namespace,
21062127
used_binding: &'a NameBinding<'a>, is_lexical_scope: bool) {
21072128
if let Some((b2, kind)) = used_binding.ambiguity {
@@ -4517,7 +4538,7 @@ impl<'a> Resolver<'a> {
45174538
let mut traits = module.traits.borrow_mut();
45184539
if traits.is_none() {
45194540
let mut collected_traits = Vec::new();
4520-
module.for_each_child(|name, ns, binding| {
4541+
self.for_each_child(module, |_, name, ns, binding| {
45214542
if ns != TypeNS { return }
45224543
match binding.res() {
45234544
Res::Def(DefKind::Trait, _) |
@@ -5071,7 +5092,6 @@ impl<'a> Resolver<'a> {
50715092
return None;
50725093
};
50735094
let crate_root = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
5074-
self.populate_module_if_necessary(&crate_root);
50755095
Some((crate_root, ty::Visibility::Public, DUMMY_SP, ExpnId::root())
50765096
.to_name_binding(self.arenas))
50775097
}

‎src/librustc_resolve/resolve_imports.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use syntax_pos::{MultiSpan, Span};
3636

3737
use log::*;
3838

39-
use std::cell::{Cell, RefCell};
39+
use std::cell::Cell;
4040
use std::{mem, ptr};
4141

4242
type Res = def::Res<NodeId>;
@@ -156,12 +156,6 @@ impl<'a> NameResolution<'a> {
156156
}
157157

158158
impl<'a> Resolver<'a> {
159-
fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
160-
-> &'a RefCell<NameResolution<'a>> {
161-
*module.resolutions.borrow_mut().entry((ident.modern(), ns))
162-
.or_insert_with(|| self.arenas.alloc_name_resolution())
163-
}
164-
165159
crate fn resolve_ident_in_module_unadjusted(
166160
&mut self,
167161
module: ModuleOrUniformRoot<'a>,
@@ -239,8 +233,6 @@ impl<'a> Resolver<'a> {
239233
}
240234
};
241235

242-
self.populate_module_if_necessary(module);
243-
244236
let resolution = self.resolution(module, ident, ns)
245237
.try_borrow_mut()
246238
.map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
@@ -1079,7 +1071,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
10791071

10801072
return if all_ns_failed {
10811073
let resolutions = match module {
1082-
ModuleOrUniformRoot::Module(module) => Some(module.resolutions.borrow()),
1074+
ModuleOrUniformRoot::Module(module) => Some(self.resolutions(module).borrow()),
10831075
_ => None,
10841076
};
10851077
let resolutions = resolutions.as_ref().into_iter().flat_map(|r| r.iter());
@@ -1317,8 +1309,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
13171309
}
13181310
};
13191311

1320-
self.populate_module_if_necessary(module);
1321-
13221312
if module.is_trait() {
13231313
self.session.span_err(directive.span, "items in traits are not importable.");
13241314
return;
@@ -1334,7 +1324,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
13341324

13351325
// Ensure that `resolutions` isn't borrowed during `try_define`,
13361326
// since it might get updated via a glob cycle.
1337-
let bindings = module.resolutions.borrow().iter().filter_map(|(&ident, resolution)| {
1327+
let bindings = self.resolutions(module).borrow().iter().filter_map(|(&ident, resolution)| {
13381328
resolution.borrow().binding().map(|binding| (ident, binding))
13391329
}).collect::<Vec<_>>();
13401330
for ((mut ident, ns), binding) in bindings {
@@ -1361,7 +1351,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
13611351

13621352
let mut reexports = Vec::new();
13631353

1364-
for (&(ident, ns), resolution) in module.resolutions.borrow().iter() {
1354+
for (&(ident, ns), resolution) in self.resolutions(module).borrow().iter() {
13651355
let resolution = &mut *resolution.borrow_mut();
13661356
let binding = match resolution.binding {
13671357
Some(binding) => binding,
@@ -1420,8 +1410,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14201410
Some(ModuleOrUniformRoot::Module(module)) => module,
14211411
_ => bug!("module should exist"),
14221412
};
1423-
let resolutions = imported_module.parent.expect("parent should exist")
1424-
.resolutions.borrow();
1413+
let parent_module = imported_module.parent.expect("parent should exist");
1414+
let resolutions = self.resolutions(parent_module).borrow();
14251415
let enum_path_segment_index = directive.module_path.len() - 1;
14261416
let enum_ident = directive.module_path[enum_path_segment_index].ident;
14271417

‎src/test/ui/json-multiple.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-pass
2+
// ignore-pass (different metadata emitted in different modes)
23
// compile-flags: --json=diagnostic-short --json artifacts --error-format=json
34

45
#![crate_type = "lib"]

‎src/test/ui/json-options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// build-pass
2+
// ignore-pass (different metadata emitted in different modes)
23
// compile-flags: --json=diagnostic-short,artifacts --error-format=json
34

45
#![crate_type = "lib"]

0 commit comments

Comments
 (0)
Please sign in to comment.