Skip to content

Commit c020d64

Browse files
authored
Rollup merge of rust-lang#65657 - nnethercote:rm-InternedString-properly, r=eddyb
Remove `InternedString` This PR removes `InternedString` by converting all occurrences to `Symbol`. There are a handful of places that need to use the symbol chars instead of the symbol index, e.g. for stable sorting; local conversions `LocalInternedString` is used in those places. r? @eddyb
2 parents d8015f6 + 08e2f05 commit c020d64

File tree

54 files changed

+246
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+246
-364
lines changed

src/librustc/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::ich::{Fingerprint, StableHashingContext};
5959
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
6060
use std::fmt;
6161
use std::hash::Hash;
62-
use syntax_pos::symbol::InternedString;
62+
use syntax_pos::symbol::Symbol;
6363
use crate::traits;
6464
use crate::traits::query::{
6565
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
@@ -426,7 +426,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
426426

427427
[anon] TraitSelect,
428428

429-
[] CompileCodegenUnit(InternedString),
429+
[] CompileCodegenUnit(Symbol),
430430

431431
[eval_always] Analysis(CrateNum),
432432
]);

src/librustc/hir/lowering.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -792,15 +792,15 @@ impl<'a> LoweringContext<'a> {
792792
// really show up for end-user.
793793
let (str_name, kind) = match hir_name {
794794
ParamName::Plain(ident) => (
795-
ident.as_interned_str(),
795+
ident.name,
796796
hir::LifetimeParamKind::InBand,
797797
),
798798
ParamName::Fresh(_) => (
799-
kw::UnderscoreLifetime.as_interned_str(),
799+
kw::UnderscoreLifetime,
800800
hir::LifetimeParamKind::Elided,
801801
),
802802
ParamName::Error => (
803-
kw::UnderscoreLifetime.as_interned_str(),
803+
kw::UnderscoreLifetime,
804804
hir::LifetimeParamKind::Error,
805805
),
806806
};
@@ -1590,7 +1590,7 @@ impl<'a> LoweringContext<'a> {
15901590
self.context.resolver.definitions().create_def_with_parent(
15911591
self.parent,
15921592
def_node_id,
1593-
DefPathData::LifetimeNs(name.ident().as_interned_str()),
1593+
DefPathData::LifetimeNs(name.ident().name),
15941594
ExpnId::root(),
15951595
lifetime.span);
15961596

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/hir/map/def_collector.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a> DefCollector<'a> {
5757

5858
// For async functions, we need to create their inner defs inside of a
5959
// closure to match their desugared representation.
60-
let fn_def_data = DefPathData::ValueNs(name.as_interned_str());
60+
let fn_def_data = DefPathData::ValueNs(name);
6161
let fn_def = self.create_def(id, fn_def_data, span);
6262
return self.with_parent(fn_def, |this| {
6363
this.create_def(return_impl_trait_id, DefPathData::ImplTrait, span);
@@ -83,8 +83,7 @@ impl<'a> DefCollector<'a> {
8383
.unwrap_or_else(|| {
8484
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
8585
sym::integer(self.definitions.placeholder_field_indices[&node_id])
86-
})
87-
.as_interned_str();
86+
});
8887
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
8988
self.with_parent(def, |this| visit::walk_struct_field(this, field));
9089
}
@@ -109,7 +108,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
109108
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
110109
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
111110
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
112-
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
111+
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
113112
ItemKind::Fn(
114113
ref decl,
115114
ref header,
@@ -127,8 +126,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
127126
)
128127
}
129128
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
130-
DefPathData::ValueNs(i.ident.as_interned_str()),
131-
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.as_interned_str()),
129+
DefPathData::ValueNs(i.ident.name),
130+
ItemKind::MacroDef(..) => DefPathData::MacroNs(i.ident.name),
132131
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id),
133132
ItemKind::GlobalAsm(..) => DefPathData::Misc,
134133
ItemKind::Use(..) => {
@@ -162,7 +161,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
162161
}
163162

164163
let def = self.create_def(foreign_item.id,
165-
DefPathData::ValueNs(foreign_item.ident.as_interned_str()),
164+
DefPathData::ValueNs(foreign_item.ident.name),
166165
foreign_item.span);
167166

