Skip to content

Commit ca9f564

Browse files
committed
Move AssocContainer to a metadata table.
1 parent 927e58d commit ca9f564

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11121112

11131113
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
11141114
match self.kind(id) {
1115-
EntryKind::AssocFn { has_self, .. } => has_self,
1115+
EntryKind::AssocFn { has_self } => has_self,
11161116
_ => false,
11171117
}
11181118
}
@@ -1134,12 +1134,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11341134
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
11351135
let name = self.item_name(id);
11361136

1137-
let (kind, container, has_self) = match self.kind(id) {
1138-
EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
1139-
EntryKind::AssocFn { container, has_self } => (ty::AssocKind::Fn, container, has_self),
1140-
EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
1141-
_ => bug!("cannot get associated-item of `{:?}`", id),
1137+
let (kind, has_self) = match self.kind(id) {
1138+
EntryKind::AssocConst => (ty::AssocKind::Const, false),
1139+
EntryKind::AssocFn { has_self } => (ty::AssocKind::Fn, has_self),
1140+
EntryKind::AssocType => (ty::AssocKind::Type, false),
1141+
_ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
11421142
};
1143+
let container = self.root.tables.assoc_container.get(self, id).unwrap();
11431144

11441145
ty::AssocItem {
11451146
name,

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1326,11 +1326,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13261326
let ast_item = tcx.hir().expect_trait_item(def_id.expect_local());
13271327
self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
13281328
let trait_item = tcx.associated_item(def_id);
1329+
self.tables.assoc_container.set(def_id.index, trait_item.container);
13291330

13301331
match trait_item.kind {
13311332
ty::AssocKind::Const => {
1332-
let container = trait_item.container;
1333-
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
1333+
record!(self.tables.kind[def_id] <- EntryKind::AssocConst);
13341334
}
13351335
ty::AssocKind::Fn => {
13361336
let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind else { bug!() };
@@ -1345,13 +1345,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13451345
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
13461346
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
13471347
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
1348-
container: ty::AssocItemContainer::TraitContainer,
13491348
has_self: trait_item.fn_has_self_parameter,
13501349
});
13511350
}
13521351
ty::AssocKind::Type => {
13531352
self.encode_explicit_item_bounds(def_id);
1354-
record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::TraitContainer));
1353+
record!(self.tables.kind[def_id] <- EntryKind::AssocType);
13551354
}
13561355
}
13571356
if trait_item.kind == ty::AssocKind::Fn {
@@ -1366,11 +1365,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13661365
let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
13671366
self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
13681367
let impl_item = self.tcx.associated_item(def_id);
1368+
self.tables.assoc_container.set(def_id.index, impl_item.container);
13691369

13701370
match impl_item.kind {
13711371
ty::AssocKind::Const => {
1372-
let container = impl_item.container;
1373-
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
1372+
record!(self.tables.kind[def_id] <- EntryKind::AssocConst);
13741373
}
13751374
ty::AssocKind::Fn => {
13761375
let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
@@ -1384,12 +1383,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13841383
};
13851384
self.tables.constness.set(def_id.index, constness);
13861385
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
1387-
container: ty::AssocItemContainer::ImplContainer,
13881386
has_self: impl_item.fn_has_self_parameter,
13891387
});
13901388
}
13911389
ty::AssocKind::Type => {
1392-
record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::ImplContainer));
1390+
record!(self.tables.kind[def_id] <- EntryKind::AssocType);
13931391
}
13941392
}
13951393
if let Some(trait_item_def_id) = impl_item.trait_item_def_id {

compiler/rustc_metadata/src/rmeta/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ define_tables! {
394394
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
395395
may_have_doc_links: Table<DefIndex, ()>,
396396
variant_data: Table<DefIndex, LazyValue<VariantData>>,
397+
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
397398
}
398399

399400
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
@@ -423,9 +424,9 @@ enum EntryKind {
423424
Generator,
424425
Trait,
425426
Impl,
426-
AssocFn { container: ty::AssocItemContainer, has_self: bool },
427-
AssocType(ty::AssocItemContainer),
428-
AssocConst(ty::AssocItemContainer),
427+
AssocFn { has_self: bool },
428+
AssocType,
429+
AssocConst,
429430
TraitAlias,
430431
}
431432

compiler/rustc_metadata/src/rmeta/table.rs

+7
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ fixed_size_enum! {
141141
}
142142
}
143143

144+
fixed_size_enum! {
145+
ty::AssocItemContainer {
146+
( TraitContainer )
147+
( ImplContainer )
148+
}
149+
}
150+
144151
// We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
145152
impl FixedSizeEncoding for Option<DefPathHash> {
146153
type ByteArray = [u8; 16];

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ trivially_parameterized_over_tcx! {
5555
crate::middle::exported_symbols::SymbolExportInfo,
5656
crate::middle::resolve_lifetime::ObjectLifetimeDefault,
5757
crate::mir::ConstQualifs,
58+
ty::AssocItemContainer,
5859
ty::Generics,
5960
ty::ImplPolarity,
6061
ty::ReprOptions,

0 commit comments

Comments
 (0)