mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Move VariantData to a metadata table.
This commit is contained in:
parent
edd25c37c5
commit
927e58d633
@ -858,19 +858,14 @@ 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) => {
|
||||
data.decode(self)
|
||||
}
|
||||
let adt_kind = match kind {
|
||||
EntryKind::Variant => ty::AdtKind::Enum,
|
||||
EntryKind::Struct => ty::AdtKind::Struct,
|
||||
EntryKind::Union => ty::AdtKind::Union,
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
let adt_kind = match kind {
|
||||
EntryKind::Variant(_) => ty::AdtKind::Enum,
|
||||
EntryKind::Struct(..) => ty::AdtKind::Struct,
|
||||
EntryKind::Union(..) => ty::AdtKind::Union,
|
||||
_ => bug!(),
|
||||
};
|
||||
let data = self.root.tables.variant_data.get(self, index).unwrap().decode(self);
|
||||
|
||||
let variant_did =
|
||||
if adt_kind == ty::AdtKind::Enum { Some(self.local_def_id(index)) } else { None };
|
||||
@ -907,8 +902,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
|
||||
let adt_kind = match kind {
|
||||
EntryKind::Enum => ty::AdtKind::Enum,
|
||||
EntryKind::Struct(_) => ty::AdtKind::Struct,
|
||||
EntryKind::Union(_) => ty::AdtKind::Union,
|
||||
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);
|
||||
@ -1158,8 +1153,8 @@ 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) => {
|
||||
let vdata = data.decode(self);
|
||||
EntryKind::Struct | EntryKind::Variant => {
|
||||
let vdata = self.root.tables.variant_data.get(self, node_id).unwrap().decode(self);
|
||||
vdata.ctor.map(|index| (self.local_def_id(index), vdata.ctor_kind))
|
||||
}
|
||||
_ => None,
|
||||
|
@ -1206,7 +1206,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
};
|
||||
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
|
||||
record!(self.tables.variant_data[def_id] <- data);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Variant);
|
||||
self.tables.constness.set(def_id.index, hir::Constness::Const);
|
||||
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
|
||||
assert!(f.did.is_local());
|
||||
@ -1234,7 +1235,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
};
|
||||
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
|
||||
record!(self.tables.variant_data[def_id] <- data);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Variant);
|
||||
self.tables.constness.set(def_id.index, hir::Constness::Const);
|
||||
if variant.ctor_kind == CtorKind::Fn {
|
||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
||||
@ -1301,8 +1303,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
};
|
||||
|
||||
record!(self.tables.repr_options[def_id] <- adt_def.repr());
|
||||
record!(self.tables.variant_data[def_id] <- data);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Struct);
|
||||
self.tables.constness.set(def_id.index, hir::Constness::Const);
|
||||
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data)));
|
||||
if variant.ctor_kind == CtorKind::Fn {
|
||||
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
|
||||
}
|
||||
@ -1541,24 +1544,26 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
||||
|
||||
let variant = adt_def.non_enum_variant();
|
||||
EntryKind::Struct(self.lazy(VariantData {
|
||||
record!(self.tables.variant_data[def_id] <- VariantData {
|
||||
ctor_kind: variant.ctor_kind,
|
||||
discr: variant.discr,
|
||||
ctor,
|
||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
}))
|
||||
});
|
||||
EntryKind::Struct
|
||||
}
|
||||
hir::ItemKind::Union(..) => {
|
||||
let adt_def = self.tcx.adt_def(def_id);
|
||||
record!(self.tables.repr_options[def_id] <- adt_def.repr());
|
||||
|
||||
let variant = adt_def.non_enum_variant();
|
||||
EntryKind::Union(self.lazy(VariantData {
|
||||
record!(self.tables.variant_data[def_id] <- VariantData {
|
||||
ctor_kind: variant.ctor_kind,
|
||||
discr: variant.discr,
|
||||
ctor: None,
|
||||
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
|
||||
}))
|
||||
});
|
||||
EntryKind::Union
|
||||
}
|
||||
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
||||
self.tables.impl_defaultness.set(def_id.index, *defaultness);
|
||||
|
@ -393,6 +393,7 @@ define_tables! {
|
||||
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
||||
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
||||
may_have_doc_links: Table<DefIndex, ()>,
|
||||
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
|
||||
@ -410,9 +411,9 @@ enum EntryKind {
|
||||
OpaqueTy,
|
||||
Enum,
|
||||
Field,
|
||||
Variant(LazyValue<VariantData>),
|
||||
Struct(LazyValue<VariantData>),
|
||||
Union(LazyValue<VariantData>),
|
||||
Variant,
|
||||
Struct,
|
||||
Union,
|
||||
Fn,
|
||||
ForeignFn,
|
||||
Mod(LazyArray<ModChild>),
|
||||
|
Loading…
Reference in New Issue
Block a user