rustc: Parameterize ty::Visibility over used ID
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
This commit is contained in:
@@ -911,8 +911,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
self.root.tables.generics_of.get(self, item_id).unwrap().decode((self, sess))
|
||||
}
|
||||
|
||||
fn get_visibility(self, id: DefIndex) -> ty::Visibility {
|
||||
self.root.tables.visibility.get(self, id).unwrap().decode(self)
|
||||
fn get_visibility(self, id: DefIndex) -> ty::Visibility<DefId> {
|
||||
self.root
|
||||
.tables
|
||||
.visibility
|
||||
.get(self, id)
|
||||
.unwrap()
|
||||
.decode(self)
|
||||
.map_id(|index| self.local_def_id(index))
|
||||
}
|
||||
|
||||
fn get_trait_item_def_id(self, id: DefIndex) -> Option<DefId> {
|
||||
@@ -1182,7 +1188,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
.map(move |index| respan(self.get_span(index, sess), self.item_name(index)))
|
||||
}
|
||||
|
||||
fn get_struct_field_visibilities(self, id: DefIndex) -> impl Iterator<Item = Visibility> + 'a {
|
||||
fn get_struct_field_visibilities(
|
||||
self,
|
||||
id: DefIndex,
|
||||
) -> impl Iterator<Item = Visibility<DefId>> + 'a {
|
||||
self.root
|
||||
.tables
|
||||
.children
|
||||
|
||||
@@ -210,7 +210,6 @@ provide! { tcx, def_id, other, cdata,
|
||||
lookup_const_stability => { table }
|
||||
lookup_default_body_stability => { table }
|
||||
lookup_deprecation_entry => { table }
|
||||
visibility => { table }
|
||||
unused_generic_params => { table }
|
||||
opt_def_kind => { table_direct }
|
||||
impl_parent => { table }
|
||||
@@ -225,6 +224,7 @@ provide! { tcx, def_id, other, cdata,
|
||||
generator_kind => { table }
|
||||
trait_def => { table }
|
||||
|
||||
visibility => { cdata.get_visibility(def_id.index) }
|
||||
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
|
||||
adt_destructor => {
|
||||
let _ = cdata;
|
||||
@@ -485,7 +485,7 @@ impl CStore {
|
||||
pub fn struct_field_visibilities_untracked(
|
||||
&self,
|
||||
def: DefId,
|
||||
) -> impl Iterator<Item = Visibility> + '_ {
|
||||
) -> impl Iterator<Item = Visibility<DefId>> + '_ {
|
||||
self.get_crate_data(def.krate).get_struct_field_visibilities(def.index)
|
||||
}
|
||||
|
||||
@@ -493,7 +493,7 @@ impl CStore {
|
||||
self.get_crate_data(def.krate).get_ctor_def_id_and_kind(def.index)
|
||||
}
|
||||
|
||||
pub fn visibility_untracked(&self, def: DefId) -> Visibility {
|
||||
pub fn visibility_untracked(&self, def: DefId) -> Visibility<DefId> {
|
||||
self.get_crate_data(def.krate).get_visibility(def.index)
|
||||
}
|
||||
|
||||
|
||||
@@ -1138,7 +1138,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
record!(self.tables.codegen_fn_attrs[def_id] <- self.tcx.codegen_fn_attrs(def_id));
|
||||
}
|
||||
if should_encode_visibility(def_kind) {
|
||||
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
|
||||
let vis =
|
||||
self.tcx.local_visibility(local_id).map_id(|def_id| def_id.local_def_index);
|
||||
record!(self.tables.visibility[def_id] <- vis);
|
||||
}
|
||||
if should_encode_stability(def_kind) {
|
||||
self.encode_stability(def_id);
|
||||
@@ -1727,7 +1729,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
self.tables.opt_def_kind.set(LOCAL_CRATE.as_def_id().index, DefKind::Mod);
|
||||
record!(self.tables.def_span[LOCAL_CRATE.as_def_id()] <- tcx.def_span(LOCAL_CRATE.as_def_id()));
|
||||
self.encode_attrs(LOCAL_CRATE.as_def_id().expect_local());
|
||||
record!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- tcx.visibility(LOCAL_CRATE.as_def_id()));
|
||||
let vis = tcx.local_visibility(CRATE_DEF_ID).map_id(|def_id| def_id.local_def_index);
|
||||
record!(self.tables.visibility[LOCAL_CRATE.as_def_id()] <- vis);
|
||||
if let Some(stability) = stability {
|
||||
record!(self.tables.lookup_stability[LOCAL_CRATE.as_def_id()] <- stability);
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ define_tables! {
|
||||
children: Table<DefIndex, LazyArray<DefIndex>>,
|
||||
|
||||
opt_def_kind: Table<DefIndex, DefKind>,
|
||||
visibility: Table<DefIndex, LazyValue<ty::Visibility>>,
|
||||
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
||||
def_span: Table<DefIndex, LazyValue<Span>>,
|
||||
def_ident_span: Table<DefIndex, LazyValue<Span>>,
|
||||
lookup_stability: Table<DefIndex, LazyValue<attr::Stability>>,
|
||||
|
||||
Reference in New Issue
Block a user