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