From 30ae64e51fae5bfbe93199dd1795207444d9931f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 3 Jul 2022 17:49:06 +0200 Subject: [PATCH] Create a table for fn_has_self_parameter. --- compiler/rustc_metadata/src/rmeta/decoder.rs | 14 ++++++-------- compiler/rustc_metadata/src/rmeta/encoder.rs | 14 ++++++++------ compiler/rustc_metadata/src/rmeta/mod.rs | 4 +++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index a29e1edc641d..b62aa95b254b 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -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 { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index fdc25270e971..65f93ce1a25d 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -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); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 0367f244c000..f32fed6ec476 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -397,6 +397,8 @@ define_tables! { assoc_container: Table, macro_definition: Table>, proc_macro: Table, + // Slot is full when there is a self parameter. + fn_has_self_parameter: Table, } #[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)] @@ -426,7 +428,7 @@ enum EntryKind { Generator, Trait, Impl, - AssocFn { has_self: bool }, + AssocFn, AssocType, AssocConst, TraitAlias,