Skip to content

Commit 08e2f05

Browse files
committed
Remove InternedString.
By using `LocalInternedString` instead for the few remaining uses.
1 parent 2da7a9c commit 08e2f05

File tree

4 files changed

+17
-127
lines changed

4 files changed

+17
-127
lines changed

src/librustc/hir/map/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
186186
});
187187

188188
let mut upstream_crates: Vec<_> = cstore.crates_untracked().iter().map(|&cnum| {
189-
let name = cstore.crate_name_untracked(cnum).as_interned_str();
189+
let name = cstore.crate_name_untracked(cnum);
190190
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
191191
let hash = cstore.crate_hash_untracked(cnum);
192192
(name, disambiguator, hash)
193193
}).collect();
194194

195-
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name, dis));
195+
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis));
196196

197197
// We hash the final, remapped names of all local source files so we
198198
// don't have to include the path prefix remapping commandline args.

src/librustc/ich/impls_syntax.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::mem;
99
use syntax::ast;
1010
use syntax::feature_gate;
1111
use syntax::parse::token;
12-
use syntax::symbol::InternedString;
12+
use syntax::symbol::LocalInternedString;
1313
use syntax::tokenstream;
1414
use syntax_pos::SourceFile;
1515

@@ -18,20 +18,21 @@ use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
1818
use smallvec::SmallVec;
1919
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
2020

21-
impl<'a> HashStable<StableHashingContext<'a>> for InternedString {
21+
impl<'a> HashStable<StableHashingContext<'a>> for LocalInternedString {
2222
#[inline]
2323
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
24-
self.with(|s| s.hash_stable(hcx, hasher))
24+
let str = self as &str;
25+
str.hash_stable(hcx, hasher)
2526
}
2627
}
2728

28-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for InternedString {
29-
type KeyType = InternedString;
29+
impl<'a> ToStableHashKey<StableHashingContext<'a>> for LocalInternedString {
30+
type KeyType = LocalInternedString;
3031

3132
#[inline]
3233
fn to_stable_hash_key(&self,
3334
_: &StableHashingContext<'a>)
34-
-> InternedString {
35+
-> LocalInternedString {
3536
self.clone()
3637
}
3738
}
@@ -44,13 +45,13 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
4445
}
4546

4647
impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::Name {
47-
type KeyType = InternedString;
48+
type KeyType = LocalInternedString;
4849

4950
#[inline]
5051
fn to_stable_hash_key(&self,
5152
_: &StableHashingContext<'a>)
52-
-> InternedString {
53-
self.as_interned_str()
53+
-> LocalInternedString {
54+
self.as_str()
5455
}
5556
}
5657

src/libsyntax_pos/symbol.rs

+5-115
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_macros::symbols;
99
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
1010
use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable};
1111

12-
use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
12+
use std::cmp::{PartialEq, PartialOrd, Ord};
1313
use std::fmt;
1414
use std::hash::{Hash, Hasher};
1515
use std::str;
@@ -766,11 +766,6 @@ impl Ident {
766766
Ident::with_dummy_span(kw::Invalid)
767767
}
768768

769-
/// Maps an interned string to an identifier with an empty syntax context.
770-
pub fn from_interned_str(string: InternedString) -> Ident {
771-
Ident::with_dummy_span(string.as_symbol())
772-
}
773-
774769
/// Maps a string to an identifier with a dummy span.
775770
pub fn from_str(string: &str) -> Ident {
776771
Ident::with_dummy_span(Symbol::intern(string))
@@ -813,11 +808,6 @@ impl Ident {
813808
pub fn as_str(self) -> LocalInternedString {
814809
self.name.as_str()
815810
}
816-
817-
/// Convert the name to an `InternedString`.
818-
pub fn as_interned_str(self) -> InternedString {
819-
self.name.as_interned_str()
820-
}
821811
}
822812

823813
impl PartialEq for Ident {
@@ -903,15 +893,6 @@ impl Symbol {
903893
})
904894
}
905895

906-
/// Access two symbols' chars. This is a slowish operation because it
907-
/// requires locking the symbol interner, but it is faster than calling
908-
/// `with()` twice.
909-
fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: Symbol, f: F) -> R {
910-
with_interner(|interner| {
911-
f(interner.get(self), interner.get(other))
912-
})
913-
}
914-
915896
/// Convert to a `LocalInternedString`. This is a slowish operation because
916897
/// it requires locking the symbol interner.
917898
pub fn as_str(self) -> LocalInternedString {
@@ -922,11 +903,6 @@ impl Symbol {
922903
})
923904
}
924905

925-
/// Convert to an `InternedString`.
926-
pub fn as_interned_str(self) -> InternedString {
927-
InternedString { symbol: self }
928-
}
929-
930906
pub fn as_u32(self) -> u32 {
931907
self.0.as_u32()
932908
}
@@ -1105,9 +1081,9 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
11051081
GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock()))
11061082
}
11071083

