Move AssocContainer to a metadata table.
This commit is contained in:
parent
927e58d633
commit
ca9f5645f3
@ -1112,7 +1112,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
|
||||
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
|
||||
match self.kind(id) {
|
||||
EntryKind::AssocFn { has_self, .. } => has_self,
|
||||
EntryKind::AssocFn { has_self } => has_self,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -1134,12 +1134,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
|
||||
let name = self.item_name(id);
|
||||
|
||||
let (kind, container, has_self) = match self.kind(id) {
|
||||
EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
|
||||
EntryKind::AssocFn { container, has_self } => (ty::AssocKind::Fn, container, has_self),
|
||||
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
|
||||
_ => bug!("cannot get associated-item of `{:?}`", id),
|
||||
let (kind, has_self) = match self.kind(id) {
|
||||
EntryKind::AssocConst => (ty::AssocKind::Const, false),
|
||||
EntryKind::AssocFn { has_self } => (ty::AssocKind::Fn, has_self),
|
||||
EntryKind::AssocType => (ty::AssocKind::Type, false),
|
||||
_ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
|
||||
};
|
||||
let container = self.root.tables.assoc_container.get(self, id).unwrap();
|
||||
|
||||
ty::AssocItem {
|
||||
name,
|
||||
|
@ -1326,11 +1326,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
let ast_item = tcx.hir().expect_trait_item(def_id.expect_local());
|
||||
self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
|
||||
let trait_item = tcx.associated_item(def_id);
|
||||
self.tables.assoc_container.set(def_id.index, trait_item.container);
|
||||
|
||||
match trait_item.kind {
|
||||
ty::AssocKind::Const => {
|
||||
let container = trait_item.container;
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst);
|
||||
}
|
||||
ty::AssocKind::Fn => {
|
||||
let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind else { bug!() };
|
||||
@ -1345,13 +1345,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
|
||||
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
|
||||
container: ty::AssocItemContainer::TraitContainer,
|
||||
has_self: trait_item.fn_has_self_parameter,
|
||||
});
|
||||
}
|
||||
ty::AssocKind::Type => {
|
||||
self.encode_explicit_item_bounds(def_id);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::TraitContainer));
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType);
|
||||
}
|
||||
}
|
||||
if trait_item.kind == ty::AssocKind::Fn {
|
||||
@ -1366,11 +1365,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
|
||||
self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
|
||||
let impl_item = self.tcx.associated_item(def_id);
|
||||
self.tables.assoc_container.set(def_id.index, impl_item.container);
|
||||
|
||||
match impl_item.kind {
|
||||
ty::AssocKind::Const => {
|
||||
let container = impl_item.container;
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocConst);
|
||||
}
|
||||
ty::AssocKind::Fn => {
|
||||
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
|
||||
@ -1384,12 +1383,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
};
|
||||
self.tables.constness.set(def_id.index, constness);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
|
||||
container: ty::AssocItemContainer::ImplContainer,
|
||||
has_self: impl_item.fn_has_self_parameter,
|
||||
});
|
||||
}
|
||||
ty::AssocKind::Type => {
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::ImplContainer));
|
||||
record!(self.tables.kind[def_id] <- EntryKind::AssocType);
|
||||
}
|
||||
}
|
||||
if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
|
||||
|
@ -394,6 +394,7 @@ define_tables! {
|
||||
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
||||
may_have_doc_links: Table<DefIndex, ()>,
|
||||
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
||||
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
|
||||
@ -423,9 +424,9 @@ enum EntryKind {
|
||||
Generator,
|
||||
Trait,
|
||||
Impl,
|
||||
AssocFn { container: ty::AssocItemContainer, has_self: bool },
|
||||
AssocType(ty::AssocItemContainer),
|
||||
AssocConst(ty::AssocItemContainer),
|
||||
AssocFn { has_self: bool },
|
||||
AssocType,
|
||||
AssocConst,
|
||||
TraitAlias,
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,13 @@ fixed_size_enum! {
|
||||
}
|
||||
}
|
||||
|
||||
fixed_size_enum! {
|
||||
ty::AssocItemContainer {
|
||||
( TraitContainer )
|
||||
( ImplContainer )
|
||||
}
|
||||
}
|
||||
|
||||
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
|
||||
impl FixedSizeEncoding for Option<DefPathHash> {
|
||||
type ByteArray = [u8; 16];
|
||||
|
@ -55,6 +55,7 @@ trivially_parameterized_over_tcx! {
|
||||
crate::middle::exported_symbols::SymbolExportInfo,
|
||||
crate::middle::resolve_lifetime::ObjectLifetimeDefault,
|
||||
crate::mir::ConstQualifs,
|
||||
ty::AssocItemContainer,
|
||||
ty::Generics,
|
||||
ty::ImplPolarity,
|
||||
ty::ReprOptions,
|
||||
|
Loading…
x
Reference in New Issue
Block a user