Rollup merge of #64141 - nnethercote:minimize-LocalInternedString, r=petrochenkov
Minimize uses of `LocalInternedString` `LocalInternedString` is described as "An alternative to `Symbol` and `InternedString`, useful when the chars within the symbol need to be accessed. It is best used for temporary values." This PR makes the code match that comment, by removing all non-local uses of `LocalInternedString`. This allows the removal of a number of operations on `LocalInternedString` and a couple of uses of `unsafe`.
This commit is contained in:
commit
4dfbaba3bf
22 changed files with 86 additions and 133 deletions
|
|
@ -5,7 +5,6 @@ use crate::context::CodegenCx;
|
|||
use crate::type_::Type;
|
||||
use crate::type_of::LayoutLlvmExt;
|
||||
use crate::value::Value;
|
||||
use syntax::symbol::LocalInternedString;
|
||||
use rustc_codegen_ssa::common::{IntPredicate, TypeKind, RealPredicate};
|
||||
use rustc_codegen_ssa::MemFlags;
|
||||
use libc::{c_uint, c_char};
|
||||
|
|
@ -24,6 +23,7 @@ use std::ffi::CStr;
|
|||
use std::ops::{Deref, Range};
|
||||
use std::ptr;
|
||||
use std::iter::TrustedLen;
|
||||
use syntax::symbol::Symbol;
|
||||
|
||||
// All Builders must have an llfn associated with them
|
||||
#[must_use]
|
||||
|
|
@ -1082,8 +1082,8 @@ impl StaticBuilderMethods for Builder<'a, 'll, 'tcx> {
|
|||
|
||||
fn static_panic_msg(
|
||||
&mut self,
|
||||
msg: Option<LocalInternedString>,
|
||||
filename: LocalInternedString,
|
||||
msg: Option<Symbol>,
|
||||
filename: Symbol,
|
||||
line: Self::Value,
|
||||
col: Self::Value,
|
||||
kind: &str,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub fn get_fn(
|
|||
return llfn;
|
||||
}
|
||||
|
||||
let sym = tcx.symbol_name(instance).as_str();
|
||||
let sym = tcx.symbol_name(instance).name.as_str();
|
||||
debug!("get_fn({:?}: {:?}) => {}", instance, sig, sym);
|
||||
|
||||
// Create a fn pointer with the substituted signature.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use rustc_codegen_ssa::mir::place::PlaceRef;
|
|||
|
||||
use libc::{c_uint, c_char};
|
||||
|
||||
use syntax::symbol::LocalInternedString;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::ast::Mutability;
|
||||
|
||||
pub use crate::context::CodegenCx;
|
||||
|
|
@ -122,7 +122,7 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
|
||||
fn const_cstr(
|
||||
&self,
|
||||
s: LocalInternedString,
|
||||
s: Symbol,
|
||||
null_terminated: bool,
|
||||
) -> &'ll Value {
|
||||
unsafe {
|
||||
|
|
@ -130,9 +130,10 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
return llval;
|
||||
}
|
||||
|
||||
let s_str = s.as_str();
|
||||
let sc = llvm::LLVMConstStringInContext(self.llcx,
|
||||
s.as_ptr() as *const c_char,
|
||||
s.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");
|
||||
let g = self.define_global(&sym[..], self.val_ty(sc)).unwrap_or_else(||{
|
||||
|
|
@ -147,8 +148,8 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn const_str_slice(&self, s: LocalInternedString) -> &'ll Value {
|
||||
let len = s.len();
|
||||
pub fn const_str_slice(&self, s: Symbol) -> &'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.mk_str()).llvm_type(self)));
|
||||
self.const_fat_ptr(cs, self.const_usize(len as u64))
|
||||
|
|
|
|||
|
|
@ -11,12 +11,11 @@ use rustc::mir::interpret::{ConstValue, Allocation, read_target_uint,
|
|||
Pointer, ErrorHandled, GlobalId};
|
||||
use rustc::mir::mono::MonoItem;
|
||||
use rustc::hir::Node;
|
||||
use syntax_pos::Span;
|
||||
use rustc_target::abi::HasDataLayout;
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::symbol::LocalInternedString;
|
||||
use rustc::ty::{self, Ty, Instance};
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use rustc::ty::layout::{self, Size, Align, LayoutOf};
|
||||
|
||||
|
|
@ -122,10 +121,11 @@ fn check_and_apply_linkage(
|
|||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
attrs: &CodegenFnAttrs,
|
||||
ty: Ty<'tcx>,
|
||||
sym: LocalInternedString,
|
||||
sym: Symbol,
|
||||
span: Span
|
||||
) -> &'ll Value {
|
||||
let llty = cx.layout_of(ty).llvm_type(cx);
|
||||
let sym = sym.as_str();
|
||||
if let Some(linkage) = attrs.linkage {
|
||||
debug!("get_static: sym={} linkage={:?}", sym, linkage);
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
def_id);
|
||||
|
||||
let ty = instance.ty(self.tcx);
|
||||
let sym = self.tcx.symbol_name(instance).as_str();
|
||||
let sym = self.tcx.symbol_name(instance).name.as_symbol();
|
||||
|
||||
debug!("get_static: sym={} instance={:?}", sym, instance);
|
||||
|
||||
|
|
@ -232,11 +232,12 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
Node::Item(&hir::Item {
|
||||
ref attrs, span, node: hir::ItemKind::Static(..), ..
|
||||
}) => {
|
||||
if self.get_declared_value(&sym[..]).is_some() {
|
||||
let sym_str = sym.as_str();
|
||||
if self.get_declared_value(&sym_str).is_some() {
|
||||
span_bug!(span, "Conflicting symbol names for static?");
|
||||
}
|
||||
|
||||
let g = self.define_global(&sym[..], llty).unwrap();
|
||||
let g = self.define_global(&sym_str, llty).unwrap();
|
||||
|
||||
if !self.tcx.is_reachable_non_generic(def_id) {
|
||||
unsafe {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ use std::cell::{Cell, RefCell};
|
|||
use std::iter;
|
||||
use std::str;
|
||||
use std::sync::Arc;
|
||||
use syntax::symbol::LocalInternedString;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::source_map::{DUMMY_SP, Span};
|
||||
use crate::abi::Abi;
|
||||
|
||||
|
|
@ -52,7 +52,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<LocalInternedString, &'ll Value>>,
|
||||
pub const_cstr_cache: RefCell<FxHashMap<Symbol, &'ll Value>>,
|
||||
|
||||
/// Reverse-direction for const ptrs cast from globals.
|
||||
/// Key is a Value holding a *T,
|
||||
|
|
|
|||
|
|
@ -2251,7 +2251,7 @@ pub fn create_global_var_metadata(
|
|||
None
|
||||
} else {
|
||||
let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id));
|
||||
Some(SmallCStr::new(&linkage_name.as_str()))
|
||||
Some(SmallCStr::new(&linkage_name.name.as_str()))
|
||||
};
|
||||
|
||||
let global_align = cx.align_of(variable_type);
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
let scope_line = span_start(self, span).line;
|
||||
|
||||
let function_name = CString::new(name).unwrap();
|
||||
let linkage_name = SmallCStr::new(&linkage_name.as_str());
|
||||
let linkage_name = SmallCStr::new(&linkage_name.name.as_str());
|
||||
|
||||
let mut flags = DIFlags::FlagPrototyped;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue