Skip to content

Commit

Permalink
Rollup merge of rust-lang#76027 - davidtwco:issue-61139-remove-obsole…
Browse files Browse the repository at this point in the history
…te-pretty-printer, r=eddyb

ty: remove obsolete pretty printer

Fixes rust-lang#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)
  • Loading branch information
Dylan-DPC authored Aug 31, 2020
2 parents 1f96030 + 6ff471b commit 0af6fed
Show file tree
Hide file tree
Showing 44 changed files with 385 additions and 664 deletions.
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::type_::Type;
use rustc_codegen_ssa::traits::*;
use rustc_middle::bug;
use rustc_middle::ty::layout::{FnAbiExt, TyAndLayout};
use rustc_middle::ty::print::obsolete::DefPathBasedNames;
use rustc_middle::ty::{self, Ty, TypeFoldable};
use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape};
use rustc_target::abi::{Int, Pointer, F32, F64};
Expand Down Expand Up @@ -60,9 +59,7 @@ fn uncached_llvm_type<'a, 'tcx>(
// ty::Dynamic(..) |
ty::Foreign(..) |
ty::Str => {
let mut name = String::with_capacity(32);
let printer = DefPathBasedNames::new(cx.tcx, true, true);
printer.push_type_name(layout.ty, &mut name, false);
let mut name = layout.ty.to_string();
if let (&ty::Adt(def, _), &Variants::Single { index })
= (&layout.ty.kind, &layout.variants)
{
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_ssa/src/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
fn define<Bx: BuilderMethods<'a, 'tcx>>(&self, cx: &'a Bx::CodegenCx) {
debug!(
"BEGIN IMPLEMENTING '{} ({})' in cgu {}",
self.to_string(cx.tcx(), true),
self,
self.to_raw_string(),
cx.codegen_unit().name()
);
Expand All @@ -45,7 +45,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {

debug!(
"END IMPLEMENTING '{} ({})' in cgu {}",
self.to_string(cx.tcx(), true),
self,
self.to_raw_string(),
cx.codegen_unit().name()
);
Expand All @@ -59,7 +59,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
) {
debug!(
"BEGIN PREDEFINING '{} ({})' in cgu {}",
self.to_string(cx.tcx(), true),
self,
self.to_raw_string(),
cx.codegen_unit().name()
);
Expand All @@ -80,7 +80,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {

debug!(
"END PREDEFINING '{} ({})' in cgu {}",
self.to_string(cx.tcx(), true),
self,
self.to_raw_string(),
cx.codegen_unit().name()
);
Expand Down
37 changes: 12 additions & 25 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId};
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::ty::print::obsolete::DefPathBasedNames;
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
use rustc_attr::InlineAttr;
use rustc_data_structures::base_n;
Expand Down Expand Up @@ -171,30 +170,6 @@ impl<'tcx> MonoItem<'tcx> {
!tcx.subst_and_check_impossible_predicates((def_id, &substs))
}

pub fn to_string(&self, tcx: TyCtxt<'tcx>, debug: bool) -> String {
return match *self {
MonoItem::Fn(instance) => to_string_internal(tcx, "fn ", instance, debug),
MonoItem::Static(def_id) => {
let instance = Instance::new(def_id, tcx.intern_substs(&[]));
to_string_internal(tcx, "static ", instance, debug)
}
MonoItem::GlobalAsm(..) => "global_asm".to_string(),
};

fn to_string_internal<'tcx>(
tcx: TyCtxt<'tcx>,
prefix: &str,
instance: Instance<'tcx>,
debug: bool,
) -> String {
let mut result = String::with_capacity(32);
result.push_str(prefix);
let printer = DefPathBasedNames::new(tcx, false, false);
printer.push_instance_as_string(instance, &mut result, debug);
result
}
}

pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option<Span> {
match *self {
MonoItem::Fn(Instance { def, .. }) => {
Expand Down Expand Up @@ -229,6 +204,18 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
}
}

impl<'tcx> fmt::Display for MonoItem<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
MonoItem::Fn(instance) => write!(f, "fn {}", instance),
MonoItem::Static(def_id) => {
write!(f, "static {}", Instance::new(def_id, InternalSubsts::empty()))
}
MonoItem::GlobalAsm(..) => write!(f, "global_asm"),
}
}
}

pub struct CodegenUnit<'tcx> {
/// A name for this CGU. Incremental compilation requires that
/// name be unique amongst **all** crates. Therefore, it should
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
mod pretty;
pub use self::pretty::*;

pub mod obsolete;

// FIXME(eddyb) false positive, the lifetime parameters are used with `P: Printer<...>`.
#[allow(unused_lifetimes)]
pub trait Print<'tcx, P> {
Expand Down
251 changes: 0 additions & 251 deletions compiler/rustc_middle/src/ty/print/obsolete.rs

This file was deleted.

Loading

0 comments on commit 0af6fed

Please sign in to comment.