about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-02-18 19:09:02 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2022-02-19 15:41:41 +0100
commit7bacdb760f18265b3a5d05406bf2cabb1d33bb5a (patch)
treeccaa4583f665a0d2a6f1d1d27c18f2f6d8f507a2 /compiler/rustc_metadata/src
parentf8fd9733b600e5175fc6810b30f2e0e14e0aaf14 (diff)
downloadrust-7bacdb760f18265b3a5d05406bf2cabb1d33bb5a.tar.gz
rust-7bacdb760f18265b3a5d05406bf2cabb1d33bb5a.zip
Add rendered_const table.
Diffstat (limited to 'compiler/rustc_metadata/src')
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder.rs11
-rw-r--r--compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs2
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs29
-rw-r--r--compiler/rustc_metadata/src/rmeta/mod.rs12
4 files changed, 19 insertions, 35 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs
index 5e298e94fcc..7071a0ee22a 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder.rs
@@ -1193,7 +1193,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
         let name = self.item_name(id);
 
         let (kind, container, has_self) = match self.kind(id) {
-            EntryKind::AssocConst(container, _) => (ty::AssocKind::Const, container, false),
+            EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
             EntryKind::AssocFn(data) => {
                 let data = data.decode(self);
                 (ty::AssocKind::Fn, data.container, data.has_self)
@@ -1411,15 +1411,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
         tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
     }
 
-    fn get_rendered_const(self, id: DefIndex) -> String {
-        match self.kind(id) {
-            EntryKind::AnonConst(data)
-            | EntryKind::Const(data)
-            | EntryKind::AssocConst(_, data) => data.decode(self).0,
-            _ => bug!(),
-        }
-    }
-
     fn get_macro(self, id: DefIndex, sess: &Session) -> MacroDef {
         match self.kind(id) {
             EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)),
diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
index 02652f84318..0a065dc1910 100644
--- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
+++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
@@ -137,6 +137,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
     impl_constness => { table }
     coerce_unsized_info => { table }
     mir_const_qualif => { table }
+    rendered_const => { table }
 
     trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
     adt_def => { cdata.get_adt_def(def_id.index, tcx) }
@@ -154,7 +155,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
     generator_kind => { cdata.generator_kind(def_id.index) }
     item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
     fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
-    rendered_const => { cdata.get_rendered_const(def_id.index) }
     trait_of_item => { cdata.get_trait_of_item(def_id.index) }
     is_mir_available => { cdata.is_item_mir_available(def_id.index) }
     is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index cff1e17a382..fcb2f3acdd6 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -1188,13 +1188,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
                     &(&self.tcx.hir() as &dyn intravisit::Map<'_>),
                     |s| s.print_trait_item(ast_item),
                 );
-                let rendered_const = self.lazy(RenderedConst(rendered));
 
-                record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
-                    container,
-                    rendered_const,
-                ));
+                record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
                 record!(self.tables.mir_const_qualif[def_id] <- mir::ConstQualifs::default());
+                record!(self.tables.rendered_const[def_id] <- rendered);
             }
             ty::AssocKind::Fn => {
                 let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind {
@@ -1256,12 +1253,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
             ty::AssocKind::Const => {
                 if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
                     let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
+                    let const_data = self.encode_rendered_const_for_body(body_id);
 
-                    record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
-                        container,
-                        self.encode_rendered_const_for_body(body_id))
-                    );
+                    record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
                     record!(self.tables.mir_const_qualif[def_id] <- qualifs);
+                    record!(self.tables.rendered_const[def_id] <- const_data);
                 } else {
                     bug!()
                 }
@@ -1385,14 +1381,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
         }
     }
 
-    fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> Lazy<RenderedConst> {
+    fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> String {
         let hir = self.tcx.hir();
         let body = hir.body(body_id);
-        let rendered = rustc_hir_pretty::to_string(&(&hir as &dyn intravisit::Map<'_>), |s| {
+        rustc_hir_pretty::to_string(&(&hir as &dyn intravisit::Map<'_>), |s| {
             s.print_expr(&body.value)
-        });
-        let rendered_const = &RenderedConst(rendered);
-        self.lazy(rendered_const)
+        })
     }
 
     fn encode_info_for_item(&mut self, def_id: DefId, item: &'tcx hir::Item<'tcx>) {
@@ -1407,8 +1401,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
             hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
             hir::ItemKind::Const(_, body_id) => {
                 let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
+                let const_data = self.encode_rendered_const_for_body(body_id);
                 record!(self.tables.mir_const_qualif[def_id] <- qualifs);
-                EntryKind::Const(self.encode_rendered_const_for_body(body_id))
+                record!(self.tables.rendered_const[def_id] <- const_data);
+                EntryKind::Const
             }
             hir::ItemKind::Fn(ref sig, .., body) => {
                 let data = FnData {
@@ -1604,8 +1600,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
         let const_data = self.encode_rendered_const_for_body(body_id);
         let qualifs = self.tcx.mir_const_qualif(def_id);
 
-        record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(const_data));
+        record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst);
         record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
+        record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
         self.encode_item_type(def_id.to_def_id());
     }
 
diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs
index c826800031e..c0cfcf3f702 100644
--- a/compiler/rustc_metadata/src/rmeta/mod.rs
+++ b/compiler/rustc_metadata/src/rmeta/mod.rs
@@ -309,6 +309,7 @@ define_tables! {
     // FIXME(eddyb) perhaps compute this on the fly if cheap enough?
     coerce_unsized_info: Table<DefIndex, Lazy!(ty::adjustment::CoerceUnsizedInfo)>,
     mir_const_qualif: Table<DefIndex, Lazy!(mir::ConstQualifs)>,
+    rendered_const: Table<DefIndex, Lazy!(String)>,
 
     trait_item_def_id: Table<DefIndex, Lazy<DefId>>,
     inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
@@ -325,8 +326,8 @@ define_tables! {
 
 #[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
 enum EntryKind {
-    AnonConst(Lazy<RenderedConst>),
-    Const(Lazy<RenderedConst>),
+    AnonConst,
+    Const,
     ImmStatic,
     MutStatic,
     ForeignImmStatic,
@@ -354,15 +355,10 @@ enum EntryKind {
     Impl,
     AssocFn(Lazy<AssocFnData>),
     AssocType(AssocContainer),
-    AssocConst(AssocContainer, Lazy<RenderedConst>),
+    AssocConst(AssocContainer),
     TraitAlias,
 }
 
-/// Contains a constant which has been rendered to a String.
-/// Used by rustdoc.
-#[derive(Encodable, Decodable)]
-struct RenderedConst(String);
-
 #[derive(MetadataEncodable, MetadataDecodable)]
 struct FnData {
     asyncness: hir::IsAsync,