Introduce repr_options table.
This commit is contained in:
parent
ffaf6f0d0c
commit
f2bf484e3a
3 changed files with 36 additions and 33 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -325,6 +325,7 @@ define_tables! {
|
|||
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
|
||||
expn_that_defined: Table<DefIndex, Lazy<ExpnId>>,
|
||||
unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>,
|
||||
repr_options: Table<DefIndex, Lazy<ReprOptions>>,
|
||||
// `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<VariantData>),
|
||||
Struct(Lazy<VariantData>, ReprOptions),
|
||||
Union(Lazy<VariantData>, ReprOptions),
|
||||
Struct(Lazy<VariantData>),
|
||||
Union(Lazy<VariantData>),
|
||||
Fn(Lazy<FnData>),
|
||||
ForeignFn(Lazy<FnData>),
|
||||
Mod(Lazy<[ModChild]>),
|
||||
|
|
Loading…
Add table
Reference in a new issue