Introduce repr_options table.
This commit is contained in:
parent
ffaf6f0d0c
commit
f2bf484e3a
@ -942,7 +942,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
|
|
||||||
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
|
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
|
||||||
let data = match kind {
|
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)
|
data.decode(self)
|
||||||
}
|
}
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
@ -988,12 +988,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
let kind = self.kind(item_id);
|
let kind = self.kind(item_id);
|
||||||
let did = self.local_def_id(item_id);
|
let did = self.local_def_id(item_id);
|
||||||
|
|
||||||
let (adt_kind, repr) = match kind {
|
let adt_kind = match kind {
|
||||||
EntryKind::Enum(repr) => (ty::AdtKind::Enum, repr),
|
EntryKind::Enum => ty::AdtKind::Enum,
|
||||||
EntryKind::Struct(_, repr) => (ty::AdtKind::Struct, repr),
|
EntryKind::Struct(_) => ty::AdtKind::Struct,
|
||||||
EntryKind::Union(_, repr) => (ty::AdtKind::Union, repr),
|
EntryKind::Union(_) => ty::AdtKind::Union,
|
||||||
_ => bug!("get_adt_def called on a non-ADT {:?}", did),
|
_ => 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 {
|
let variants = if let ty::AdtKind::Enum = adt_kind {
|
||||||
self.root
|
self.root
|
||||||
@ -1171,7 +1172,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
|||||||
callback(exp);
|
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)),
|
_ => 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 {
|
fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
|
||||||
match self.kind(id) {
|
match self.kind(id) {
|
||||||
EntryKind::Mod(_) | EntryKind::Enum(_) | EntryKind::Trait(_) => {
|
EntryKind::Mod(_) | EntryKind::Enum | EntryKind::Trait(_) => {
|
||||||
self.get_expn_that_defined(id, sess)
|
self.get_expn_that_defined(id, sess)
|
||||||
}
|
}
|
||||||
_ => panic!("Expected module, found {:?}", self.local_def_id(id)),
|
_ => 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)> {
|
fn get_ctor_def_id_and_kind(self, node_id: DefIndex) -> Option<(DefId, CtorKind)> {
|
||||||
match self.kind(node_id) {
|
match self.kind(node_id) {
|
||||||
EntryKind::Struct(data, _) | EntryKind::Variant(data) => {
|
EntryKind::Struct(data) | EntryKind::Variant(data) => {
|
||||||
let vdata = data.decode(self);
|
let vdata = data.decode(self);
|
||||||
vdata.ctor.map(|index| (self.local_def_id(index), vdata.ctor_kind))
|
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(),
|
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);
|
self.encode_item_type(def_id);
|
||||||
if variant.ctor_kind == CtorKind::Fn {
|
if variant.ctor_kind == CtorKind::Fn {
|
||||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
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);
|
self.encode_explicit_item_bounds(def_id);
|
||||||
EntryKind::OpaqueTy
|
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, _) => {
|
hir::ItemKind::Struct(ref struct_def, _) => {
|
||||||
let adt_def = self.tcx.adt_def(def_id);
|
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
|
// Encode def_ids for each field and method
|
||||||
// for methods, write all the stuff get_trait_method
|
// for methods, write all the stuff get_trait_method
|
||||||
@ -1430,29 +1435,25 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
.ctor_hir_id()
|
.ctor_hir_id()
|
||||||
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
||||||
|
|
||||||
EntryKind::Struct(
|
let variant = adt_def.non_enum_variant();
|
||||||
self.lazy(VariantData {
|
EntryKind::Struct(self.lazy(VariantData {
|
||||||
ctor_kind: variant.ctor_kind,
|
ctor_kind: variant.ctor_kind,
|
||||||
discr: variant.discr,
|
discr: variant.discr,
|
||||||
ctor,
|
ctor,
|
||||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||||
}),
|
}))
|
||||||
adt_def.repr(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(..) => {
|
hir::ItemKind::Union(..) => {
|
||||||
let adt_def = self.tcx.adt_def(def_id);
|
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(
|
let variant = adt_def.non_enum_variant();
|
||||||
self.lazy(VariantData {
|
EntryKind::Union(self.lazy(VariantData {
|
||||||
ctor_kind: variant.ctor_kind,
|
ctor_kind: variant.ctor_kind,
|
||||||
discr: variant.discr,
|
discr: variant.discr,
|
||||||
ctor: None,
|
ctor: None,
|
||||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||||
}),
|
}))
|
||||||
adt_def.repr(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
||||||
record!(self.tables.impl_defaultness[def_id] <- defaultness);
|
record!(self.tables.impl_defaultness[def_id] <- defaultness);
|
||||||
|
@ -325,6 +325,7 @@ define_tables! {
|
|||||||
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
|
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
|
||||||
expn_that_defined: Table<DefIndex, Lazy<ExpnId>>,
|
expn_that_defined: Table<DefIndex, Lazy<ExpnId>>,
|
||||||
unused_generic_params: Table<DefIndex, Lazy<FiniteBitSet<u32>>>,
|
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
|
// `def_keys` and `def_path_hashes` represent a lazy version of a
|
||||||
// `DefPathTable`. This allows us to avoid deserializing an entire
|
// `DefPathTable`. This allows us to avoid deserializing an entire
|
||||||
// `DefPathTable` up front, since we may only ever use a few
|
// `DefPathTable` up front, since we may only ever use a few
|
||||||
@ -347,11 +348,11 @@ enum EntryKind {
|
|||||||
TypeParam,
|
TypeParam,
|
||||||
ConstParam,
|
ConstParam,
|
||||||
OpaqueTy,
|
OpaqueTy,
|
||||||
Enum(ReprOptions),
|
Enum,
|
||||||
Field,
|
Field,
|
||||||
Variant(Lazy<VariantData>),
|
Variant(Lazy<VariantData>),
|
||||||
Struct(Lazy<VariantData>, ReprOptions),
|
Struct(Lazy<VariantData>),
|
||||||
Union(Lazy<VariantData>, ReprOptions),
|
Union(Lazy<VariantData>),
|
||||||
Fn(Lazy<FnData>),
|
Fn(Lazy<FnData>),
|
||||||
ForeignFn(Lazy<FnData>),
|
ForeignFn(Lazy<FnData>),
|
||||||
Mod(Lazy<[ModChild]>),
|
Mod(Lazy<[ModChild]>),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user