1
Fork 0

Avoid unnecessary string interning for const_str

This commit is contained in:
bjorn3 2022-06-28 17:34:24 +00:00
parent 94e93749ab
commit f6484fa9b5
8 changed files with 45 additions and 34 deletions

View file

@ -481,8 +481,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(LangItem::PanicBoundsCheck, vec![index, len, location])
}
_ => {
let msg_str = Symbol::intern(msg.description());
let msg = bx.const_str(msg_str);
let msg = bx.const_str(msg.description());
// It's `pub fn panic(expr: &str)`, with the wide reference being passed
// as two arguments, and `#[track_caller]` adds an implicit third argument.
(LangItem::Panic, vec![msg.0, msg.1, location])
@ -563,7 +562,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
})
});
let msg = bx.const_str(Symbol::intern(&msg_str));
let msg = bx.const_str(&msg_str);
let location = self.get_caller_location(bx, source_info).immediate();
// Obtain the panic entry point.

View file

@ -2,7 +2,6 @@ use super::BackendTypes;
use crate::mir::place::PlaceRef;
use rustc_middle::mir::interpret::{ConstAllocation, Scalar};
use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::Symbol;
use rustc_target::abi::{self, Size};
pub trait ConstMethods<'tcx>: BackendTypes {
@ -21,7 +20,7 @@ pub trait ConstMethods<'tcx>: BackendTypes {
fn const_u8(&self, i: u8) -> Self::Value;
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
fn const_str(&self, s: Symbol) -> (Self::Value, Self::Value);
fn const_str(&self, s: &str) -> (Self::Value, Self::Value);
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
fn const_to_opt_uint(&self, v: Self::Value) -> Option<u64>;