Auto merge of #74214 - nnethercote:change-SymbolName-name, r=eddyb
Change `SymbolName::name` to a `&str`. This eliminates a bunch of `Symbol::intern()` and `Symbol::as_str()` calls, which is good, because they require locking the interner. Note that the unsafety in `from_cycle_error()` is identical to the unsafety on other adjacent impls. r? @eddyb
This commit is contained in:
commit
d9e8d62907
19 changed files with 77 additions and 68 deletions
|
@ -35,7 +35,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
|
||||||
return llfn;
|
return llfn;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sym = tcx.symbol_name(instance).name.as_str();
|
let sym = tcx.symbol_name(instance).name;
|
||||||
debug!("get_fn({:?}: {:?}) => {}", instance, instance.monomorphic_ty(cx.tcx()), sym);
|
debug!("get_fn({:?}: {:?}) => {}", instance, instance.monomorphic_ty(cx.tcx()), sym);
|
||||||
|
|
||||||
let fn_abi = FnAbi::of_instance(cx, instance, &[]);
|
let fn_abi = FnAbi::of_instance(cx, instance, &[]);
|
||||||
|
|
|
@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{
|
||||||
use rustc_middle::mir::mono::MonoItem;
|
use rustc_middle::mir::mono::MonoItem;
|
||||||
use rustc_middle::ty::{self, Instance, Ty};
|
use rustc_middle::ty::{self, Instance, Ty};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size};
|
use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size};
|
||||||
|
|
||||||
|
@ -107,11 +107,10 @@ fn check_and_apply_linkage(
|
||||||
cx: &CodegenCx<'ll, 'tcx>,
|
cx: &CodegenCx<'ll, 'tcx>,
|
||||||
attrs: &CodegenFnAttrs,
|
attrs: &CodegenFnAttrs,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
sym: Symbol,
|
sym: &str,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> &'ll Value {
|
) -> &'ll Value {
|
||||||
let llty = cx.layout_of(ty).llvm_type(cx);
|
let llty = cx.layout_of(ty).llvm_type(cx);
|
||||||
let sym = sym.as_str();
|
|
||||||
if let Some(linkage) = attrs.linkage {
|
if let Some(linkage) = attrs.linkage {
|
||||||
debug!("get_static: sym={} linkage={:?}", sym, linkage);
|
debug!("get_static: sym={} linkage={:?}", sym, linkage);
|
||||||
|
|
||||||
|
@ -215,14 +214,13 @@ impl CodegenCx<'ll, 'tcx> {
|
||||||
// FIXME: refactor this to work without accessing the HIR
|
// FIXME: refactor this to work without accessing the HIR
|
||||||
let (g, attrs) = match self.tcx.hir().get(id) {
|
let (g, attrs) = match self.tcx.hir().get(id) {
|
||||||
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {
|
Node::Item(&hir::Item { attrs, span, kind: hir::ItemKind::Static(..), .. }) => {
|
||||||
let sym_str = sym.as_str();
|
if let Some(g) = self.get_declared_value(sym) {
|
||||||
if let Some(g) = self.get_declared_value(&sym_str) {
|
|
||||||
if self.val_ty(g) != self.type_ptr_to(llty) {
|
if self.val_ty(g) != self.type_ptr_to(llty) {
|
||||||
span_bug!(span, "Conflicting types for static");
|
span_bug!(span, "Conflicting types for static");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let g = self.declare_global(&sym_str, llty);
|
let g = self.declare_global(sym, llty);
|
||||||
|
|
||||||
if !self.tcx.is_reachable_non_generic(def_id) {
|
if !self.tcx.is_reachable_non_generic(def_id) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -2468,8 +2468,7 @@ pub fn create_global_var_metadata(cx: &CodegenCx<'ll, '_>, def_id: DefId, global
|
||||||
let variable_type = Instance::mono(cx.tcx, def_id).monomorphic_ty(cx.tcx);
|
let variable_type = Instance::mono(cx.tcx, def_id).monomorphic_ty(cx.tcx);
|
||||||
let type_metadata = type_metadata(cx, variable_type, span);
|
let type_metadata = type_metadata(cx, variable_type, span);
|
||||||
let var_name = tcx.item_name(def_id).as_str();
|
let var_name = tcx.item_name(def_id).as_str();
|
||||||
let linkage_name: &str =
|
let linkage_name = mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name;
|
||||||
&mangled_name_of_instance(cx, Instance::mono(tcx, def_id)).name.as_str();
|
|
||||||
// When empty, linkage_name field is omitted,
|
// When empty, linkage_name field is omitted,
|
||||||
// which is what we want for no_mangle statics
|
// which is what we want for no_mangle statics
|
||||||
let linkage_name = if var_name == linkage_name { "" } else { linkage_name };
|
let linkage_name = if var_name == linkage_name { "" } else { linkage_name };
|
||||||
|
|
|
@ -267,7 +267,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
let substs = instance.substs.truncate_to(self.tcx(), generics);
|
let substs = instance.substs.truncate_to(self.tcx(), generics);
|
||||||
let template_parameters = get_template_parameters(self, &generics, substs, &mut name);
|
let template_parameters = get_template_parameters(self, &generics, substs, &mut name);
|
||||||
|
|
||||||
let linkage_name: &str = &mangled_name_of_instance(self, instance).name.as_str();
|
let linkage_name = &mangled_name_of_instance(self, instance).name;
|
||||||
// Omit the linkage_name if it is the same as subprogram name.
|
// Omit the linkage_name if it is the same as subprogram name.
|
||||||
let linkage_name = if &name == linkage_name { "" } else { linkage_name };
|
let linkage_name = if &name == linkage_name { "" } else { linkage_name };
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ use rustc_hir::definitions::DefPathData;
|
||||||
pub fn mangled_name_of_instance<'a, 'tcx>(
|
pub fn mangled_name_of_instance<'a, 'tcx>(
|
||||||
cx: &CodegenCx<'a, 'tcx>,
|
cx: &CodegenCx<'a, 'tcx>,
|
||||||
instance: Instance<'tcx>,
|
instance: Instance<'tcx>,
|
||||||
) -> ty::SymbolName {
|
) -> ty::SymbolName<'tcx> {
|
||||||
let tcx = cx.tcx;
|
let tcx = cx.tcx;
|
||||||
tcx.symbol_name(instance)
|
tcx.symbol_name(instance)
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
// and/or monomorphization invalidates these assumptions.
|
// and/or monomorphization invalidates these assumptions.
|
||||||
let coverageinfo = tcx.coverageinfo(caller_instance.def_id());
|
let coverageinfo = tcx.coverageinfo(caller_instance.def_id());
|
||||||
let mangled_fn = tcx.symbol_name(caller_instance);
|
let mangled_fn = tcx.symbol_name(caller_instance);
|
||||||
let (mangled_fn_name, _len_val) = self.const_str(mangled_fn.name);
|
let (mangled_fn_name, _len_val) = self.const_str(Symbol::intern(mangled_fn.name));
|
||||||
let hash = self.const_u64(coverageinfo.hash);
|
let hash = self.const_u64(coverageinfo.hash);
|
||||||
let num_counters = self.const_u32(coverageinfo.num_counters);
|
let num_counters = self.const_u32(coverageinfo.num_counters);
|
||||||
use coverage::count_code_region_args::*;
|
use coverage::count_code_region_args::*;
|
||||||
|
|
|
@ -16,7 +16,6 @@ use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||||
use rustc_middle::ty::Instance;
|
use rustc_middle::ty::Instance;
|
||||||
use rustc_middle::ty::{SymbolName, TyCtxt};
|
use rustc_middle::ty::{SymbolName, TyCtxt};
|
||||||
use rustc_session::config::{CrateType, SanitizerSet};
|
use rustc_session::config::{CrateType, SanitizerSet};
|
||||||
use rustc_span::symbol::sym;
|
|
||||||
|
|
||||||
pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
|
pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
|
||||||
crates_export_threshold(&tcx.sess.crate_types())
|
crates_export_threshold(&tcx.sess.crate_types())
|
||||||
|
@ -117,9 +116,9 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
||||||
// In general though we won't link right if these
|
// In general though we won't link right if these
|
||||||
// symbols are stripped, and LTO currently strips them.
|
// symbols are stripped, and LTO currently strips them.
|
||||||
match name {
|
match name {
|
||||||
sym::rust_eh_personality
|
"rust_eh_personality"
|
||||||
| sym::rust_eh_register_frames
|
| "rust_eh_register_frames"
|
||||||
| sym::rust_eh_unregister_frames =>
|
| "rust_eh_unregister_frames" =>
|
||||||
SymbolExportLevel::C,
|
SymbolExportLevel::C,
|
||||||
_ => SymbolExportLevel::Rust,
|
_ => SymbolExportLevel::Rust,
|
||||||
}
|
}
|
||||||
|
@ -177,7 +176,7 @@ fn exported_symbols_provider_local(
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if tcx.entry_fn(LOCAL_CRATE).is_some() {
|
if tcx.entry_fn(LOCAL_CRATE).is_some() {
|
||||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new("main"));
|
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
|
||||||
|
|
||||||
symbols.push((exported_symbol, SymbolExportLevel::C));
|
symbols.push((exported_symbol, SymbolExportLevel::C));
|
||||||
}
|
}
|
||||||
|
@ -185,7 +184,7 @@ fn exported_symbols_provider_local(
|
||||||
if tcx.allocator_kind().is_some() {
|
if tcx.allocator_kind().is_some() {
|
||||||
for method in ALLOCATOR_METHODS {
|
for method in ALLOCATOR_METHODS {
|
||||||
let symbol_name = format!("__rust_{}", method.name);
|
let symbol_name = format!("__rust_{}", method.name);
|
||||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
|
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
|
||||||
|
|
||||||
symbols.push((exported_symbol, SymbolExportLevel::Rust));
|
symbols.push((exported_symbol, SymbolExportLevel::Rust));
|
||||||
}
|
}
|
||||||
|
@ -199,7 +198,7 @@ fn exported_symbols_provider_local(
|
||||||
["__llvm_profile_raw_version", "__llvm_profile_filename"];
|
["__llvm_profile_raw_version", "__llvm_profile_filename"];
|
||||||
|
|
||||||
symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
|
symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
|
||||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym));
|
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
|
||||||
(exported_symbol, SymbolExportLevel::C)
|
(exported_symbol, SymbolExportLevel::C)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -209,14 +208,14 @@ fn exported_symbols_provider_local(
|
||||||
const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
|
const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
|
||||||
|
|
||||||
symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
|
symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
|
||||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(sym));
|
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
|
||||||
(exported_symbol, SymbolExportLevel::C)
|
(exported_symbol, SymbolExportLevel::C)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if tcx.sess.crate_types().contains(&CrateType::Dylib) {
|
if tcx.sess.crate_types().contains(&CrateType::Dylib) {
|
||||||
let symbol_name = metadata_symbol_name(tcx);
|
let symbol_name = metadata_symbol_name(tcx);
|
||||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name));
|
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
|
||||||
|
|
||||||
symbols.push((exported_symbol, SymbolExportLevel::Rust));
|
symbols.push((exported_symbol, SymbolExportLevel::Rust));
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
|
||||||
cx.codegen_unit().name()
|
cx.codegen_unit().name()
|
||||||
);
|
);
|
||||||
|
|
||||||
let symbol_name = self.symbol_name(cx.tcx()).name.as_str();
|
let symbol_name = self.symbol_name(cx.tcx()).name;
|
||||||
|
|
||||||
debug!("symbol {}", &symbol_name);
|
debug!("symbol {}", &symbol_name);
|
||||||
|
|
||||||
|
|
|
@ -558,7 +558,7 @@ impl<'tcx> EncodeContext<'tcx> {
|
||||||
// Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
|
// Encode exported symbols info. This is prefetched in `encode_metadata` so we encode
|
||||||
// this late to give the prefetching as much time as possible to complete.
|
// this late to give the prefetching as much time as possible to complete.
|
||||||
i = self.position();
|
i = self.position();
|
||||||
let exported_symbols = self.tcx.exported_symbols(LOCAL_CRATE);
|
let exported_symbols = tcx.exported_symbols(LOCAL_CRATE);
|
||||||
let exported_symbols = self.encode_exported_symbols(&exported_symbols);
|
let exported_symbols = self.encode_exported_symbols(&exported_symbols);
|
||||||
let exported_symbols_bytes = self.position() - i;
|
let exported_symbols_bytes = self.position() - i;
|
||||||
|
|
||||||
|
@ -622,7 +622,7 @@ impl<'tcx> EncodeContext<'tcx> {
|
||||||
|
|
||||||
let total_bytes = self.position();
|
let total_bytes = self.position();
|
||||||
|
|
||||||
if self.tcx.sess.meta_stats() {
|
if tcx.sess.meta_stats() {
|
||||||
let mut zero_bytes = 0;
|
let mut zero_bytes = 0;
|
||||||
for e in self.opaque.data.iter() {
|
for e in self.opaque.data.iter() {
|
||||||
if *e == 0 {
|
if *e == 0 {
|
||||||
|
@ -1541,7 +1541,7 @@ impl EncodeContext<'tcx> {
|
||||||
) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportLevel)]> {
|
) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportLevel)]> {
|
||||||
// The metadata symbol name is special. It should not show up in
|
// The metadata symbol name is special. It should not show up in
|
||||||
// downstream crates.
|
// downstream crates.
|
||||||
let metadata_symbol_name = SymbolName::new(&metadata_symbol_name(self.tcx));
|
let metadata_symbol_name = SymbolName::new(self.tcx, &metadata_symbol_name(self.tcx));
|
||||||
|
|
||||||
self.lazy(
|
self.lazy(
|
||||||
exported_symbols
|
exported_symbols
|
||||||
|
|
|
@ -26,13 +26,13 @@ pub enum ExportedSymbol<'tcx> {
|
||||||
NonGeneric(DefId),
|
NonGeneric(DefId),
|
||||||
Generic(DefId, SubstsRef<'tcx>),
|
Generic(DefId, SubstsRef<'tcx>),
|
||||||
DropGlue(Ty<'tcx>),
|
DropGlue(Ty<'tcx>),
|
||||||
NoDefId(ty::SymbolName),
|
NoDefId(ty::SymbolName<'tcx>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ExportedSymbol<'tcx> {
|
impl<'tcx> ExportedSymbol<'tcx> {
|
||||||
/// This is the symbol name of an instance if it is instantiated in the
|
/// This is the symbol name of an instance if it is instantiated in the
|
||||||
/// local crate.
|
/// local crate.
|
||||||
pub fn symbol_name_for_local_instance(&self, tcx: TyCtxt<'tcx>) -> ty::SymbolName {
|
pub fn symbol_name_for_local_instance(&self, tcx: TyCtxt<'tcx>) -> ty::SymbolName<'tcx> {
|
||||||
match *self {
|
match *self {
|
||||||
ExportedSymbol::NonGeneric(def_id) => tcx.symbol_name(ty::Instance::mono(tcx, def_id)),
|
ExportedSymbol::NonGeneric(def_id) => tcx.symbol_name(ty::Instance::mono(tcx, def_id)),
|
||||||
ExportedSymbol::Generic(def_id, substs) => {
|
ExportedSymbol::Generic(def_id, substs) => {
|
||||||
|
|
|
@ -68,13 +68,13 @@ impl<'tcx> MonoItem<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn symbol_name(&self, tcx: TyCtxt<'tcx>) -> SymbolName {
|
pub fn symbol_name(&self, tcx: TyCtxt<'tcx>) -> SymbolName<'tcx> {
|
||||||
match *self {
|
match *self {
|
||||||
MonoItem::Fn(instance) => tcx.symbol_name(instance),
|
MonoItem::Fn(instance) => tcx.symbol_name(instance),
|
||||||
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
|
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
|
||||||
MonoItem::GlobalAsm(hir_id) => {
|
MonoItem::GlobalAsm(hir_id) => {
|
||||||
let def_id = tcx.hir().local_def_id(hir_id);
|
let def_id = tcx.hir().local_def_id(hir_id);
|
||||||
SymbolName { name: Symbol::intern(&format!("global_asm_{:?}", def_id)) }
|
SymbolName::new(tcx, &format!("global_asm_{:?}", def_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,9 +335,9 @@ impl<'tcx> CodegenUnit<'tcx> {
|
||||||
// The codegen tests rely on items being process in the same order as
|
// The codegen tests rely on items being process in the same order as
|
||||||
// they appear in the file, so for local items, we sort by node_id first
|
// they appear in the file, so for local items, we sort by node_id first
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct ItemSortKey(Option<HirId>, SymbolName);
|
pub struct ItemSortKey<'tcx>(Option<HirId>, SymbolName<'tcx>);
|
||||||
|
|
||||||
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey {
|
fn item_sort_key<'tcx>(tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>) -> ItemSortKey<'tcx> {
|
||||||
ItemSortKey(
|
ItemSortKey(
|
||||||
match item {
|
match item {
|
||||||
MonoItem::Fn(ref instance) => {
|
MonoItem::Fn(ref instance) => {
|
||||||
|
|
|
@ -691,7 +691,7 @@ rustc_queries! {
|
||||||
/// The `symbol_name` query provides the symbol name for calling a
|
/// The `symbol_name` query provides the symbol name for calling a
|
||||||
/// given instance from the local crate. In particular, it will also
|
/// given instance from the local crate. In particular, it will also
|
||||||
/// look up the correct symbol name of instances from upstream crates.
|
/// look up the correct symbol name of instances from upstream crates.
|
||||||
query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName {
|
query symbol_name(key: ty::Instance<'tcx>) -> ty::SymbolName<'tcx> {
|
||||||
desc { "computing the symbol for `{}`", key }
|
desc { "computing the symbol for `{}`", key }
|
||||||
cache_on_disk_if { true }
|
cache_on_disk_if { true }
|
||||||
}
|
}
|
||||||
|
|
|
@ -262,6 +262,14 @@ where
|
||||||
Ok(decoder.tcx().adt_def(def_id))
|
Ok(decoder.tcx().adt_def(def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn decode_symbol_name<D>(decoder: &mut D) -> Result<ty::SymbolName<'tcx>, D::Error>
|
||||||
|
where
|
||||||
|
D: TyDecoder<'tcx>,
|
||||||
|
{
|
||||||
|
Ok(ty::SymbolName::new(decoder.tcx(), &decoder.read_str()?))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn decode_existential_predicate_slice<D>(
|
pub fn decode_existential_predicate_slice<D>(
|
||||||
decoder: &mut D,
|
decoder: &mut D,
|
||||||
|
@ -504,6 +512,13 @@ macro_rules! implement_ty_decoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'_x, $($typaram),*> SpecializedDecoder<ty::SymbolName<'_x>>
|
||||||
|
for $DecoderName<$($typaram),*> {
|
||||||
|
fn specialized_decode(&mut self) -> Result<ty::SymbolName<'_x>, Self::Error> {
|
||||||
|
unsafe { transmute(decode_symbol_name(self)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'_x, '_y, $($typaram),*> SpecializedDecoder<&'_x ty::List<ty::ExistentialPredicate<'_y>>>
|
impl<'_x, '_y, $($typaram),*> SpecializedDecoder<&'_x ty::List<ty::ExistentialPredicate<'_y>>>
|
||||||
for $DecoderName<$($typaram),*>
|
for $DecoderName<$($typaram),*>
|
||||||
where &'_x ty::List<ty::ExistentialPredicate<'_y>>: UseSpecializedDecodable {
|
where &'_x ty::List<ty::ExistentialPredicate<'_y>>: UseSpecializedDecodable {
|
||||||
|
|
|
@ -50,6 +50,7 @@ use std::hash::{Hash, Hasher};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::str;
|
||||||
|
|
||||||
pub use self::sty::BoundRegion::*;
|
pub use self::sty::BoundRegion::*;
|
||||||
pub use self::sty::InferTy::*;
|
pub use self::sty::InferTy::*;
|
||||||
|
@ -2988,40 +2989,37 @@ pub struct CrateInherentImpls {
|
||||||
pub inherent_impls: DefIdMap<Vec<DefId>>,
|
pub inherent_impls: DefIdMap<Vec<DefId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)]
|
||||||
pub struct SymbolName {
|
pub struct SymbolName<'tcx> {
|
||||||
// FIXME: we don't rely on interning or equality here - better have
|
/// `&str` gives a consistent ordering, which ensures reproducible builds.
|
||||||
// this be a `&'tcx str`.
|
pub name: &'tcx str,
|
||||||
pub name: Symbol,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SymbolName {
|
impl<'tcx> SymbolName<'tcx> {
|
||||||
pub fn new(name: &str) -> SymbolName {
|
pub fn new(tcx: TyCtxt<'tcx>, name: &str) -> SymbolName<'tcx> {
|
||||||
SymbolName { name: Symbol::intern(name) }
|
SymbolName {
|
||||||
|
name: unsafe { str::from_utf8_unchecked(tcx.arena.alloc_slice(name.as_bytes())) },
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialOrd for SymbolName {
|
impl<'tcx> fmt::Display for SymbolName<'tcx> {
|
||||||
fn partial_cmp(&self, other: &SymbolName) -> Option<Ordering> {
|
|
||||||
self.name.as_str().partial_cmp(&other.name.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Ordering must use the chars to ensure reproducible builds.
|
|
||||||
impl Ord for SymbolName {
|
|
||||||
fn cmp(&self, other: &SymbolName) -> Ordering {
|
|
||||||
self.name.as_str().cmp(&other.name.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for SymbolName {
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(&self.name, fmt)
|
fmt::Display::fmt(&self.name, fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for SymbolName {
|
impl<'tcx> fmt::Debug for SymbolName<'tcx> {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt::Display::fmt(&self.name, fmt)
|
fmt::Display::fmt(&self.name, fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> rustc_serialize::UseSpecializedEncodable for SymbolName<'tcx> {
|
||||||
|
fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||||
|
s.emit_str(self.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The decoding takes place in `decode_symbol_name()`.
|
||||||
|
impl<'tcx> rustc_serialize::UseSpecializedDecodable for SymbolName<'tcx> {}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use crate::ty::{self, AdtSizedConstraint, Ty, TyCtxt, TyS};
|
use crate::ty::{self, AdtSizedConstraint, Ty, TyCtxt, TyS};
|
||||||
|
|
||||||
use rustc_span::symbol::Symbol;
|
|
||||||
|
|
||||||
pub(super) trait Value<'tcx>: Sized {
|
pub(super) trait Value<'tcx>: Sized {
|
||||||
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self;
|
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self;
|
||||||
}
|
}
|
||||||
|
@ -21,9 +19,15 @@ impl<'tcx> Value<'tcx> for &'_ TyS<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Value<'tcx> for ty::SymbolName {
|
impl<'tcx> Value<'tcx> for ty::SymbolName<'_> {
|
||||||
fn from_cycle_error(_: TyCtxt<'tcx>) -> Self {
|
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self {
|
||||||
ty::SymbolName { name: Symbol::intern("<error>") }
|
// SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`.
|
||||||
|
// FIXME: Represent the above fact in the trait system somehow.
|
||||||
|
unsafe {
|
||||||
|
std::mem::transmute::<ty::SymbolName<'tcx>, ty::SymbolName<'_>>(ty::SymbolName::new(
|
||||||
|
tcx, "<error>",
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -817,7 +817,7 @@ where
|
||||||
debug!("CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());
|
debug!("CodegenUnit {} estimated size {} :", cgu.name(), cgu.size_estimate());
|
||||||
|
|
||||||
for (mono_item, linkage) in cgu.items() {
|
for (mono_item, linkage) in cgu.items() {
|
||||||
let symbol_name = mono_item.symbol_name(tcx).name.as_str();
|
let symbol_name = mono_item.symbol_name(tcx).name;
|
||||||
let symbol_hash_start = symbol_name.rfind('h');
|
let symbol_hash_start = symbol_name.rfind('h');
|
||||||
let symbol_hash =
|
let symbol_hash =
|
||||||
symbol_hash_start.map(|i| &symbol_name[i..]).unwrap_or("<no hash>");
|
symbol_hash_start.map(|i| &symbol_name[i..]).unwrap_or("<no hash>");
|
||||||
|
|
|
@ -856,8 +856,6 @@ symbols! {
|
||||||
rustc_unsafe_specialization_marker,
|
rustc_unsafe_specialization_marker,
|
||||||
rustc_variance,
|
rustc_variance,
|
||||||
rust_eh_personality,
|
rust_eh_personality,
|
||||||
rust_eh_register_frames,
|
|
||||||
rust_eh_unregister_frames,
|
|
||||||
rustfmt,
|
rustfmt,
|
||||||
rust_oom,
|
rust_oom,
|
||||||
rvalue_static_promotion,
|
rvalue_static_promotion,
|
||||||
|
|
|
@ -106,8 +106,6 @@ use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_middle::ty::{self, Instance, TyCtxt};
|
use rustc_middle::ty::{self, Instance, TyCtxt};
|
||||||
use rustc_session::config::SymbolManglingVersion;
|
use rustc_session::config::SymbolManglingVersion;
|
||||||
|
|
||||||
use rustc_span::symbol::Symbol;
|
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
mod legacy;
|
mod legacy;
|
||||||
|
@ -133,7 +131,7 @@ pub fn provide(providers: &mut Providers) {
|
||||||
// The `symbol_name` query provides the symbol name for calling a given
|
// The `symbol_name` query provides the symbol name for calling a given
|
||||||
// instance from the local crate. In particular, it will also look up the
|
// instance from the local crate. In particular, it will also look up the
|
||||||
// correct symbol name of instances from upstream crates.
|
// correct symbol name of instances from upstream crates.
|
||||||
fn symbol_name_provider(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
|
fn symbol_name_provider(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> {
|
||||||
let symbol_name = compute_symbol_name(tcx, instance, || {
|
let symbol_name = compute_symbol_name(tcx, instance, || {
|
||||||
// This closure determines the instantiating crate for instances that
|
// This closure determines the instantiating crate for instances that
|
||||||
// need an instantiating-crate-suffix for their symbol name, in order
|
// need an instantiating-crate-suffix for their symbol name, in order
|
||||||
|
@ -149,7 +147,7 @@ fn symbol_name_provider(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::Symb
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ty::SymbolName { name: Symbol::intern(&symbol_name) }
|
ty::SymbolName::new(tcx, &symbol_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the symbol name for the given instance. This function will call
|
/// Computes the symbol name for the given instance. This function will call
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl SymbolNamesTest<'tcx> {
|
||||||
let instance = Instance::mono(tcx, def_id.to_def_id());
|
let instance = Instance::mono(tcx, def_id.to_def_id());
|
||||||
let mangled = self.tcx.symbol_name(instance);
|
let mangled = self.tcx.symbol_name(instance);
|
||||||
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));
|
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));
|
||||||
if let Ok(demangling) = rustc_demangle::try_demangle(&mangled.name.as_str()) {
|
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
|
||||||
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling));
|
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling));
|
||||||
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));
|
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue