Skip to content

Commit

Permalink
Undo the const_str changes from the previous commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
nnethercote committed Jul 15, 2020
1 parent 7c4d431 commit a1b8540
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_codegen_ssa::traits::*;
use rustc_middle::bug;
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::SymbolName;
use rustc_span::symbol::Symbol;
use rustc_target::abi::{self, HasDataLayout, LayoutOf, Pointer, Size};

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

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

let s_str = s.as_str();
let sc = llvm::LLVMConstStringInContext(
self.llcx,
s.name.as_ptr() as *const c_char,
s.name.len() as c_uint,
s_str.as_ptr() as *const c_char,
s_str.len() as c_uint,
!null_terminated as Bool,
);
let sym = self.generate_local_symbol_name("str");
Expand Down Expand Up @@ -201,8 +202,8 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
unsafe { llvm::LLVMConstReal(t, val) }
}

fn const_str(&self, s: SymbolName<'tcx>) -> (&'ll Value, &'ll Value) {
let len = s.name.len();
fn const_str(&self, s: Symbol) -> (&'ll Value, &'ll Value) {
let len = s.as_str().len();
let cs = consts::ptrcast(
self.const_cstr(s, false),
self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self)),
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc_middle::bug;
use rustc_middle::mir::mono::CodegenUnit;
use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout};
use rustc_middle::ty::{self, Instance, SymbolName, Ty, TyCtxt};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::{CFGuard, CrateType, DebugInfo};
use rustc_session::Session;
use rustc_span::source_map::{Span, DUMMY_SP};
use rustc_span::symbol::Symbol;
use rustc_target::abi::{HasDataLayout, LayoutOf, PointeeInfo, Size, TargetDataLayout, VariantIdx};
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};

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

/// Reverse-direction for const ptrs cast from globals.
///
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
// and/or monomorphization invalidates these assumptions.
let coverageinfo = tcx.coverageinfo(caller_instance.def_id());
let mangled_fn = tcx.symbol_name(caller_instance);
let (mangled_fn_name, _len_val) = self.const_str(mangled_fn);
let (mangled_fn_name, _len_val) = self.const_str(Symbol::intern(mangled_fn.name));
let hash = self.const_u64(coverageinfo.hash);
let num_counters = self.const_u32(coverageinfo.num_counters);
use coverage::count_code_region_args::*;
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_middle::mir;
use rustc_middle::mir::interpret::{AllocId, ConstValue, Pointer, Scalar};
use rustc_middle::mir::AssertKind;
use rustc_middle::ty::layout::{FnAbiExt, HasTyCtxt};
use rustc_middle::ty::{self, Instance, SymbolName, Ty, TypeFoldable};
use rustc_middle::ty::{self, Instance, Ty, TypeFoldable};
use rustc_span::source_map::Span;
use rustc_span::{sym, Symbol};
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
Expand Down Expand Up @@ -423,7 +423,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(lang_items::PanicBoundsCheckFnLangItem, vec![index, len, location])
}
_ => {
let msg = bx.const_str(SymbolName::new(bx.tcx(), msg.description()));
let msg_str = Symbol::intern(msg.description());
let msg = bx.const_str(msg_str);
// It's `pub fn panic(expr: &str)`, with the wide reference being passed
// as two arguments, and `#[track_caller]` adds an implicit third argument.
(lang_items::PanicFnLangItem, vec![msg.0, msg.1, location])
Expand Down Expand Up @@ -486,7 +487,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
} else {
format!("attempted to leave type `{}` uninitialized, which is invalid", ty)
};
let msg = bx.const_str(SymbolName::new(bx.tcx(), &msg_str));
let msg = bx.const_str(Symbol::intern(&msg_str));
let location = self.get_caller_location(bx, span).immediate();

// Obtain the panic entry point.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/traits/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::BackendTypes;
use crate::mir::place::PlaceRef;
use rustc_middle::mir::interpret::{Allocation, Scalar};
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::ty::SymbolName;
use rustc_span::Symbol;
use rustc_target::abi::{self, Size};

pub trait ConstMethods<'tcx>: BackendTypes {
Expand All @@ -20,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: SymbolName<'tcx>) -> (Self::Value, Self::Value);
fn const_str(&self, s: Symbol) -> (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>;
Expand Down

0 comments on commit a1b8540

Please sign in to comment.