168167
self.with_parent(def, |this| {
@@ -175,7 +174,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
175174
return self.visit_macro_invoc(v.id);
176175
}
177176
let def = self.create_def(v.id,
178-
DefPathData::TypeNs(v.ident.as_interned_str()),
177+
DefPathData::TypeNs(v.ident.name),
179178
v.span);
180179
self.with_parent(def, |this| {
181180
if let Some(ctor_hir_id) = v.data.ctor_id() {
@@ -202,7 +201,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
202201
self.visit_macro_invoc(param.id);
203202
return;
204203
}
205-
let name = param.ident.as_interned_str();
204+
let name = param.ident.name;
206205
let def_path_data = match param.kind {
207206
GenericParamKind::Lifetime { .. } => DefPathData::LifetimeNs(name),
208207
GenericParamKind::Type { .. } => DefPathData::TypeNs(name),
@@ -216,9 +215,9 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
216215
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
217216
let def_data = match ti.kind {
218217
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
219-
DefPathData::ValueNs(ti.ident.as_interned_str()),
218+
DefPathData::ValueNs(ti.ident.name),
220219
TraitItemKind::Type(..) => {
221-
DefPathData::TypeNs(ti.ident.as_interned_str())
220+
DefPathData::TypeNs(ti.ident.name)
222221
},
223222
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id),
224223
};
@@ -243,12 +242,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
243242
body,
244243
)
245244
}
246-
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
247-
DefPathData::ValueNs(ii.ident.as_interned_str()),
245+
ImplItemKind::Method(..) |
246+
ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
248247
ImplItemKind::TyAlias(..) |
249-
ImplItemKind::OpaqueTy(..) => {
250-
DefPathData::TypeNs(ii.ident.as_interned_str())
251-
},
248+
ImplItemKind::OpaqueTy(..) => DefPathData::TypeNs(ii.ident.name),
252249
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
253250
};
254251

src/librustc/hir/map/definitions.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::fmt::Write;
1818
use std::hash::Hash;
1919
use syntax::ast;
2020
use syntax_expand::hygiene::ExpnId;
21-
use syntax::symbol::{Symbol, sym, InternedString};
21+
use syntax::symbol::{Symbol, sym};
2222
use syntax_pos::{Span, DUMMY_SP};
2323

