Skip to content

Commit 7bacdb7

Browse files
committed
Add rendered_const table.
1 parent f8fd973 commit 7bacdb7

File tree

4 files changed

+19
-35
lines changed

4 files changed

+19
-35
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
11931193
let name = self.item_name(id);
11941194

11951195
let (kind, container, has_self) = match self.kind(id) {
1196-
EntryKind::AssocConst(container, _) => (ty::AssocKind::Const, container, false),
1196+
EntryKind::AssocConst(container) => (ty::AssocKind::Const, container, false),
11971197
EntryKind::AssocFn(data) => {
11981198
let data = data.decode(self);
11991199
(ty::AssocKind::Fn, data.container, data.has_self)
@@ -1411,15 +1411,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
14111411
tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
14121412
}
14131413

1414-
fn get_rendered_const(self, id: DefIndex) -> String {
1415-
match self.kind(id) {
1416-
EntryKind::AnonConst(data)
1417-
| EntryKind::Const(data)
1418-
| EntryKind::AssocConst(_, data) => data.decode(self).0,
1419-
_ => bug!(),
1420-
}
1421-
}
1422-
14231414
fn get_macro(self, id: DefIndex, sess: &Session) -> MacroDef {
14241415
match self.kind(id) {
14251416
EntryKind::MacroDef(macro_def) => macro_def.decode((self, sess)),

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
137137
impl_constness => { table }
138138
coerce_unsized_info => { table }
139139
mir_const_qualif => { table }
140+
rendered_const => { table }
140141

141142
trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
142143
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
@@ -154,7 +155,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
154155
generator_kind => { cdata.generator_kind(def_id.index) }
155156
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
156157
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
157-
rendered_const => { cdata.get_rendered_const(def_id.index) }
158158
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
159159
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
160160
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(def_id.index) }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,13 +1188,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11881188
&(&self.tcx.hir() as &dyn intravisit::Map<'_>),
11891189
|s| s.print_trait_item(ast_item),
11901190
);
1191-
let rendered_const = self.lazy(RenderedConst(rendered));
11921191

1193-
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
1194-
container,
1195-
rendered_const,
1196-
));
1192+
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
11971193
record!(self.tables.mir_const_qualif[def_id] <- mir::ConstQualifs::default());
1194+
record!(self.tables.rendered_const[def_id] <- rendered);
11981195
}
11991196
ty::AssocKind::Fn => {
12001197
let fn_data = if let hir::TraitItemKind::Fn(m_sig, m) = &ast_item.kind {
@@ -1256,12 +1253,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12561253
ty::AssocKind::Const => {
12571254
if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
12581255
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
1256+
let const_data = self.encode_rendered_const_for_body(body_id);
12591257

1260-
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(
1261-
container,
1262-
self.encode_rendered_const_for_body(body_id))
1263-
);
1258+
record!(self.tables.kind[def_id] <- EntryKind::AssocConst(container));
12641259
record!(self.tables.mir_const_qualif[def_id] <- qualifs);
1260+
record!(self.tables.rendered_const[def_id] <- const_data);
12651261
} else {
12661262
bug!()
12671263
}
@@ -1385,14 +1381,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13851381
}
13861382
}
13871383

1388-
fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> Lazy<RenderedConst> {
1384+
fn encode_rendered_const_for_body(&mut self, body_id: hir::BodyId) -> String {
13891385
let hir = self.tcx.hir();
13901386
let body = hir.body(body_id);
1391-
let rendered = rustc_hir_pretty::to_string(&(&hir as &dyn intravisit::Map<'_>), |s| {
1387+
rustc_hir_pretty::to_string(&(&hir as &dyn intravisit::Map<'_>), |s| {
13921388
s.print_expr(&body.value)
1393-
});
1394-
let rendered_const = &RenderedConst(rendered);
1395-
self.lazy(rendered_const)
1389+
})
13961390
}
13971391

13981392
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> {
14071401
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
14081402
hir::ItemKind::Const(_, body_id) => {
14091403
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
1404+
let const_data = self.encode_rendered_const_for_body(body_id);
14101405
record!(self.tables.mir_const_qualif[def_id] <- qualifs);
1411-
EntryKind::Const(self.encode_rendered_const_for_body(body_id))
1406+
record!(self.tables.rendered_const[def_id] <- const_data);
1407+
EntryKind::Const
14121408
}
14131409
hir::ItemKind::Fn(ref sig, .., body) => {
14141410
let data = FnData {
@@ -1604,8 +1600,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16041600
let const_data = self.encode_rendered_const_for_body(body_id);
16051601
let qualifs = self.tcx.mir_const_qualif(def_id);
16061602

1607-
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(const_data));
1603+
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst);
16081604
record!(self.tables.mir_const_qualif[def_id.to_def_id()] <- qualifs);
1605+
record!(self.tables.rendered_const[def_id.to_def_id()] <- const_data);
16091606
self.encode_item_type(def_id.to_def_id());
16101607
}
16111608

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ define_tables! {
309309
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?
310310
coerce_unsized_info: Table<DefIndex, Lazy!(ty::adjustment::CoerceUnsizedInfo)>,
311311
mir_const_qualif: Table<DefIndex, Lazy!(mir::ConstQualifs)>,
312+
rendered_const: Table<DefIndex, Lazy!(String)>,
312313

313314
trait_item_def_id: Table<DefIndex, Lazy<DefId>>,
314315
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
@@ -325,8 +326,8 @@ define_tables! {
325326

326327
#[derive(Copy, Clone, MetadataEncodable, MetadataDecodable)]
327328
enum EntryKind {
328-
AnonConst(Lazy<RenderedConst>),
329-
Const(Lazy<RenderedConst>),
329+
AnonConst,
330+
Const,
330331
ImmStatic,
331332
MutStatic,
332333
ForeignImmStatic,
@@ -354,15 +355,10 @@ enum EntryKind {
354355
Impl,
355356
AssocFn(Lazy<AssocFnData>),
356357
AssocType(AssocContainer),
357-
AssocConst(AssocContainer, Lazy<RenderedConst>),
358+
AssocConst(AssocContainer),
358359
TraitAlias,
359360
}
360361

361-
/// Contains a constant which has been rendered to a String.
362-
/// Used by rustdoc.
363-
#[derive(Encodable, Decodable)]
364-
struct RenderedConst(String);
365-
366362
#[derive(MetadataEncodable, MetadataDecodable)]
367363
struct FnData {
368364
asyncness: hir::IsAsync,

0 commit comments

Comments
 (0)