1108-
/// An alternative to `Symbol` and `InternedString`, useful when the chars
1109-
/// within the symbol need to be accessed. It deliberately has limited
1110-
/// functionality and should only be used for temporary values.
1084+
/// An alternative to `Symbol`, useful when the chars within the symbol need to
1085+
/// be accessed. It deliberately has limited functionality and should only be
1086+
/// used for temporary values.
11111087
///
11121088
/// Because the interner outlives any thread which uses this type, we can
11131089
/// safely treat `string` which points to interner data, as an immortal string,
@@ -1116,7 +1092,7 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
11161092
// FIXME: ensure that the interner outlives any thread which uses
11171093
// `LocalInternedString`, by creating a new thread right after constructing the
11181094
// interner.
1119-
#[derive(Eq, PartialOrd, Ord)]
1095+
#[derive(Clone, Eq, PartialOrd, Ord)]
11201096
pub struct LocalInternedString {
11211097
string: &'static str,
11221098
}
@@ -1157,89 +1133,3 @@ impl fmt::Display for LocalInternedString {
11571133
fmt::Display::fmt(self.string, f)
11581134
}
11591135
}
1160-
1161-
/// An alternative to `Symbol` that is focused on string contents.
1162-
///
1163-
/// Its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1164-
/// string chars rather than the symbol integer. This is useful when hash
1165-
/// stability is required across compile sessions, or a guaranteed sort
1166-
/// ordering is required.
1167-
#[derive(Clone, Copy, PartialEq, Eq)]
1168-
pub struct InternedString {
1169-
symbol: Symbol,
1170-
}
1171-
1172-
impl InternedString {
1173-
/// Maps a string to its interned representation.
1174-
pub fn intern(string: &str) -> Self {
1175-
InternedString {
1176-
symbol: Symbol::intern(string)
1177-
}
1178-
}
1179-
1180-
pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
1181-
self.symbol.with(f)
1182-
}
1183-
1184-
fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: &InternedString, f: F) -> R {
1185-
self.symbol.with2(other.symbol, f)
1186-
}
1187-
1188-
pub fn as_symbol(self) -> Symbol {
1189-
self.symbol
1190-
}
1191-
1192-
/// Convert to a `LocalInternedString`. This is a slowish operation because it
1193-
/// requires locking the symbol interner.
1194-
pub fn as_str(self) -> LocalInternedString {
1195-
self.symbol.as_str()
1196-
}
1197-
}
1198-
1199-
impl Hash for InternedString {
1200-
fn hash<H: Hasher>(&self, state: &mut H) {
1201-
self.with(|str| str.hash(state))
1202-
}
1203-
}
1204-
1205-
impl PartialOrd<InternedString> for InternedString {
1206-
fn partial_cmp(&self, other: &InternedString) -> Option<Ordering> {
1207-
if self.symbol == other.symbol {
1208-
return Some(Ordering::Equal);
1209-
}
1210-
self.with2(other, |self_str, other_str| self_str.partial_cmp(other_str))
1211-
}
1212-
}
1213-
1214-
impl Ord for InternedString {
1215-
fn cmp(&self, other: &InternedString) -> Ordering {
1216-
if self.symbol == other.symbol {
1217-
return Ordering::Equal;
1218-
}
1219-
self.with2(other, |self_str, other_str| self_str.cmp(other_str))
1220-
}
1221-
}
1222-
1223-
impl fmt::Debug for InternedString {
1224-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1225-
self.with(|str| fmt::Debug::fmt(&str, f))
1226-
}
1227-
}
1228-
1229-
impl fmt::Display for InternedString {
1230-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1231-
self.with(|str| fmt::Display::fmt(&str, f))
1232-
}
1233-
}
1234-
1235-
impl Decodable for InternedString {
1236-
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
1237-
Ok(InternedString::intern(&d.read_str()?))
1238-
}
1239-
}
1240-
1241-
impl Encodable for InternedString {
1242-
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
1243-
self.with(|string| s.emit_str(string))
1244-
}
1245-
}

src/tools/linkchecker/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ fn check(cache: &mut Cache,
126126
// FIXME(#32129)
127127
if file.ends_with("std/string/struct.String.html") ||
128128
file.ends_with("interpret/struct.ImmTy.html") ||
129-
file.ends_with("symbol/struct.InternedString.html") ||
130129
file.ends_with("ast/struct.ThinVec.html") ||
131130
file.ends_with("util/struct.ThinVec.html") ||
132131
file.ends_with("layout/struct.TyLayout.html") ||

0 commit comments

Comments
 (0)