Calculate visibilities once in resolve
Then use them through a query based on resolver outputs
This commit is contained in:
parent
cb2462c53f
commit
cee5521a03
26 changed files with 323 additions and 409 deletions
|
@ -944,7 +944,8 @@ pub struct Resolver<'a> {
|
|||
|
||||
/// Maps glob imports to the names of items actually imported.
|
||||
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
|
||||
|
||||
/// Visibilities in "lowered" form, for all entities that have them.
|
||||
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
|
||||
used_imports: FxHashSet<(NodeId, Namespace)>,
|
||||
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
|
||||
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
|
||||
|
@ -1008,10 +1009,6 @@ pub struct Resolver<'a> {
|
|||
/// Features enabled for this crate.
|
||||
active_features: FxHashSet<Symbol>,
|
||||
|
||||
/// Stores enum visibilities to properly build a reduced graph
|
||||
/// when visiting the correspondent variants.
|
||||
variant_vis: DefIdMap<ty::Visibility>,
|
||||
|
||||
lint_buffer: LintBuffer,
|
||||
|
||||
next_node_id: NodeId,
|
||||
|
@ -1028,6 +1025,9 @@ pub struct Resolver<'a> {
|
|||
invocation_parents: FxHashMap<ExpnId, LocalDefId>,
|
||||
|
||||
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
||||
/// Some way to know that we are in a *trait* impl in `visit_assoc_item`.
|
||||
/// FIXME: Replace with a more general AST map (together with some other fields).
|
||||
trait_impl_items: FxHashSet<LocalDefId>,
|
||||
}
|
||||
|
||||
/// Nothing really interesting here; it just provides memory for the rest of the crate.
|
||||
|
@ -1195,7 +1195,8 @@ impl<'a> Resolver<'a> {
|
|||
metadata_loader: &'a MetadataLoaderDyn,
|
||||
arenas: &'a ResolverArenas<'a>,
|
||||
) -> Resolver<'a> {
|
||||
let root_def_id = DefId::local(CRATE_DEF_INDEX);
|
||||
let root_local_def_id = LocalDefId { local_def_index: CRATE_DEF_INDEX };
|
||||
let root_def_id = root_local_def_id.to_def_id();
|
||||
let root_module_kind = ModuleKind::Def(DefKind::Mod, root_def_id, kw::Invalid);
|
||||
let graph_root = arenas.alloc_module(ModuleData {
|
||||
no_implicit_prelude: session.contains_name(&krate.attrs, sym::no_implicit_prelude),
|
||||
|
@ -1213,11 +1214,14 @@ impl<'a> Resolver<'a> {
|
|||
)
|
||||
});
|
||||
let mut module_map = FxHashMap::default();
|
||||
module_map.insert(LocalDefId { local_def_index: CRATE_DEF_INDEX }, graph_root);
|
||||
module_map.insert(root_local_def_id, graph_root);
|
||||
|
||||
let definitions = Definitions::new(crate_name, session.local_crate_disambiguator());
|
||||
let root = definitions.get_root_def();
|
||||
|
||||
let mut visibilities = FxHashMap::default();
|
||||
visibilities.insert(root_local_def_id, ty::Visibility::Public);
|
||||
|
||||
let mut def_id_to_span = IndexVec::default();
|
||||
assert_eq!(def_id_to_span.push(rustc_span::DUMMY_SP), root);
|
||||
let mut def_id_to_node_id = IndexVec::default();
|
||||
|
@ -1290,7 +1294,7 @@ impl<'a> Resolver<'a> {
|
|||
ast_transform_scopes: FxHashMap::default(),
|
||||
|
||||
glob_map: Default::default(),
|
||||
|
||||
visibilities,
|
||||
used_imports: FxHashSet::default(),
|
||||
maybe_unused_trait_imports: Default::default(),
|
||||
maybe_unused_extern_crates: Vec::new(),
|
||||
|
@ -1339,7 +1343,6 @@ impl<'a> Resolver<'a> {
|
|||
.map(|(feat, ..)| *feat)
|
||||
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
|
||||
.collect(),
|
||||
variant_vis: Default::default(),
|
||||
lint_buffer: LintBuffer::default(),
|
||||
next_node_id: NodeId::from_u32(1),
|
||||
def_id_to_span,
|
||||
|
@ -1348,6 +1351,7 @@ impl<'a> Resolver<'a> {
|
|||
placeholder_field_indices: Default::default(),
|
||||
invocation_parents,
|
||||
next_disambiguator: Default::default(),
|
||||
trait_impl_items: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1371,6 +1375,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
pub fn into_outputs(self) -> ResolverOutputs {
|
||||
let definitions = self.definitions;
|
||||
let visibilities = self.visibilities;
|
||||
let extern_crate_map = self.extern_crate_map;
|
||||
let export_map = self.export_map;
|
||||
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
|
||||
|
@ -1379,6 +1384,7 @@ impl<'a> Resolver<'a> {
|
|||
ResolverOutputs {
|
||||
definitions: definitions,
|
||||
cstore: Box::new(self.crate_loader.into_cstore()),
|
||||
visibilities,
|
||||
extern_crate_map,
|
||||
export_map,
|
||||
glob_map,
|
||||
|
@ -1396,6 +1402,7 @@ impl<'a> Resolver<'a> {
|
|||
ResolverOutputs {
|
||||
definitions: self.definitions.clone(),
|
||||
cstore: Box::new(self.cstore().clone()),
|
||||
visibilities: self.visibilities.clone(),
|
||||
extern_crate_map: self.extern_crate_map.clone(),
|
||||
export_map: self.export_map.clone(),
|
||||
glob_map: self.glob_map.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue