]> git.lizzy.rs Git - rust.git/commitdiff
Move AssocContainer to a metadata table.
authorCamille GILLOT <gillot.camille@gmail.com>
Wed, 8 Jun 2022 19:11:08 +0000 (21:11 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Tue, 30 Aug 2022 17:04:58 +0000 (19:04 +0200)
compiler/rustc_metadata/src/rmeta/decoder.rs
compiler/rustc_metadata/src/rmeta/encoder.rs
compiler/rustc_metadata/src/rmeta/mod.rs
compiler/rustc_metadata/src/rmeta/table.rs
compiler/rustc_middle/src/ty/parameterized.rs

index d04bcbfc4b0eba41e7e0f90ecb50e64f808a6596..7e2ade03c73e6c901ce4ed0d40d94105cc79304d 100644 (file)
@@ -1112,7 +1112,7 @@ fn module_expansion(self, id: DefIndex, sess: &Session) -> ExpnId {
 
     fn get_fn_has_self_parameter(self, id: DefIndex) -> bool {
         match self.kind(id) {
-            EntryKind::AssocFn { has_self, .. } => has_self,
+            EntryKind::AssocFn { has_self } => has_self,
             _ => false,
         }
     }
@@ -1134,12 +1134,13 @@ fn get_associated_item_def_ids(
     fn get_associated_item(self, id: DefIndex) -> ty::AssocItem {
         let name = self.item_name(id);
 
-        let (kind, container, has_self) = match self.kind(id) {
-            EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
-            EntryKind::AssocFn { container, has_self } => (ty::AssocKind::Fn, container, has_self),
-            EntryKind::AssocType(container) => (ty::AssocKind::Type, container, false),
-            _ => bug!("cannot get associated-item of `{:?}`", 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),
+            _ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
         };
+        let container = self.root.tables.assoc_container.get(self, id).unwrap();
 
         ty::AssocItem {
             name,
index fa410821f3155218e30259ab0bb6851e5838fbb3..25590af84f64fa5a1b0db4b81a3b1c315fad4c60 100644 (file)
@@ -1326,11 +1326,11 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
         let ast_item = tcx.hir().expect_trait_item(def_id.expect_local());
         self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
         let trait_item = tcx.associated_item(def_id);
+        self.tables.assoc_container.set(def_id.index, trait_item.container);
 
         match trait_item.kind {
             ty::AssocKind::Const => {
-                let container = trait_item.container;
-                record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
+                record!(self.tables.kind[def_id] <- EntryKind::AssocConst);
             }
             ty::AssocKind::Fn => {
                 let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind else { bug!() };
@@ -1345,13 +1345,12 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
                 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 {
-                    container: ty::AssocItemContainer::TraitContainer,
                     has_self: trait_item.fn_has_self_parameter,
                 });
             }
             ty::AssocKind::Type => {
                 self.encode_explicit_item_bounds(def_id);
-                record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::TraitContainer));
+                record!(self.tables.kind[def_id] <- EntryKind::AssocType);
             }
         }
         if trait_item.kind == ty::AssocKind::Fn {
@@ -1366,11 +1365,11 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) {
         let ast_item = self.tcx.hir().expect_impl_item(def_id.expect_local());
         self.tables.impl_defaultness.set(def_id.index, ast_item.defaultness);
         let impl_item = self.tcx.associated_item(def_id);
+        self.tables.assoc_container.set(def_id.index, impl_item.container);
 
         match impl_item.kind {
             ty::AssocKind::Const => {
-                let container = impl_item.container;
-                record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
+                record!(self.tables.kind[def_id] <- EntryKind::AssocConst);
             }
             ty::AssocKind::Fn => {
                 let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind else { bug!() };
@@ -1384,12 +1383,11 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) {
                 };
                 self.tables.constness.set(def_id.index, constness);
                 record!(self.tables.kind[def_id] <- EntryKind::AssocFn {
-                    container: ty::AssocItemContainer::ImplContainer,
                     has_self: impl_item.fn_has_self_parameter,
                 });
             }
             ty::AssocKind::Type => {
-                record!(self.tables.kind[def_id] <- EntryKind::AssocType(ty::AssocItemContainer::ImplContainer));
+                record!(self.tables.kind[def_id] <- EntryKind::AssocType);
             }
         }
         if let Some(trait_item_def_id) = impl_item.trait_item_def_id {
index 6353e04316b1a03a2f47cc4909061e007edf31b9..7537f2c68e59307790f153814e8cff67336825db 100644 (file)
@@ -394,6 +394,7 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
     generator_diagnostic_data: Table<DefIndex, LazyValue<GeneratorDiagnosticData<'static>>>,
     may_have_doc_links: Table<DefIndex, ()>,
     variant_data: Table<DefIndex, LazyValue<VariantData>>,
+    assoc_container: Table<DefIndex, ty::AssocItemContainer>,
 }
 
 #[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
@@ -423,9 +424,9 @@ enum EntryKind {
     Generator,
     Trait,
     Impl,
-    AssocFn { container: ty::AssocItemContainer, has_self: bool },
-    AssocType(ty::AssocItemContainer),
-    AssocConst(ty::AssocItemContainer),
+    AssocFn { has_self: bool },
+    AssocType,
+    AssocConst,
     TraitAlias,
 }
 
index 21841ae2532a7b913f1da7b901c1417ae091cc84..6000df75934885a7f377ca67b3b8985e09604e82 100644 (file)
@@ -141,6 +141,13 @@ impl FixedSizeEncoding for Option<$ty> {
     }
 }
 
+fixed_size_enum! {
+    ty::AssocItemContainer {
+        ( TraitContainer )
+        ( ImplContainer  )
+    }
+}
+
 // We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost.
 impl FixedSizeEncoding for Option<DefPathHash> {
     type ByteArray = [u8; 16];
index 19b8f27bc95caae910d164128766cbefb533a254..ca24c0d1ce386fc5801be18526395b68e3589677 100644 (file)
@@ -55,6 +55,7 @@ impl $crate::ty::ParameterizedOverTcx for $ty {
     crate::middle::exported_symbols::SymbolExportInfo,
     crate::middle::resolve_lifetime::ObjectLifetimeDefault,
     crate::mir::ConstQualifs,
+    ty::AssocItemContainer,
     ty::Generics,
     ty::ImplPolarity,
     ty::ReprOptions,