Skip to content

Commit 0533837

Browse files
committed
Auto merge of #65543 - nnethercote:rm-InternedString, r=<try>
[DO NOT MERGE] Remove `InternedString` This is a proof of concept relating to #60869. It does the following: - Makes `Symbol` equivalent to `InternedString`, primarily by Changing `Symbol`'s `PartialOrd`, `Ord`, and `Hash` impls to work on the chars instead of the index. - Removes `InternedString`. It shows that this approach works, but causes some performance regressions. r? @ghost
2 parents fa0f7d0 + f0648cb commit 0533837

File tree

62 files changed

+267
-381
lines changed

Some content is hidden

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

62 files changed

+267
-381
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ 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)

src/librustc/hir/map/def_collector.rs

+12-13
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
};
@@ -244,10 +243,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
244243
)
245244
}
246245
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
247-
DefPathData::ValueNs(ii.ident.as_interned_str()),
246+
DefPathData::ValueNs(ii.ident.name),
248247
ImplItemKind::TyAlias(..) |
249248
ImplItemKind::OpaqueTy(..) => {
250-
DefPathData::TypeNs(ii.ident.as_interned_str())
249+
DefPathData::TypeNs(ii.ident.name)
251250
},
252251
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
253252
};

src/librustc/hir/map/definitions.rs

