Create a table for fn_has_self_parameter.

This commit is contained in:
Camille GILLOT 2022-07-03 17:49:06 +02:00
parent 1ddb944311
commit 30ae64e51f
3 changed files with 17 additions and 15 deletions

View File

@ -1115,10 +1115,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
match self.kind(id) {
EntryKind::AssocFn { has_self } => has_self,
_ => false,
}
self.root.tables.fn_has_self_parameter.get(self, id).is_some()
}
fn get_associated_item_def_ids(
@ -1138,12 +1135,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
let name = self.item_name(id);
let (kind, has_self) = match self.kind(id) {
EntryKind::AssocConst => (ty::AssocKind::Const, false),
EntryKind::AssocFn { has_self } => (ty::AssocKind::Fn, has_self),
EntryKind::AssocType => (ty::AssocKind::Type, false),
let kind = match self.kind(id) {
EntryKind::AssocConst => ty::AssocKind::Const,
EntryKind::AssocFn => ty::AssocKind::Fn,
EntryKind::AssocType => ty::AssocKind::Type,
_ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
};
let has_self = self.get_fn_has_self_parameter(id);
let container = self.root.tables.assoc_container.get(self, id).unwrap();
ty::AssocItem {

View File

@ -1344,9 +1344,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
};
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
has_self: trait_item.fn_has_self_parameter,
});
if trait_item.fn_has_self_parameter {
self.tables.fn_has_self_parameter.set(def_id.index, ());
}
record!(self.tables.kind[def_id] <- EntryKind::AssocFn );
}
ty::AssocKind::Type => {
self.encode_explicit_item_bounds(def_id);
@ -1382,9 +1383,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hir::Constness::NotConst
};
self.tables.constness.set(def_id.index, constness);
record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
has_self: impl_item.fn_has_self_parameter,
});
if impl_item.fn_has_self_parameter {
self.tables.fn_has_self_parameter.set(def_id.index, ());
}
record!(self.tables.kind[def_id] <- EntryKind::AssocFn);
}
ty::AssocKind::Type => {
record!(self.tables.kind[def_id] <- EntryKind::AssocType);

View File

@ -397,6 +397,8 @@ define_tables! {
assoc_container: Table<DefIndex, ty::AssocItemContainer>,
macro_definition: Table<DefIndex, LazyValue<ast::MacroDef>>,
proc_macro: Table<DefIndex, MacroKind>,
// Slot is full when there is a self parameter.
fn_has_self_parameter: Table<DefIndex, ()>,
}
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
@ -426,7 +428,7 @@ enum EntryKind {
Generator,
Trait,
Impl,
AssocFn { has_self: bool },
AssocFn,
AssocType,
AssocConst,
TraitAlias,