rustc_codegen_ssa: change set_var_name back to taking a &str.

This commit is contained in:
Eduard-Mihai Burtescu 2019-10-22 12:36:00 +03:00
parent 5f4ee36e03
commit 06869b8d17
3 changed files with 10 additions and 34 deletions

View File

@ -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());
}

View File

@ -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<D> DebugScope<D> {
}
}
// HACK(eddyb) helpers for `set_var_name` calls, move elsewhere?
enum Either<T, U> {
Left(T),
Right(U),
}
impl<T: fmt::Display, U: fmt::Display> fmt::Display for Either<T, U> {
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>(T);
impl<T: fmt::Debug> fmt::Display for DisplayViaDebug<T> {
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) => {}

View File

@ -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);
}