resolve: Pre-compute non-reexport module children
Instead of repeating the same logic by walking HIR during metadata encoding. The only difference is that we are no longer encoding `macro_rules` items, but we never currently need them as a part of this list. They can be encoded separately if this need ever arises. `module_reexports` is also un-querified, because I don't see any reasons to make it a query, only overhead.
This commit is contained in:
parent
9be9b5e09a
commit
7c40a6fb34
16 changed files with 72 additions and 99 deletions
|
@ -931,7 +931,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
/// Builds the reduced graph for a single item in an external crate.
|
||||
fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) {
|
||||
let parent = self.parent_scope.module;
|
||||
let ModChild { ident, res, vis, span, macro_rules, .. } = child;
|
||||
let ModChild { ident, res, vis, span, .. } = child;
|
||||
let res = res.expect_non_local();
|
||||
let expansion = self.parent_scope.expansion;
|
||||
// Record primary definitions.
|
||||
|
@ -964,9 +964,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
|||
_,
|
||||
) => self.r.define(parent, ident, ValueNS, (res, vis, span, expansion)),
|
||||
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => {
|
||||
if !macro_rules {
|
||||
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion))
|
||||
}
|
||||
self.r.define(parent, ident, MacroNS, (res, vis, span, expansion))
|
||||
}
|
||||
Res::Def(
|
||||
DefKind::TyParam
|
||||
|
|
|
@ -1261,10 +1261,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
*module.globs.borrow_mut() = Vec::new();
|
||||
|
||||
if let Some(def_id) = module.opt_def_id() {
|
||||
let mut non_reexports = Vec::new();
|
||||
let mut reexports = Vec::new();
|
||||
|
||||
module.for_each_child(self, |this, ident, _, binding| {
|
||||
if let Some(res) = this.is_reexport(binding) {
|
||||
let res = binding.res().expect_non_local();
|
||||
if !binding.is_import() {
|
||||
non_reexports.push(res.def_id().expect_local());
|
||||
} else if res != def::Res::Err && !binding.is_ambiguity() {
|
||||
let mut reexport_chain = SmallVec::new();
|
||||
let mut next_binding = binding;
|
||||
while let NameBindingKind::Import { binding, import, .. } = next_binding.kind {
|
||||
|
@ -1277,16 +1281,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
res,
|
||||
vis: binding.vis,
|
||||
span: binding.span,
|
||||
macro_rules: false,
|
||||
reexport_chain,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Should be fine because this code is only called for local modules.
|
||||
let def_id = def_id.expect_local();
|
||||
if !non_reexports.is_empty() {
|
||||
self.module_children_non_reexports.insert(def_id, non_reexports);
|
||||
}
|
||||
if !reexports.is_empty() {
|
||||
// Call to `expect_local` should be fine because current
|
||||
// code is only called for local modules.
|
||||
self.reexport_map.insert(def_id.expect_local(), reexports);
|
||||
self.module_children_reexports.insert(def_id, reexports);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -910,7 +910,8 @@ pub struct Resolver<'a, 'tcx> {
|
|||
|
||||
/// `CrateNum` resolutions of `extern crate` items.
|
||||
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
|
||||
reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
|
||||
module_children_non_reexports: LocalDefIdMap<Vec<LocalDefId>>,
|
||||
module_children_reexports: LocalDefIdMap<Vec<ModChild>>,
|
||||
trait_map: NodeMap<Vec<TraitCandidate>>,
|
||||
|
||||
/// A map from nodes to anonymous modules.
|
||||
|
@ -1260,7 +1261,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
lifetimes_res_map: Default::default(),
|
||||
extra_lifetime_params_map: Default::default(),
|
||||
extern_crate_map: Default::default(),
|
||||
reexport_map: FxHashMap::default(),
|
||||
module_children_non_reexports: Default::default(),
|
||||
module_children_reexports: Default::default(),
|
||||
trait_map: NodeMap::default(),
|
||||
underscore_disambiguator: 0,
|
||||
empty_module,
|
||||
|
@ -1387,7 +1389,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let visibilities = self.visibilities;
|
||||
let has_pub_restricted = self.has_pub_restricted;
|
||||
let extern_crate_map = self.extern_crate_map;
|
||||
let reexport_map = self.reexport_map;
|
||||
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
|
||||
let glob_map = self.glob_map;
|
||||
let main_def = self.main_def;
|
||||
|
@ -1399,7 +1400,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
has_pub_restricted,
|
||||
effective_visibilities,
|
||||
extern_crate_map,
|
||||
reexport_map,
|
||||
module_children_non_reexports: self.module_children_non_reexports,
|
||||
module_children_reexports: self.module_children_reexports,
|
||||
glob_map,
|
||||
maybe_unused_trait_imports,
|
||||
main_def,
|
||||
|
@ -1950,20 +1952,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
}
|
||||
self.main_def = Some(MainDefinition { res, is_import, span });
|
||||
}
|
||||
|
||||
// Items that go to reexport table encoded to metadata and visible through it to other crates.
|
||||
fn is_reexport(&self, binding: &NameBinding<'a>) -> Option<def::Res<!>> {
|
||||
if binding.is_import() {
|
||||
let res = binding.res().expect_non_local();
|
||||
// Ambiguous imports are treated as errors at this point and are
|
||||
// not exposed to other crates (see #36837 for more details).
|
||||
if res != def::Res::Err && !binding.is_ambiguity() {
|
||||
return Some(res);
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
fn names_to_string(names: &[Symbol]) -> String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue