Skip to content

Commit 88ebd97

Browse files
committed
Auto merge of #49695 - michaelwoerister:unhygienic-ty-min, r=nikomatsakis
Use InternedString instead of Symbol for type parameter types (2) Reduced alternative to #49266. Let's see if this causes a performance regression.
2 parents 0b72d48 + 4c4f9b9 commit 88ebd97

File tree

16 files changed

+52
-35
lines changed

16 files changed

+52
-35
lines changed

src/librustc/infer/type_variable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use syntax::ast;
11+
use syntax::symbol::InternedString;
1212
use syntax_pos::Span;
1313
use ty::{self, Ty};
1414

@@ -53,7 +53,7 @@ pub enum TypeVariableOrigin {
5353
MiscVariable(Span),
5454
NormalizeProjectionType(Span),
5555
TypeInference(Span),
56-
TypeParameterDefinition(Span, ast::Name),
56+
TypeParameterDefinition(Span, InternedString),
5757

5858
/// one of the upvars or closure kind parameters in a `ClosureSubsts`
5959
/// (before it has been determined)

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
378378
}
379379

380380
for param in generics.types.iter() {
381-
let name = param.name.as_str().to_string();
381+
let name = param.name.to_string();
382382
let ty = trait_ref.substs.type_for_def(param);
383383
let ty_str = ty.to_string();
384384
flags.push((name.clone(),

src/librustc/traits/on_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
289289
let trait_str = tcx.item_path_str(trait_ref.def_id);
290290
let generics = tcx.generics_of(trait_ref.def_id);
291291
let generic_map = generics.types.iter().map(|param| {
292-
(param.name.as_str().to_string(),
292+
(param.name.to_string(),
293293
trait_ref.substs.type_for_def(param).to_string())
294294
}).collect::<FxHashMap<String, String>>();
295295

src/librustc/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ use std::iter;
7171
use std::sync::mpsc;
7272
use std::sync::Arc;
7373
use syntax::abi;
74-
use syntax::ast::{self, Name, NodeId};
74+
use syntax::ast::{self, NodeId};
7575
use syntax::attr;
7676
use syntax::codemap::MultiSpan;
7777
use syntax::feature_gate;
78-
use syntax::symbol::{Symbol, keywords};
78+
use syntax::symbol::{Symbol, keywords, InternedString};
7979
use syntax_pos::Span;
8080

8181
use hir;
@@ -2430,12 +2430,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24302430

24312431
pub fn mk_param(self,
24322432
index: u32,
2433-
name: Name) -> Ty<'tcx> {
2433+
name: InternedString) -> Ty<'tcx> {
24342434
self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
24352435
}
24362436

24372437
pub fn mk_self_type(self) -> Ty<'tcx> {
2438-
self.mk_param(0, keywords::SelfType.name())
2438+
self.mk_param(0, keywords::SelfType.name().as_str())
24392439
}
24402440

24412441
pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {

src/librustc/ty/maps/plumbing.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,16 @@ macro_rules! define_maps {
671671
map: LockGuard<'_, QueryMap<$tcx, Self>>,
672672
dep_node: DepNode)
673673
-> Result<($V, DepNodeIndex), CycleError<$tcx>> {
674-
debug_assert!(!tcx.dep_graph.dep_node_exists(&dep_node));
674+
// If the following assertion triggers, it can have two reasons:
675+
// 1. Something is wrong with DepNode creation, either here or
676+
// in DepGraph::try_mark_green()
677+
// 2. Two distinct query keys get mapped to the same DepNode
678+
// (see for example #48923)
679+
assert!(!tcx.dep_graph.dep_node_exists(&dep_node),
680+
"Forcing query with already existing DepNode.\n\
681+
- query-key: {:?}\n\
682+
- dep-node: {:?}",
683+
key, dep_node);
675684

676685
profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
677686
let res = Self::start_job(tcx,

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ pub struct FloatVarValue(pub ast::FloatTy);
712712

713713
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
714714
pub struct TypeParameterDef {
715-
pub name: Name,
715+
pub name: InternedString,
716716
pub def_id: DefId,
717717
pub index: u32,
718718
pub has_default: bool,

src/librustc/ty/sty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::iter;
2424
use std::cmp::Ordering;
2525
use syntax::abi;
2626
use syntax::ast::{self, Name};
27-
use syntax::symbol::keywords;
27+
use syntax::symbol::{keywords, InternedString};
2828

2929
use serialize;
3030

@@ -864,16 +864,16 @@ impl<'tcx> PolyFnSig<'tcx> {
864864
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
865865
pub struct ParamTy {
866866
pub idx: u32,
867-
pub name: Name,
867+
pub name: InternedString,
868868
}
869869

870870
impl<'a, 'gcx, 'tcx> ParamTy {
871-
pub fn new(index: u32, name: Name) -> ParamTy {
871+
pub fn new(index: u32, name: InternedString) -> ParamTy {
872872
ParamTy { idx: index, name: name }
873873
}
874874

875875
pub fn for_self() -> ParamTy {
876-
ParamTy::new(0, keywords::SelfType.name())
876+
ParamTy::new(0, keywords::SelfType.name().as_str())
877877
}
878878

879879
pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {
@@ -885,7 +885,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
885885
}
886886

887887
pub fn is_self(&self) -> bool {
888-
if self.name == keywords::SelfType.name() {
888+
if self.name == keywords::SelfType.name().as_str() {
889889
assert_eq!(self.idx, 0);
890890
true
891891
} else {

src/librustc/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
729729
}
730730
TyParam(p) => {
731731
self.hash(p.idx);
732-
self.hash(p.name.as_str());
732+
self.hash(p.name);
733733
}
734734
TyProjection(ref data) => {
735735
self.def_id(data.item_def_id);

src/librustc_driver/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
303303

304304
pub fn t_param(&self, index: u32) -> Ty<'tcx> {
305305
let name = format!("T{}", index);
306-
self.infcx.tcx.mk_param(index, Symbol::intern(&name))
306+
self.infcx.tcx.mk_param(index, Symbol::intern(&name).as_str())
307307
}
308308

309309
pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> {

src/librustc_trans/debuginfo/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::ptr;
4242

4343
use syntax_pos::{self, Span, Pos};
4444
use syntax::ast;
45-
use syntax::symbol::Symbol;
45+
use syntax::symbol::{Symbol, InternedString};
4646
use rustc::ty::layout::{self, LayoutOf};
4747

4848
pub mod gdb;
@@ -393,7 +393,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
393393
substs.types().zip(names).map(|(ty, name)| {
394394
let actual_type = cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
395395
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
396-
let name = CString::new(name.as_str().as_bytes()).unwrap();
396+
let name = CString::new(name.as_bytes()).unwrap();
397397
unsafe {
398398
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
399399
DIB(cx),
@@ -412,7 +412,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
412412
return create_DIArray(DIB(cx), &template_params[..]);
413413
}
414414

415-
fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<ast::Name> {
415+
fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<InternedString> {
416416
let mut names = generics.parent.map_or(vec![], |def_id| {
417417
get_type_parameter_names(cx, cx.tcx.generics_of(def_id))
418418
});

0 commit comments

Comments
 (0)