From 06869b8d17d06818d8e2ac36834ba21827443985 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 22 Oct 2019 12:36:00 +0300 Subject: [PATCH] rustc_codegen_ssa: change set_var_name back to taking a &str. --- src/librustc_codegen_llvm/debuginfo/mod.rs | 4 +-- src/librustc_codegen_ssa/mir/debuginfo.rs | 38 ++++---------------- src/librustc_codegen_ssa/traits/debuginfo.rs | 2 +- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index d7706b3251b..0e6269fc7e1 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -225,7 +225,7 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { gdb::insert_reference_to_gdb_debug_scripts_section_global(self) } - fn set_var_name(&mut self, value: &'ll Value, name: impl ToString) { + fn set_var_name(&mut self, value: &'ll Value, name: &str) { // Avoid wasting time if LLVM value names aren't even enabled. if self.sess().fewer_names() { return; @@ -255,7 +255,7 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { Err(_) => return, } - let cname = CString::new(name.to_string()).unwrap(); + let cname = SmallCStr::new(name); unsafe { llvm::LLVMSetValueName(value, cname.as_ptr()); } diff --git a/src/librustc_codegen_ssa/mir/debuginfo.rs b/src/librustc_codegen_ssa/mir/debuginfo.rs index cd209717cc4..29c0d70b58a 100644 --- a/src/librustc_codegen_ssa/mir/debuginfo.rs +++ b/src/librustc_codegen_ssa/mir/debuginfo.rs @@ -7,7 +7,6 @@ use rustc::ty::layout::HasTyCtxt; use rustc_target::abi::{Variants, VariantIdx}; use crate::traits::*; -use std::fmt; use syntax_pos::{DUMMY_SP, BytePos, Span}; use syntax::symbol::kw; @@ -92,29 +91,6 @@ impl DebugScope { } } -// HACK(eddyb) helpers for `set_var_name` calls, move elsewhere? -enum Either { - Left(T), - Right(U), -} - -impl fmt::Display for Either { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Either::Left(x) => x.fmt(f), - Either::Right(x) => x.fmt(f), - } - } -} - -struct DisplayViaDebug(T); - -impl fmt::Display for DisplayViaDebug { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.fmt(f) - } -} - impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { pub fn set_debug_loc( &mut self, @@ -207,26 +183,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let local_ref = &self.locals[local]; - { + if !bx.sess().fewer_names() { let name = match name { - Some(name) if name != kw::Invalid => Either::Left(name), - _ => Either::Right(DisplayViaDebug(local)), + Some(name) if name != kw::Invalid => name.to_string(), + _ => format!("{:?}", local), }; match local_ref { LocalRef::Place(place) | LocalRef::UnsizedPlace(place) => { - bx.set_var_name(place.llval, name); + bx.set_var_name(place.llval, &name); } LocalRef::Operand(Some(operand)) => match operand.val { OperandValue::Ref(x, ..) | OperandValue::Immediate(x) => { - bx.set_var_name(x, name); + bx.set_var_name(x, &name); } OperandValue::Pair(a, b) => { // FIXME(eddyb) these are scalar components, // maybe extract the high-level fields? - bx.set_var_name(a, format_args!("{}.0", name)); - bx.set_var_name(b, format_args!("{}.1", name)); + bx.set_var_name(a, &(name.clone() + ".0")); + bx.set_var_name(b, &(name + ".1")); } } LocalRef::Operand(None) => {} diff --git a/src/librustc_codegen_ssa/traits/debuginfo.rs b/src/librustc_codegen_ssa/traits/debuginfo.rs index 244fe845d7d..4712eff6796 100644 --- a/src/librustc_codegen_ssa/traits/debuginfo.rs +++ b/src/librustc_codegen_ssa/traits/debuginfo.rs @@ -57,5 +57,5 @@ pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes { span: Span, ); fn insert_reference_to_gdb_debug_scripts_section_global(&mut self); - fn set_var_name(&mut self, value: Self::Value, name: impl ToString); + fn set_var_name(&mut self, value: Self::Value, name: &str); }