Move VariantData to a metadata table.
This commit is contained in:
parent
edd25c37c5
commit
927e58d633
@ -858,19 +858,14 @@ fn load_proc_macro(self, id: DefIndex, sess: &Session) -> SyntaxExtension {
|
||||
}
|
||||
|
||||
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 @@ fn get_adt_def(self, item_id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::AdtDef<'tcx> {
|
||||
|
||||
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 @@ fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
|
||||
|
||||
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 @@ fn encode_enum_variant_info(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx)
|
||||
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 @@ fn encode_enum_variant_ctor(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx)
|
||||
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 @@ fn encode_struct_ctor(&mut self, adt_def: ty::AdtDef<'tcx>, def_id: DefId) {
|
||||
};
|
||||
|
||||
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 @@ fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'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 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
|
||||
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