diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 6993ffbeddf..cccf5fc8459 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -942,7 +942,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef { let data = match kind { - EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => { + EntryKind::Variant(data) | EntryKind::Struct(data) | EntryKind::Union(data) => { data.decode(self) } _ => bug!(), @@ -988,12 +988,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { let kind = self.kind(item_id); let did = self.local_def_id(item_id); - let (adt_kind, repr) = match kind { - EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr), - EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr), - EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr), + let adt_kind = match kind { + EntryKind::Enum => ty::AdtKind::Enum, + EntryKind::Struct(_) => ty::AdtKind::Struct, + EntryKind::Union(_) => ty::AdtKind::Union, _ => bug!("get_adt_def called on a non-ADT {:?}", did), }; + let repr = self.root.tables.repr_options.get(self, item_id).unwrap().decode(self); let variants = if let ty::AdtKind::Enum = adt_kind { self.root @@ -1171,7 +1172,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { callback(exp); } } - EntryKind::Enum(..) | EntryKind::Trait(..) => {} + EntryKind::Enum | EntryKind::Trait(..) => {} _ => bug!("`for_each_module_child` is called on a non-module: {:?}", self.def_kind(id)), } } @@ -1186,7 +1187,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId { match self.kind(id) { - EntryKind::Mod(_) | EntryKind::Enum(_) | EntryKind::Trait(_) => { + EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait(_) => { self.get_expn_that_defined(id, sess) } _ => panic!("Expected module, found {:?}", self.local_def_id(id)), @@ -1239,7 +1240,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn get_ctor_def_id_and_kind(self, node_id: DefIndex) -> Option<(DefId, CtorKind)> { match self.kind(node_id) { - EntryKind::Struct(data, _) | EntryKind::Variant(data) => { + EntryKind::Struct(data) | EntryKind::Variant(data) => { let vdata = data.decode(self); vdata.ctor.map(|index| (self.local_def_id(index), vdata.ctor_kind)) } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index cb3932eba35..db2defab445 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1154,7 +1154,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { is_non_exhaustive: variant.is_field_list_non_exhaustive(), }; - record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr())); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); + record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data))); self.encode_item_type(def_id); if variant.ctor_kind == CtorKind::Fn { record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id)); @@ -1418,10 +1419,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { self.encode_explicit_item_bounds(def_id); EntryKind::OpaqueTy } - hir::ItemKind::Enum(..) => EntryKind::Enum(self.tcx.adt_def(def_id).repr()), + hir::ItemKind::Enum(..) => { + let adt_def = self.tcx.adt_def(def_id); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); + EntryKind::Enum + } hir::ItemKind::Struct(ref struct_def, _) => { let adt_def = self.tcx.adt_def(def_id); - let variant = adt_def.non_enum_variant(); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); // Encode def_ids for each field and method // for methods, write all the stuff get_trait_method @@ -1430,29 +1435,25 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { .ctor_hir_id() .map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index); - EntryKind::Struct( - self.lazy(VariantData { - ctor_kind: variant.ctor_kind, - discr: variant.discr, - ctor, - is_non_exhaustive: variant.is_field_list_non_exhaustive(), - }), - adt_def.repr(), - ) + let variant = adt_def.non_enum_variant(); + EntryKind::Struct(self.lazy(VariantData { + ctor_kind: variant.ctor_kind, + discr: variant.discr, + ctor, + is_non_exhaustive: variant.is_field_list_non_exhaustive(), + })) } hir::ItemKind::Union(..) => { let adt_def = self.tcx.adt_def(def_id); - let variant = adt_def.non_enum_variant(); + record!(self.tables.repr_options[def_id] <- adt_def.repr()); - EntryKind::Union( - self.lazy(VariantData { - ctor_kind: variant.ctor_kind, - discr: variant.discr, - ctor: None, - is_non_exhaustive: variant.is_field_list_non_exhaustive(), - }), - adt_def.repr(), - ) + let variant = adt_def.non_enum_variant(); + EntryKind::Union(self.lazy(VariantData { + ctor_kind: variant.ctor_kind, + discr: variant.discr, + ctor: None, + is_non_exhaustive: variant.is_field_list_non_exhaustive(), + })) } hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => { record!(self.tables.impl_defaultness[def_id] <- defaultness); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 06581033129..1d09d8d555a 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -325,6 +325,7 @@ define_tables! { inherent_impls: Table>, expn_that_defined: Table>, unused_generic_params: Table>>, + repr_options: Table>, // `def_keys` and `def_path_hashes` represent a lazy version of a // `DefPathTable`. This allows us to avoid deserializing an entire // `DefPathTable` up front, since we may only ever use a few @@ -347,11 +348,11 @@ enum EntryKind { TypeParam, ConstParam, OpaqueTy, - Enum(ReprOptions), + Enum, Field, Variant(Lazy), - Struct(Lazy, ReprOptions), - Union(Lazy, ReprOptions), + Struct(Lazy), + Union(Lazy), Fn(Lazy), ForeignFn(Lazy), Mod(Lazy<[ModChild]>),