2424
/// The `DefPathTable` maps `DefIndex`es to `DefKey`s and vice versa.
@@ -136,7 +136,9 @@ impl DefKey {
136136

137137
::std::mem::discriminant(data).hash(&mut hasher);
138138
if let Some(name) = data.get_opt_name() {
139-
name.hash(&mut hasher);
139+
// Get a stable hash by considering the symbol chars rather than
140+
// the symbol index.
141+
name.as_str().hash(&mut hasher);
140142
}
141143

142144
disambiguator.hash(&mut hasher);
@@ -218,7 +220,7 @@ impl DefPath {
218220
for component in &self.data {
219221
write!(s,
220222
"::{}[{}]",
221-
component.data.as_interned_str(),
223+
component.data.as_symbol(),
222224
component.disambiguator)
223225
.unwrap();
224226
}
@@ -238,11 +240,11 @@ impl DefPath {
238240

239241
for component in &self.data {
240242
if component.disambiguator == 0 {
241-
write!(s, "::{}", component.data.as_interned_str()).unwrap();
243+
write!(s, "::{}", component.data.as_symbol()).unwrap();
242244
} else {
243245
write!(s,
244246
"{}[{}]",
245-
component.data.as_interned_str(),
247+
component.data.as_symbol(),
246248
component.disambiguator)
247249
.unwrap();
248250
}
@@ -262,11 +264,11 @@ impl DefPath {
262264
opt_delimiter.map(|d| s.push(d));
263265
opt_delimiter = Some('-');
264266
if component.disambiguator == 0 {
265-
write!(s, "{}", component.data.as_interned_str()).unwrap();
267+
write!(s, "{}", component.data.as_symbol()).unwrap();
266268
} else {
267269
write!(s,
268270
"{}[{}]",
269-
component.data.as_interned_str(),
271+
component.data.as_symbol(),
270272
component.disambiguator)
271273
.unwrap();
272274
}
@@ -290,13 +292,13 @@ pub enum DefPathData {
290292
/// An impl.
291293
Impl,
292294
/// Something in the type namespace.
293-
TypeNs(InternedString),
295+
TypeNs(Symbol),
294296
/// Something in the value namespace.
295-
ValueNs(InternedString),
297+
ValueNs(Symbol),
296298
/// Something in the macro namespace.
297-
MacroNs(InternedString),
299+
MacroNs(Symbol),
298300
/// Something in the lifetime namespace.
299-
LifetimeNs(InternedString),
301+
LifetimeNs(Symbol),
300302
/// A closure expression.
301303
ClosureExpr,
302304

@@ -311,7 +313,7 @@ pub enum DefPathData {
311313
/// Identifies a piece of crate metadata that is global to a whole crate
312314
/// (as opposed to just one item). `GlobalMetaData` components are only
313315
/// supposed to show up right below the crate root.
314-
GlobalMetaData(InternedString),
316+
GlobalMetaData(Symbol),
315317
}
316318

317319
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
@@ -545,7 +547,7 @@ impl Definitions {
545547
}
546548

547549
impl DefPathData {
548-
pub fn get_opt_name(&self) -> Option<InternedString> {
550+
pub fn get_opt_name(&self) -> Option<Symbol> {
549551
use self::DefPathData::*;
550552
match *self {
551553
TypeNs(name) |
@@ -564,15 +566,15 @@ impl DefPathData {
564566
}
565567
}
566568

567-
pub fn as_interned_str(&self) -> InternedString {
569+
pub fn as_symbol(&self) -> Symbol {
568570
use self::DefPathData::*;
569-
let s = match *self {
571+
match *self {
570572
TypeNs(name) |
571573
ValueNs(name) |
572574
MacroNs(name) |
573575
LifetimeNs(name) |
574576
GlobalMetaData(name) => {
575-
return name
577+
name
576578
}
577579
// Note that this does not show up in user print-outs.
578580
CrateRoot => sym::double_braced_crate,
@@ -582,13 +584,11 @@ impl DefPathData {
582584
Ctor => sym::double_braced_constructor,
583585
AnonConst => sym::double_braced_constant,
584586
ImplTrait => sym::double_braced_opaque,
585-
};
586-
587-
s.as_interned_str()
587+
}
588588
}
589589

590590
pub fn to_string(&self) -> String {
591-
self.as_interned_str().to_string()
591+
self.as_symbol().to_string()
592592
}
593593
}
594594

@@ -610,7 +610,7 @@ macro_rules! define_global_metadata_kind {
610610
definitions.create_def_with_parent(
611611
CRATE_DEF_INDEX,
612612
ast::DUMMY_NODE_ID,
613-
DefPathData::GlobalMetaData(instance.name().as_interned_str()),
613+
DefPathData::GlobalMetaData(instance.name()),
614614
ExpnId::root(),
615615
DUMMY_SP
616616
);
@@ -624,7 +624,7 @@ macro_rules! define_global_metadata_kind {
624624
let def_key = DefKey {
625625
parent: Some(CRATE_DEF_INDEX),
626626
disambiguated_data: DisambiguatedDefPathData {
627-
data: DefPathData::GlobalMetaData(self.name().as_interned_str()),
627+
data: DefPathData::GlobalMetaData(self.name()),
628628
disambiguator: 0,
629629
}
630630
};

src/librustc/hir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::ty::query::Providers;
1919
use crate::util::nodemap::{NodeMap, FxHashSet};
2020

2121
use errors::FatalError;
22-
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString, MultiSpan};
22+
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
2323
use syntax::source_map::Spanned;
2424
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
2525
use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
@@ -628,9 +628,9 @@ impl Generics {
628628
own_counts
629629
}
630630

631-
pub fn get_named(&self, name: InternedString) -> Option<&GenericParam> {
631+
pub fn get_named(&self, name: Symbol) -> Option<&GenericParam> {
632632
for param in &self.params {
633-
if name == param.name.ident().as_interned_str() {
633+
if name == param.name.ident().name {
634634
return Some(param);
635635
}
636636
}

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/librustc/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
542542
disambiguated_data: &DisambiguatedDefPathData,
543543
) -> Result<Self::Path, Self::Error> {
544544
let mut path = print_prefix(self)?;
545-
path.push(disambiguated_data.data.as_interned_str().to_string());
545+
path.push(disambiguated_data.data.as_symbol().to_string());
546546
Ok(path)
547547
}
548548
fn path_generic_args(

0 commit comments

Comments
 (0)