Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change SymbolName::name from InternedString to Symbol.
This requires changing the `PartialOrd`/`Ord` implementations to look at
the chars rather than the symbol index.
  • Loading branch information
nnethercote committed Oct 21, 2019
commit dddacf1eb3efb3c2111b27456be43c21e4497ffd
4 changes: 2 additions & 2 deletions src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use crate::hir::HirId;
use syntax::symbol::InternedString;
use syntax::symbol::{InternedString, Symbol};
use syntax::attr::InlineAttr;
use syntax::source_map::Span;
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
Expand Down Expand Up @@ -80,7 +80,7 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::GlobalAsm(hir_id) => {
let def_id = tcx.hir().local_def_id(hir_id);
SymbolName {
name: InternedString::intern(&format!("global_asm_{:?}", def_id))
name: Symbol::intern(&format!("global_asm_{:?}", def_id))
}
}
}
Expand Down
21 changes: 17 additions & 4 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::ops::Range;
use syntax::ast::{self, Name, Ident, NodeId};
use syntax::attr;
use syntax_expand::hygiene::ExpnId;
use syntax::symbol::{kw, sym, Symbol, InternedString};
use syntax::symbol::{kw, sym, Symbol};
use syntax_pos::Span;

use smallvec;
Expand Down Expand Up @@ -3429,11 +3429,11 @@ pub struct CrateInherentImpls {
pub inherent_impls: DefIdMap<Vec<DefId>>,
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct SymbolName {
// FIXME: we don't rely on interning or equality here - better have
// this be a `&'tcx str`.
pub name: InternedString
pub name: Symbol
}

impl_stable_hash_for!(struct self::SymbolName {
Expand All @@ -3443,11 +3443,24 @@ impl_stable_hash_for!(struct self::SymbolName {
impl SymbolName {
pub fn new(name: &str) -> SymbolName {
SymbolName {
name: InternedString::intern(name)
name: Symbol::intern(name)
}
}
}

impl PartialOrd for SymbolName {
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 {
fmt::Display::fmt(&self.name, fmt)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/query/values.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ty::{self, Ty, TyCtxt, AdtSizedConstraint};
use crate::ty::util::NeedsDrop;

use syntax::symbol::InternedString;
use syntax::symbol::Symbol;

pub(super) trait Value<'tcx>: Sized {
fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self;
Expand All @@ -22,7 +22,7 @@ impl<'tcx> Value<'tcx> for Ty<'tcx> {

impl<'tcx> Value<'tcx> for ty::SymbolName {
fn from_cycle_error(_: TyCtxt<'tcx>) -> Self {
ty::SymbolName { name: InternedString::intern("<error>") }
ty::SymbolName { name: Symbol::intern("<error>") }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl CodegenCx<'ll, 'tcx> {
def_id);

let ty = instance.ty(self.tcx);
let sym = self.tcx.symbol_name(instance).name.as_symbol();
let sym = self.tcx.symbol_name(instance).name;

debug!("get_static: sym={} instance={:?}", sym, instance);

Expand Down
23 changes: 10 additions & 13 deletions src/librustc_codegen_utils/symbol_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ use rustc::ty::query::Providers;
use rustc::ty::{self, TyCtxt, Instance};
use rustc::mir::mono::{MonoItem, InstantiationMode};

use syntax_pos::symbol::InternedString;
use syntax_pos::symbol::Symbol;

use log::debug;

Expand All @@ -112,7 +112,7 @@ pub fn provide(providers: &mut Providers<'_>) {
};
}

fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {
fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Symbol {
let def_id = instance.def_id();
let substs = instance.substs;

Expand All @@ -123,13 +123,11 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {
if def_id.is_local() {
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator();
return
InternedString::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator));
return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator));
}
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
let disambiguator = tcx.sess.local_crate_disambiguator();
return
InternedString::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator));
return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator));
}
}

Expand All @@ -146,23 +144,22 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {
let attrs = tcx.codegen_fn_attrs(def_id);
if is_foreign {
if let Some(name) = attrs.link_name {
return name.as_interned_str();
return name;
}
// Don't mangle foreign items.
return tcx.item_name(def_id).as_interned_str();
return tcx.item_name(def_id);
}

if let Some(name) = &attrs.export_name {
if let Some(name) = attrs.export_name {
// Use provided name
return name.as_interned_str();
return name;
}

if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
// Don't mangle
return tcx.item_name(def_id).as_interned_str();
return tcx.item_name(def_id);
}


let is_generic = substs.non_erasable_generics().next().is_some();
let avoid_cross_crate_conflicts =
// If this is an instance of a generic function, we also hash in
Expand Down Expand Up @@ -222,5 +219,5 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {
SymbolManglingVersion::V0 => v0::mangle(tcx, instance, instantiating_crate),
};

InternedString::intern(&mangled)
Symbol::intern(&mangled)
}