+19-21
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.
@@ -218,7 +218,7 @@ impl DefPath {
218218
for component in &self.data {
219219
write!(s,
220220
"::{}[{}]",
221-
component.data.as_interned_str(),
221+
component.data.as_symbol(),
222222
component.disambiguator)
223223
.unwrap();
224224
}
@@ -238,11 +238,11 @@ impl DefPath {
238238

239239
for component in &self.data {
240240
if component.disambiguator == 0 {
241-
write!(s, "::{}", component.data.as_interned_str()).unwrap();
241+
write!(s, "::{}", component.data.as_symbol()).unwrap();
242242
} else {
243243
write!(s,
244244
"{}[{}]",
245-
component.data.as_interned_str(),
245+
component.data.as_symbol(),
246246
component.disambiguator)
247247
.unwrap();
248248
}
@@ -262,11 +262,11 @@ impl DefPath {
262262
opt_delimiter.map(|d| s.push(d));
263263
opt_delimiter = Some('-');
264264
if component.disambiguator == 0 {
265-
write!(s, "{}", component.data.as_interned_str()).unwrap();
265+
write!(s, "{}", component.data.as_symbol()).unwrap();
266266
} else {
267267
write!(s,
268268
"{}[{}]",
269-
component.data.as_interned_str(),
269+
component.data.as_symbol(),
270270
component.disambiguator)
271271
.unwrap();
272272
}
@@ -290,13 +290,13 @@ pub enum DefPathData {
290290
/// An impl.
291291
Impl,
292292
/// Something in the type namespace.
293-
TypeNs(InternedString),
293+
TypeNs(Symbol),
294294
/// Something in the value namespace.
295-
ValueNs(InternedString),
295+
ValueNs(Symbol),
296296
/// Something in the macro namespace.
297-
MacroNs(InternedString),
297+
MacroNs(Symbol),
298298
/// Something in the lifetime namespace.
299-
LifetimeNs(InternedString),
299+
LifetimeNs(Symbol),
300300
/// A closure expression.
301301
ClosureExpr,
302302

@@ -311,7 +311,7 @@ pub enum DefPathData {
311311
/// Identifies a piece of crate metadata that is global to a whole crate
312312
/// (as opposed to just one item). `GlobalMetaData` components are only
313313
/// supposed to show up right below the crate root.
314-
GlobalMetaData(InternedString),
314+
GlobalMetaData(Symbol),
315315
}
316316

317317
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
@@ -545,7 +545,7 @@ impl Definitions {
545545
}
546546

547547
impl DefPathData {
548-
pub fn get_opt_name(&self) -> Option<InternedString> {
548+
pub fn get_opt_name(&self) -> Option<Symbol> {
549549
use self::DefPathData::*;
550550
match *self {
551551
TypeNs(name) |
@@ -564,15 +564,15 @@ impl DefPathData {
564564
}
565565
}
566566

567-
pub fn as_interned_str(&self) -> InternedString {
567+
pub fn as_symbol(&self) -> Symbol {
568568
use self::DefPathData::*;
569-
let s = match *self {
569+
match *self {
570570
TypeNs(name) |
571571
ValueNs(name) |
572572
MacroNs(name) |
573573
LifetimeNs(name) |
574574
GlobalMetaData(name) => {
575-
return name
575+
name
576576
}
577577
// Note that this does not show up in user print-outs.
578578
CrateRoot => sym::double_braced_crate,
@@ -582,13 +582,11 @@ impl DefPathData {
582582
Ctor => sym::double_braced_constructor,
583583
AnonConst => sym::double_braced_constant,
584584
ImplTrait => sym::double_braced_opaque,
585-
};
586-
587-
s.as_interned_str()
585+
}
588586
}
589587

590588
pub fn to_string(&self) -> String {
591-
self.as_interned_str().to_string()
589+
self.as_symbol().to_string()
592590
}
593591
}
594592

@@ -611,7 +609,7 @@ macro_rules! define_global_metadata_kind {
611609
definitions.create_def_with_parent(
612610
CRATE_DEF_INDEX,
613611
ast::DUMMY_NODE_ID,
614-
DefPathData::GlobalMetaData(instance.name().as_interned_str()),
612+
DefPathData::GlobalMetaData(instance.name()),
615613
ExpnId::root(),
616614
DUMMY_SP
617615
);
@@ -625,7 +623,7 @@ macro_rules! define_global_metadata_kind {
625623
let def_key = DefKey {
626624
parent: Some(CRATE_DEF_INDEX),
627625
disambiguated_data: DisambiguatedDefPathData {
628-
data: DefPathData::GlobalMetaData(self.name().as_interned_str()),
626+
data: DefPathData::GlobalMetaData(self.name()),
629627
disambiguator: 0,
630628
}
631629
};

src/librustc/hir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ 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, symbol::Symbol, 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};
2626
use syntax::attr::{InlineAttr, OptimizeAttr};
27-
use syntax::symbol::{Symbol, kw};
27+
use syntax::symbol::kw;
2828
use syntax::tokenstream::TokenStream;
2929
use syntax::util::parser::ExprPrecedence;
3030
use rustc_target::spec::abi::Abi;
@@ -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

+5-23
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::Symbol;
1313
use syntax::tokenstream;
1414
use syntax_pos::SourceFile;
1515

@@ -18,39 +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 {
22-
#[inline]
23-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
24-
self.with(|s| s.hash_stable(hcx, hasher))
25-
}
26-
}
27-
28-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for InternedString {
29-
type KeyType = InternedString;
30-
31-
#[inline]
32-
fn to_stable_hash_key(&self,
33-
_: &StableHashingContext<'a>)
34-
-> InternedString {
35-
self.clone()
36-
}
37-
}
38-
3921
impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
4022
#[inline]
4123
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
42-
self.as_str().hash_stable(hcx, hasher);
24+
self.with(|s| s.hash_stable(hcx, hasher))
4325
}
4426
}
4527

4628
impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::Name {
47-
type KeyType = InternedString;
29+
type KeyType = Symbol;
4830

4931
#[inline]
5032
fn to_stable_hash_key(&self,
5133
_: &StableHashingContext<'a>)
52-
-> InternedString {
53-
self.as_interned_str()
34+
-> Symbol {
35+
self.clone()
5436
}
5537
}
5638

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(

src/librustc/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::cell::{Cell, Ref, RefCell, RefMut};
3232
use std::collections::BTreeMap;
3333
use std::fmt;
3434
use syntax::ast;
35-
use syntax_pos::symbol::InternedString;
35+
use syntax_pos::symbol::Symbol;
3636
use syntax_pos::Span;
3737

3838
use self::combine::CombineFields;
@@ -392,7 +392,7 @@ pub enum RegionVariableOrigin {
392392
Coercion(Span),
393393

394394
/// Region variables created as the values for early-bound regions
395-
EarlyBoundRegion(Span, InternedString),
395+
EarlyBoundRegion(Span, Symbol),
396396

397397
/// Region variables created for bound regions
398398
/// in a function or method that is called

0 commit comments

Comments
 (0)