Move VariantData to a metadata table.

This commit is contained in:
Camille GILLOT 2022-06-08 20:59:59 +02:00
parent edd25c37c5
commit 927e58d633
3 changed files with 25 additions and 24 deletions

View File

@ -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 { 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 @@ fn get_adt_def(self, item_id: DefIndex, tcx: TyCtxt<'tcx>) -> ty::AdtDef<'tcx> {
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 @@ fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
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,

View File

@ -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(), 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 @@ fn encode_enum_variant_ctor(&mut self, def: ty::AdtDef<'tcx>, index: VariantIdx)
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 @@ 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.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 @@ 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); .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);

View File

@ -393,6 +393,7 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
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>),