Skip to content

Commit dddacf1

Browse files
committed
Change SymbolName::name from InternedString to Symbol.
This requires changing the `PartialOrd`/`Ord` implementations to look at the chars rather than the symbol index.
1 parent b8214e9 commit dddacf1

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
lines changed

src/librustc/mir/mono.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
22
use crate::hir::HirId;
3-
use syntax::symbol::InternedString;
3+
use syntax::symbol::{InternedString, Symbol};
44
use syntax::attr::InlineAttr;
55
use syntax::source_map::Span;
66
use crate::ty::{Instance, InstanceDef, TyCtxt, SymbolName, subst::InternalSubsts};
@@ -80,7 +80,7 @@ impl<'tcx> MonoItem<'tcx> {
8080
MonoItem::GlobalAsm(hir_id) => {
8181
let def_id = tcx.hir().local_def_id(hir_id);
8282
SymbolName {
83-
name: InternedString::intern(&format!("global_asm_{:?}", def_id))
83+
name: Symbol::intern(&format!("global_asm_{:?}", def_id))
8484
}
8585
}
8686
}

src/librustc/ty/mod.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use std::ops::Range;
4646
use syntax::ast::{self, Name, Ident, NodeId};
4747
use syntax::attr;
4848
use syntax_expand::hygiene::ExpnId;
49-
use syntax::symbol::{kw, sym, Symbol, InternedString};
49+
use syntax::symbol::{kw, sym, Symbol};
5050
use syntax_pos::Span;
5151

5252
use smallvec;
@@ -3429,11 +3429,11 @@ pub struct CrateInherentImpls {
34293429
pub inherent_impls: DefIdMap<Vec<DefId>>,
34303430
}
34313431

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

34393439
impl_stable_hash_for!(struct self::SymbolName {
@@ -3443,11 +3443,24 @@ impl_stable_hash_for!(struct self::SymbolName {
34433443
impl SymbolName {
34443444
pub fn new(name: &str) -> SymbolName {
34453445
SymbolName {
3446-
name: InternedString::intern(name)
3446+
name: Symbol::intern(name)
34473447
}
34483448
}
34493449
}
34503450

3451+
impl PartialOrd for SymbolName {
3452+
fn partial_cmp(&self, other: &SymbolName) -> Option<Ordering> {
3453+
self.name.as_str().partial_cmp(&other.name.as_str())
3454+
}
3455+
}
3456+
3457+
/// Ordering must use the chars to ensure reproducible builds.
3458+
impl Ord for SymbolName {
3459+
fn cmp(&self, other: &SymbolName) -> Ordering {
3460+
self.name.as_str().cmp(&other.name.as_str())
3461+
}
3462+
}
3463+
34513464
impl fmt::Display for SymbolName {
34523465
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
34533466
fmt::Display::fmt(&self.name, fmt)

src/librustc/ty/query/values.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::ty::{self, Ty, TyCtxt, AdtSizedConstraint};
22
use crate::ty::util::NeedsDrop;
33

4-
use syntax::symbol::InternedString;
4+
use syntax::symbol::Symbol;
55

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

2323
impl<'tcx> Value<'tcx> for ty::SymbolName {
2424
fn from_cycle_error(_: TyCtxt<'tcx>) -> Self {
25-
ty::SymbolName { name: InternedString::intern("<error>") }
25+
ty::SymbolName { name: Symbol::intern("<error>") }
2626
}
2727
}
2828

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl CodegenCx<'ll, 'tcx> {
221221
def_id);
222222

223223
let ty = instance.ty(self.tcx);
224-
let sym = self.tcx.symbol_name(instance).name.as_symbol();
224+
let sym = self.tcx.symbol_name(instance).name;
225225

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

src/librustc_codegen_utils/symbol_names.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ use rustc::ty::query::Providers;
9595
use rustc::ty::{self, TyCtxt, Instance};
9696
use rustc::mir::mono::{MonoItem, InstantiationMode};
9797

98-
use syntax_pos::symbol::InternedString;
98+
use syntax_pos::symbol::Symbol;
9999

100100
use log::debug;
101101

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

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

@@ -123,13 +123,11 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {
123123
if def_id.is_local() {
124124
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
125125
let disambiguator = tcx.sess.local_crate_disambiguator();
126-
return
127-
InternedString::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator));
126+
return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator));
128127
}
129128
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
130129
let disambiguator = tcx.sess.local_crate_disambiguator();
131-
return
132-
InternedString::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator));
130+
return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator));
133131
}
134132
}
135133

@@ -146,23 +144,22 @@ fn symbol_name(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> InternedString {
146144
let attrs = tcx.codegen_fn_attrs(def_id);
147145
if is_foreign {
148146
if let Some(name) = attrs.link_name {
149-
return name.as_interned_str();
147+
return name;
150148
}
151149
// Don't mangle foreign items.
152-
return tcx.item_name(def_id).as_interned_str();
150+
return tcx.item_name(def_id);
153151
}
154152

155-
if let Some(name) = &attrs.export_name {
153+
if let Some(name) = attrs.export_name {
156154
// Use provided name
157-
return name.as_interned_str();
155+
return name;
158156
}
159157

160158
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
161159
// Don't mangle
162-
return tcx.item_name(def_id).as_interned_str();
160+
return tcx.item_name(def_id);
163161
}
164162

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

225-
InternedString::intern(&mangled)
222+
Symbol::intern(&mangled)
226223
}

0 commit comments

Comments
 (0)