mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +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 {
|
fn get_variant(self, kind: &EntryKind, index: DefIndex, parent_did: DefId) -> ty::VariantDef {
|
||||||
let data = match kind {
|
let adt_kind = match kind {
|
||||||
EntryKind::Variant(data) | EntryKind::Struct(data) | EntryKind::Union(data) => {
|
EntryKind::Variant => ty::AdtKind::Enum,
|
||||||
data.decode(self)
|
EntryKind::Struct => ty::AdtKind::Struct,
|
||||||
}
|
EntryKind::Union => ty::AdtKind::Union,
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let adt_kind = match kind {
|
let data = self.root.tables.variant_data.get(self, index).unwrap().decode(self);
|
||||||
EntryKind::Variant(_) => ty::AdtKind::Enum,
|
|
||||||
EntryKind::Struct(..) => ty::AdtKind::Struct,
|
|
||||||
EntryKind::Union(..) => ty::AdtKind::Union,
|
|
||||||
_ => bug!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let variant_did =
|
let variant_did =
|
||||||
if adt_kind == ty::AdtKind::Enum { Some(self.local_def_id(index)) } else { None };
|
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 {
|
let adt_kind = match kind {
|
||||||
EntryKind::Enum => ty::AdtKind::Enum,
|
EntryKind::Enum => ty::AdtKind::Enum,
|
||||||
EntryKind::Struct(_) => ty::AdtKind::Struct,
|
EntryKind::Struct => ty::AdtKind::Struct,
|
||||||
EntryKind::Union(_) => ty::AdtKind::Union,
|
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 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)> {
|
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 | EntryKind::Variant => {
|
||||||
let vdata = data.decode(self);
|
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))
|
vdata.ctor.map(|index| (self.local_def_id(index), vdata.ctor_kind))
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -1206,7 +1206,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::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);
|
self.tables.constness.set(def_id.index, hir::Constness::Const);
|
||||||
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
|
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
|
||||||
assert!(f.did.is_local());
|
assert!(f.did.is_local());
|
||||||
@ -1234,7 +1235,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::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);
|
self.tables.constness.set(def_id.index, hir::Constness::Const);
|
||||||
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));
|
||||||
@ -1301,8 +1303,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
record!(self.tables.repr_options[def_id] <- adt_def.repr());
|
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);
|
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 {
|
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));
|
||||||
}
|
}
|
||||||
@ -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);
|
.map(|ctor_hir_id| self.tcx.hir().local_def_id(ctor_hir_id).local_def_index);
|
||||||
|
|
||||||
let variant = adt_def.non_enum_variant();
|
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,
|
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(),
|
||||||
}))
|
});
|
||||||
|
EntryKind::Struct
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(..) => {
|
hir::ItemKind::Union(..) => {
|
||||||
let adt_def = self.tcx.adt_def(def_id);
|
let adt_def = self.tcx.adt_def(def_id);
|
||||||
record!(self.tables.repr_options[def_id] <- adt_def.repr());
|
record!(self.tables.repr_options[def_id] <- adt_def.repr());
|
||||||
|
|
||||||
let variant = adt_def.non_enum_variant();
|
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,
|
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(),
|
||||||
}))
|
});
|
||||||
|
EntryKind::Union
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
|
||||||
self.tables.impl_defaultness.set(def_id.index, *defaultness);
|
self.tables.impl_defaultness.set(def_id.index, *defaultness);
|
||||||
|
@ -393,6 +393,7 @@ define_tables! {
|
|||||||
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
proc_macro_quoted_spans: Table<usize, LazyValue<Span>>,
|
||||||
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
|
||||||
may_have_doc_links: Table<DefIndex, ()>,
|
may_have_doc_links: Table<DefIndex, ()>,
|
||||||
|
variant_data: Table<DefIndex, LazyValue<VariantData>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
|
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
|
||||||
@ -410,9 +411,9 @@ enum EntryKind {
|
|||||||
OpaqueTy,
|
OpaqueTy,
|
||||||
Enum,
|
Enum,
|
||||||
Field,
|
Field,
|
||||||
Variant(LazyValue<VariantData>),
|
Variant,
|
||||||
Struct(LazyValue<VariantData>),
|
Struct,
|
||||||
Union(LazyValue<VariantData>),
|
Union,
|
||||||
Fn,
|
Fn,
|
||||||
ForeignFn,
|
ForeignFn,
|
||||||
Mod(LazyArray<ModChild>),
|
Mod(LazyArray<ModChild>),
|
||||||
|
Loading…
Reference in New Issue
Block a user