Skip to content

Commit a1b8540

Browse files
committed
Undo the const_str changes from the previous commit.
1 parent 7c4d431 commit a1b8540

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

src/librustc_codegen_llvm/common.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_codegen_ssa::traits::*;
1515
use rustc_middle::bug;
1616
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
1717
use rustc_middle::ty::layout::TyAndLayout;
18-
use rustc_middle::ty::SymbolName;
18+
use rustc_span::symbol::Symbol;
1919
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size};
2020

2121
use libc::{c_char, c_uint};
@@ -105,16 +105,17 @@ impl CodegenCx<'ll, 'tcx> {
105105
bytes_in_context(self.llcx, bytes)
106106
}
107107

108-
fn const_cstr(&self, s: SymbolName<'tcx>, null_terminated: bool) -> &'ll Value {
108+
fn const_cstr(&self, s: Symbol, null_terminated: bool) -> &'ll Value {
109109
unsafe {
110110
if let Some(&llval) = self.const_cstr_cache.borrow().get(&s) {
111111
return llval;
112112
}
113113

114+
let s_str = s.as_str();
114115
let sc = llvm::LLVMConstStringInContext(
115116
self.llcx,
116-
s.name.as_ptr() as *const c_char,
117-
s.name.len() as c_uint,
117+
s_str.as_ptr() as *const c_char,
118+
s_str.len() as c_uint,
118119
!null_terminated as Bool,
119120
);
120121
let sym = self.generate_local_symbol_name("str");
@@ -201,8 +202,8 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
201202
unsafe { llvm::LLVMConstReal(t, val) }
202203
}
203204

204-
fn const_str(&self, s: SymbolName<'tcx>) -> (&'ll Value, &'ll Value) {
205-
let len = s.name.len();
205+
fn const_str(&self, s: Symbol) -> (&'ll Value, &'ll Value) {
206+
let len = s.as_str().len();
206207
let cs = consts::ptrcast(
207208
self.const_cstr(s, false),
208209
self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self)),

src/librustc_codegen_llvm/context.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ use rustc_data_structures::small_c_str::SmallCStr;
1616
use rustc_middle::bug;
1717
use rustc_middle::mir::mono::CodegenUnit;
1818
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
19-
use rustc_middle::ty::{self, Instance, SymbolName, Ty, TyCtxt};
19+
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2020
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
2121
use rustc_session::Session;
2222
use rustc_span::source_map::{Span, DUMMY_SP};
23+
use rustc_span::symbol::Symbol;
2324
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
2425
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
2526

@@ -46,7 +47,7 @@ pub struct CodegenCx<'ll, 'tcx> {
4647
pub vtables:
4748
RefCell<FxHashMap<(Ty<'tcx>, Option<ty::PolyExistentialTraitRef<'tcx>>), &'ll Value>>,
4849
/// Cache of constant strings,
49-
pub const_cstr_cache: RefCell<FxHashMap<SymbolName<'tcx>, &'ll Value>>,
50+
pub const_cstr_cache: RefCell<FxHashMap<Symbol, &'ll Value>>,
5051

5152
/// Reverse-direction for const ptrs cast from globals.
5253
///

src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
196196
// and/or monomorphization invalidates these assumptions.
197197
let coverageinfo = tcx.coverageinfo(caller_instance.def_id());
198198
let mangled_fn = tcx.symbol_name(caller_instance);
199-
let (mangled_fn_name, _len_val) = self.const_str(mangled_fn);
199+
let (mangled_fn_name, _len_val) = self.const_str(Symbol::intern(mangled_fn.name));
200200
let hash = self.const_u64(coverageinfo.hash);
201201
let num_counters = self.const_u32(coverageinfo.num_counters);
202202
use coverage::count_code_region_args::*;

src/librustc_codegen_ssa/mir/block.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir;
1616
use rustc_middle::mir::interpret::{AllocId, ConstValue, Pointer, Scalar};
1717
use rustc_middle::mir::AssertKind;
1818
use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
19-
use rustc_middle::ty::{self, Instance, SymbolName, Ty, TypeFoldable};
19+
use rustc_middle::ty::{self, Instance, Ty, TypeFoldable};
2020
use rustc_span::source_map::Span;
2121
use rustc_span::{sym, Symbol};
2222
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
@@ -423,7 +423,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
423423
(lang_items::PanicBoundsCheckFnLangItem, vec![index, len, location])
424424
}
425425
_ => {
426-
let msg = bx.const_str(SymbolName::new(bx.tcx(), msg.description()));
426+
let msg_str = Symbol::intern(msg.description());
427+
let msg = bx.const_str(msg_str);
427428
// It's `pub fn panic(expr: &str)`, with the wide reference being passed
428429
// as two arguments, and `#[track_caller]` adds an implicit third argument.
429430
(lang_items::PanicFnLangItem, vec![msg.0, msg.1, location])
@@ -486,7 +487,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
486487
} else {
487488
format!("attempted to leave type `{}` uninitialized, which is invalid", ty)
488489
};
489-
let msg = bx.const_str(SymbolName::new(bx.tcx(), &msg_str));
490+
let msg = bx.const_str(Symbol::intern(&msg_str));
490491
let location = self.get_caller_location(bx, span).immediate();
491492

492493
// Obtain the panic entry point.

src/librustc_codegen_ssa/traits/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::BackendTypes;
22
use crate::mir::place::PlaceRef;
33
use rustc_middle::mir::interpret::{Allocation, Scalar};
44
use rustc_middle::ty::layout::TyAndLayout;
5-
use rustc_middle::ty::SymbolName;
5+
use rustc_span::Symbol;
66
use rustc_target::abi::{self, Size};
77

88
pub trait ConstMethods<'tcx>: BackendTypes {
@@ -20,7 +20,7 @@ pub trait ConstMethods<'tcx>: BackendTypes {
2020
fn const_u8(&self, i: u8) -> Self::Value;
2121
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
2222

23-
fn const_str(&self, s: SymbolName<'tcx>) -> (Self::Value, Self::Value);
23+
fn const_str(&self, s: Symbol) -> (Self::Value, Self::Value);
2424
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
2525

2626
fn const_to_opt_uint(&self, v: Self::Value) -> Option<u64>;

0 commit comments

Comments
 (0)