Skip to content

Commit b8214e9

Browse files
committed
Convert fields within DefPathData from InternedString to Symbol.
It's a full conversion, except in `DefKey::compute_stable_hash()` where a `Symbol` now is converted to an `InternedString` before being hashed. This was necessary to avoid test failures.
1 parent 78c3427 commit b8214e9

File tree

16 files changed

+59
-63
lines changed

16 files changed

+59
-63
lines changed

src/librustc/hir/lowering.rs

Lines changed: 4 additions & 4 deletions
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/def_collector.rs

Lines changed: 13 additions & 16 deletions
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

Lines changed: 22 additions & 22 deletions
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

@@ -611,7 +611,7 @@ macro_rules! define_global_metadata_kind {
611611
definitions.create_def_with_parent(
612612
CRATE_DEF_INDEX,
613613
ast::DUMMY_NODE_ID,
614-
DefPathData::GlobalMetaData(instance.name().as_interned_str()),
614+
DefPathData::GlobalMetaData(instance.name()),
615615
ExpnId::root(),
616616
DUMMY_SP
617617
);
@@ -625,7 +625,7 @@ macro_rules! define_global_metadata_kind {
625625
let def_key = DefKey {
626626
parent: Some(CRATE_DEF_INDEX),
627627
disambiguated_data: DisambiguatedDefPathData {
628-
data: DefPathData::GlobalMetaData(self.name().as_interned_str()),
628+
data: DefPathData::GlobalMetaData(self.name()),
629629
disambiguator: 0,
630630
}
631631
};

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
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/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
875875
_ => {}
876876
}
877877

878-
path.push(disambiguated_data.data.as_interned_str().as_symbol());
878+
path.push(disambiguated_data.data.as_symbol());
879879
Ok(path)
880880
}
881881

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3019,7 +3019,7 @@ impl<'tcx> TyCtxt<'tcx> {
30193019
}),
30203020
_ => def_key.disambiguated_data.data.get_opt_name().unwrap_or_else(|| {
30213021
bug!("item_name: no name for {:?}", self.def_path(id));
3022-
}).as_symbol(),
3022+
}),
30233023
}
30243024
}
30253025
}

src/librustc/ty/print/obsolete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ impl DefPathBasedNames<'tcx> {
218218
// foo::bar::ItemName::
219219
for part in self.tcx.def_path(def_id).data {
220220
if self.omit_disambiguators {
221-
write!(output, "{}::", part.data.as_interned_str()).unwrap();
221+
write!(output, "{}::", part.data.as_symbol()).unwrap();
222222
} else {
223-
write!(output, "{}[{}]::", part.data.as_interned_str(), part.disambiguator)
223+
write!(output, "{}[{}]::", part.data.as_symbol(), part.disambiguator)
224224
.unwrap();
225225
}
226226
}

src/librustc/ty/print/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ pub trait PrettyPrinter<'tcx>:
384384
let reexport = self.tcx().item_children(visible_parent)
385385
.iter()
386386
.find(|child| child.res.def_id() == def_id)
387-
.map(|child| child.ident.as_interned_str());
387+
.map(|child| child.ident.name);
388388
if let Some(reexport) = reexport {
389389
*name = reexport;
390390
}
391391
}
392392
// Re-exported `extern crate` (#43189).
393393
DefPathData::CrateRoot => {
394394
data = DefPathData::TypeNs(
395-
self.tcx().original_crate_name(def_id.krate).as_interned_str(),
395+
self.tcx().original_crate_name(def_id.krate),
396396
);
397397
}
398398
_ => {}
@@ -1222,7 +1222,7 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
12221222

12231223
// FIXME(eddyb) `name` should never be empty, but it
12241224
// currently is for `extern { ... }` "foreign modules".
1225-
let name = disambiguated_data.data.as_interned_str().as_str();
1225+
let name = disambiguated_data.data.as_symbol().as_str();
12261226
if !name.is_empty() {
12271227
if !self.empty_path {
12281228
write!(self, "::")?;

src/librustc_codegen_llvm/debuginfo/namespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
3535

3636
let namespace_name = match def_key.disambiguated_data.data {
3737
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate).as_str(),
38-
data => data.as_interned_str().as_str()
38+
data => data.as_symbol().as_str()
3939
};
4040

4141
let namespace_name = SmallCStr::new(&namespace_name);

src/librustc_codegen_ssa/debuginfo/type_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ pub fn push_debuginfo_type_name<'tcx>(
221221
output.push_str(&tcx.crate_name(def_id.krate).as_str());
222222
for path_element in tcx.def_path(def_id).data {
223223
output.push_str("::");
224-
output.push_str(&path_element.data.as_interned_str().as_str());
224+
output.push_str(&path_element.data.as_symbol().as_str());
225225
}
226226
} else {
227227
output.push_str(&tcx.item_name(def_id).as_str());

src/librustc_codegen_utils/symbol_names/legacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
335335
self.path.finalize_pending_component();
336336
}
337337

338-
self.write_str(&disambiguated_data.data.as_interned_str().as_str())?;
338+
self.write_str(&disambiguated_data.data.as_symbol().as_str())?;
339339
Ok(self)
340340
}
341341
fn path_generic_args(

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl cstore::CStore {
460460

461461
LoadedMacro::MacroDef(ast::Item {
462462
// FIXME: cross-crate hygiene
463-
ident: ast::Ident::with_dummy_span(name.as_symbol()),
463+
ident: ast::Ident::with_dummy_span(name),
464464
id: ast::DUMMY_NODE_ID,
465465
span: local_span,
466466
attrs: attrs.iter().cloned().collect(),

0 commit comments

Comments
 (0)