Skip to content

Commit 8ed5cb5

Browse files
committed
Auto merge of #76027 - davidtwco:issue-61139-remove-obsolete-pretty-printer, r=eddyb
ty: remove obsolete pretty printer Fixes #61139. This PR removes the obsolete printer and replaces all uses of it with `FmtPrinter`. Of the replaced uses, all but one use was in `debug!` logging, two cases were notable: - `MonoItem::to_string` is used in `-Z print-mono-items` and therefore affects the output of all codegen-units tests (which have been updated). - `DefPathBasedNames` was used in `librustc_codegen_llvm/type_of.rs` with `LLVMStructCreateNamed` and that'll now get different values, but nothing will break as a result of this. cc @eddyb (whom I've discussed this with)
2 parents e98f063 + 6ff471b commit 8ed5cb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+385
-664
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::type_::Type;
44
use rustc_codegen_ssa::traits::*;
55
use rustc_middle::bug;
66
use rustc_middle::ty::layout::{FnAbiExt, TyAndLayout};
7-
use rustc_middle::ty::print::obsolete::DefPathBasedNames;
87
use rustc_middle::ty::{self, Ty, TypeFoldable};
98
use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape};
109
use rustc_target::abi::{Int, Pointer, F32, F64};
@@ -60,9 +59,7 @@ fn uncached_llvm_type<'a, 'tcx>(
6059
// ty::Dynamic(..) |
6160
ty::Foreign(..) |
6261
ty::Str => {
63-
let mut name = String::with_capacity(32);
64-
let printer = DefPathBasedNames::new(cx.tcx, true, true);
65-
printer.push_type_name(layout.ty, &mut name, false);
62+
let mut name = layout.ty.to_string();
6663
if let (&ty::Adt(def, _), &Variants::Single { index })
6764
= (&layout.ty.kind, &layout.variants)
6865
{

compiler/rustc_codegen_ssa/src/mono_item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
2121
fn define<Bx: BuilderMethods<'a, 'tcx>>(&self, cx: &'a Bx::CodegenCx) {
2222
debug!(
2323
"BEGIN IMPLEMENTING '{} ({})' in cgu {}",
24-
self.to_string(cx.tcx(), true),
24+
self,
2525
self.to_raw_string(),
2626
cx.codegen_unit().name()
2727
);
@@ -45,7 +45,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
4545

4646
debug!(
4747
"END IMPLEMENTING '{} ({})' in cgu {}",
48-
self.to_string(cx.tcx(), true),
48+
self,
4949
self.to_raw_string(),
5050
cx.codegen_unit().name()
5151
);
@@ -59,7 +59,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
5959
) {
6060
debug!(
6161
"BEGIN PREDEFINING '{} ({})' in cgu {}",
62-
self.to_string(cx.tcx(), true),
62+
self,
6363
self.to_raw_string(),
6464
cx.codegen_unit().name()
6565
);
@@ -80,7 +80,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
8080

8181
debug!(
8282
"END PREDEFINING '{} ({})' in cgu {}",
83-
self.to_string(cx.tcx(), true),
83+
self,
8484
self.to_raw_string(),
8585
cx.codegen_unit().name()
8686
);

compiler/rustc_middle/src/mir/mono.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId};
22
use crate::ich::{NodeIdHashingMode, StableHashingContext};
3-
use crate::ty::print::obsolete::DefPathBasedNames;
43
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
54
use rustc_attr::InlineAttr;
65
use rustc_data_structures::base_n;
@@ -171,30 +170,6 @@ impl<'tcx> MonoItem<'tcx> {
171170
!tcx.subst_and_check_impossible_predicates((def_id, &substs))
172171
}
173172

174-
pub fn to_string(&self, tcx: TyCtxt<'tcx>, debug: bool) -> String {
175-
return match *self {
176-
MonoItem::Fn(instance) => to_string_internal(tcx, "fn ", instance, debug),
177-
MonoItem::Static(def_id) => {
178-
let instance = Instance::new(def_id, tcx.intern_substs(&[]));
179-
to_string_internal(tcx, "static ", instance, debug)
180-
}
181-
MonoItem::GlobalAsm(..) => "global_asm".to_string(),
182-
};
183-
184-
fn to_string_internal<'tcx>(
185-
tcx: TyCtxt<'tcx>,
186-
prefix: &str,
187-
instance: Instance<'tcx>,
188-
debug: bool,
189-
) -> String {
190-
let mut result = String::with_capacity(32);
191-
result.push_str(prefix);
192-
let printer = DefPathBasedNames::new(tcx, false, false);
193-
printer.push_instance_as_string(instance, &mut result, debug);
194-
result
195-
}
196-
}
197-
198173
pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option<Span> {
199174
match *self {
200175
MonoItem::Fn(Instance { def, .. }) => {
@@ -229,6 +204,18 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
229204
}
230205
}
231206

207+
impl<'tcx> fmt::Display for MonoItem<'tcx> {
208+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
209+
match *self {
210+
MonoItem::Fn(instance) => write!(f, "fn {}", instance),
211+
MonoItem::Static(def_id) => {
212+
write!(f, "static {}", Instance::new(def_id, InternalSubsts::empty()))
213+
}
214+
MonoItem::GlobalAsm(..) => write!(f, "global_asm"),
215+
}
216+
}
217+
}
218+
232219
pub struct CodegenUnit<'tcx> {
233220
/// A name for this CGU. Incremental compilation requires that
234221
/// name be unique amongst **all** crates. Therefore, it should

compiler/rustc_middle/src/ty/print/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
99
mod pretty;
1010
pub use self::pretty::*;
1111

12-
pub mod obsolete;
13-
1412
// FIXME(eddyb) false positive, the lifetime parameters are used with `P: Printer<...>`.
1513
#[allow(unused_lifetimes)]
1614
pub trait Print<'tcx, P> {

compiler/rustc_middle/src/ty/print/obsolete.rs

-251
This file was deleted.

0 commit comments

Comments
 (0)