Skip to content

Commit f2bf484

Browse files
committed
Introduce repr_options table.
1 parent ffaf6f0 commit f2bf484

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
942942

943943
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
944944
let data = match kind {
945-
EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => {
945+
EntryKind::Variant(data) | EntryKind::Struct(data) | EntryKind::Union(data) => {
946946
data.decode(self)
947947
}
948948
_ => bug!(),
@@ -988,12 +988,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
988988
let kind = self.kind(item_id);
989989
let did = self.local_def_id(item_id);
990990

991-
let (adt_kind, repr) = match kind {
992-
EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr),
993-
EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr),
994-
EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr),
991+
let adt_kind = match kind {
992+
EntryKind::Enum => ty::AdtKind::Enum,
993+
EntryKind::Struct(_) => ty::AdtKind::Struct,
994+
EntryKind::Union(_) => ty::AdtKind::Union,
995995
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
996996
};
997+
let repr = self.root.tables.repr_options.get(self, item_id).unwrap().decode(self);
997998

998999
let variants = if let ty::AdtKind::Enum = adt_kind {
9991000
self.root
@@ -1171,7 +1172,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11711172
callback(exp);
11721173
}
11731174
}
1174-
EntryKind::Enum(..) | EntryKind::Trait(..) => {}
1175+
EntryKind::Enum | EntryKind::Trait(..) => {}
11751176
_ => bug!("`for_each_module_child` is called on a non-module: {:?}", self.def_kind(id)),
11761177
}
11771178
}
@@ -1186,7 +1187,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11861187

11871188
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
11881189
match self.kind(id) {
1189-
EntryKind::Mod(_) | EntryKind::Enum(_) | EntryKind::Trait(_) => {
1190+
EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait(_) => {
11901191
self.get_expn_that_defined(id, sess)
11911192
}
11921193
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
@@ -1239,7 +1240,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12391240

12401241
fn get_ctor_def_id_and_kind(self, node_id: DefIndex) -> Option<(DefId, CtorKind)> {
12411242
match self.kind(node_id) {
1242-
EntryKind::Struct(data, _) | EntryKind::Variant(data) => {
1243+
EntryKind::Struct(data) | EntryKind::Variant(data) => {
12431244
let vdata = data.decode(self);
12441245
vdata.ctor.map(|index| (self.local_def_id(index), vdata.ctor_kind))
12451246
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11541154
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
11551155
};
11561156

1157-
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr()));
1157+
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1158+
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data)));
11581159
self.encode_item_type(def_id);
11591160
if variant.ctor_kind == CtorKind::Fn {
11601161
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@@ -1418,10 +1419,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14181419
self.encode_explicit_item_bounds(def_id);
14191420
EntryKind::OpaqueTy
14201421
}
1421-
hir::ItemKind::Enum(..) => EntryKind::Enum(self.tcx.adt_def(def_id).repr()),
1422+
hir::ItemKind::Enum(..) => {
1423+
let adt_def = self.tcx.adt_def(def_id);
1424+
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1425+
EntryKind::Enum
1426+
}
14221427
hir::ItemKind::Struct(ref struct_def, _) => {
14231428
let adt_def = self.tcx.adt_def(def_id);
1424-
let variant = adt_def.non_enum_variant();
1429+
record!(self.tables.repr_options[def_id] <- adt_def.repr());
14251430

14261431
// Encode def_ids for each field and method
14271432
// for methods, write all the stuff get_trait_method
@@ -1430,29 +1435,25 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14301435
.ctor_hir_id()
14311436
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
14321437

1433-
EntryKind::Struct(
1434-
self.lazy(VariantData {
1435-
ctor_kind: variant.ctor_kind,
1436-
discr: variant.discr,
1437-
ctor,
1438-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1439-
}),
1440-
adt_def.repr(),
1441-
)
1438+
let variant = adt_def.non_enum_variant();
1439+
EntryKind::Struct(self.lazy(VariantData {
1440+
ctor_kind: variant.ctor_kind,
1441+
discr: variant.discr,
1442+
ctor,
1443+
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1444+
}))
14421445
}
14431446
hir::ItemKind::Union(..) => {
14441447
let adt_def = self.tcx.adt_def(def_id);
1445-
let variant = adt_def.non_enum_variant();
1448+
record!(self.tables.repr_options[def_id] <- adt_def.repr());
14461449

1447-
EntryKind::Union(
1448-
self.lazy(VariantData {
1449-
ctor_kind: variant.ctor_kind,
1450-
discr: variant.discr,
1451-
ctor: None,
1452-
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1453-
}),
1454-
adt_def.repr(),
1455-
)
1450+
let variant = adt_def.non_enum_variant();
1451+
EntryKind::Union(self.lazy(VariantData {
1452+
ctor_kind: variant.ctor_kind,
1453+
discr: variant.discr,
1454+
ctor: None,
1455+
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
1456+
}))
14561457
}
14571458
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
14581459
record!(self.tables.impl_defaultness[def_id] <- defaultness);

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ define_tables! {
325325
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
326326
expn_that_defined: Table<DefIndex, Lazy<ExpnId>>,
327327
unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>,
328+
repr_options: Table<DefIndex, Lazy<ReprOptions>>,
328329
// `def_keys` and `def_path_hashes` represent a lazy version of a
329330
// `DefPathTable`. This allows us to avoid deserializing an entire
330331
// `DefPathTable` up front, since we may only ever use a few
@@ -347,11 +348,11 @@ enum EntryKind {
347348
TypeParam,
348349
ConstParam,
349350
OpaqueTy,
350-
Enum(ReprOptions),
351+
Enum,
351352
Field,
352353
Variant(Lazy<VariantData>),
353-
Struct(Lazy<VariantData>, ReprOptions),
354-
Union(Lazy<VariantData>, ReprOptions),
354+
Struct(Lazy<VariantData>),
355+
Union(Lazy<VariantData>),
355356
Fn(Lazy<FnData>),
356357
ForeignFn(Lazy<FnData>),
357358
Mod(Lazy<[ModChild]>),

0 commit comments

Comments
 (0)