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

+2-2
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

+1-1
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

+1-1
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

+4-4
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

+10-1
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

+1-1
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

+5-5
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

+1-1
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

+1-1
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

+3-3
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
});

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
979979
let item_def_id = tcx.hir.local_def_id(item_id);
980980
let generics = tcx.generics_of(item_def_id);
981981
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
982-
tcx.mk_param(index, tcx.hir.name(node_id))
982+
tcx.mk_param(index, tcx.hir.name(node_id).as_str())
983983
}
984984
Def::SelfTy(_, Some(def_id)) => {
985985
// Self in impl (we know the concrete type).

src/librustc_typeck/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7676
/// and in libcore/intrinsics.rs
7777
pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7878
it: &hir::ForeignItem) {
79-
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)));
79+
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)).as_str());
8080
let name = it.name.as_str();
8181
let (n_tps, inputs, output) = if name.starts_with("atomic_") {
8282
let split : Vec<&str> = name.split('_').collect();
@@ -341,7 +341,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
341341
pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
342342
it: &hir::ForeignItem) {
343343
let param = |n| {
344-
let name = Symbol::intern(&format!("P{}", n));
344+
let name = Symbol::intern(&format!("P{}", n)).as_str();
345345
tcx.mk_param(n, name)
346346
};
347347

src/librustc_typeck/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) {
655655
// local so it should be okay to just unwrap everything.
656656
let trait_def_id = impl_params[&method_param.name];
657657
let trait_decl_span = tcx.def_span(trait_def_id);
658-
error_194(tcx, type_span, trait_decl_span, method_param.name);
658+
error_194(tcx, type_span, trait_decl_span, &method_param.name[..]);
659659
}
660660
}
661661
}
@@ -759,7 +759,7 @@ fn error_392<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, param_name: ast:
759759
err
760760
}
761761

762-
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
762+
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: &str) {
763763
struct_span_err!(tcx.sess, span, E0194,
764764
"type parameter `{}` shadows another type parameter of the same name",
765765
name)

src/librustc_typeck/collect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
241241
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
242242
let generics = tcx.generics_of(param_owner_def_id);
243243
let index = generics.type_param_to_index[&def_id];
244-
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
244+
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id).as_str());
245245

246246
// Don't look for bounds where the type parameter isn't in scope.
247247
let parent = if item_def_id == param_owner_def_id {
@@ -839,7 +839,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
839839

840840
opt_self = Some(ty::TypeParameterDef {
841841
index: 0,
842-
name: keywords::SelfType.name(),
842+
name: keywords::SelfType.name().as_str(),
843843
def_id: tcx.hir.local_def_id(param_id),
844844
has_default: false,
845845
object_lifetime_default: rl::Set1::Empty,
@@ -915,7 +915,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
915915

916916
ty::TypeParameterDef {
917917
index: type_start + i as u32,
918-
name: p.name,
918+
name: p.name.as_str(),
919919
def_id: tcx.hir.local_def_id(p.id),
920920
has_default: p.default.is_some(),
921921
object_lifetime_default:
@@ -934,7 +934,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
934934
// add a dummy parameter for the closure kind
935935
types.push(ty::TypeParameterDef {
936936
index: type_start,
937-
name: Symbol::intern("<closure_kind>"),
937+
name: Symbol::intern("<closure_kind>").as_str(),
938938
def_id,
939939
has_default: false,
940940
object_lifetime_default: rl::Set1::Empty,
@@ -945,7 +945,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
945945
// add a dummy parameter for the closure signature
946946
types.push(ty::TypeParameterDef {
947947
index: type_start + 1,
948-
name: Symbol::intern("<closure_signature>"),
948+
name: Symbol::intern("<closure_signature>").as_str(),
949949
def_id,
950950
has_default: false,
951951
object_lifetime_default: rl::Set1::Empty,
@@ -956,7 +956,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
956956
tcx.with_freevars(node_id, |fv| {
957957
types.extend(fv.iter().zip(2..).map(|(_, i)| ty::TypeParameterDef {
958958
index: type_start + i,
959-
name: Symbol::intern("<upvar>"),
959+
name: Symbol::intern("<upvar>").as_str(),
960960
def_id,
961961
has_default: false,
962962
object_lifetime_default: rl::Set1::Empty,
@@ -1436,7 +1436,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
14361436
// Collect the predicates that were written inline by the user on each
14371437
// type parameter (e.g., `<T:Foo>`).
14381438
for param in ast_generics.ty_params() {
1439-
let param_ty = ty::ParamTy::new(index, param.name).to_ty(tcx);
1439+
let param_ty = ty::ParamTy::new(index, param.name.as_str()).to_ty(tcx);
14401440
index += 1;
14411441

14421442
let bounds = compute_bounds(&icx,

src/librustdoc/clean/auto_trait.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
260260
P(hir::Path {
261261
span: DUMMY_SP,
262262
def: Def::TyParam(param.def_id),
263-
segments: HirVec::from_vec(vec![hir::PathSegment::from_name(param.name)]),
263+
segments: HirVec::from_vec(vec![
264+
hir::PathSegment::from_name(Symbol::intern(&param.name))
265+
]),
264266
}),
265267
)),
266268
span: DUMMY_SP,

src/librustdoc/clean/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax::codemap::{dummy_spanned, Spanned};
2727
use syntax::feature_gate::UnstableFeatures;
2828
use syntax::ptr::P;
2929
use syntax::symbol::keywords;
30-
use syntax::symbol::Symbol;
30+
use syntax::symbol::{Symbol, InternedString};
3131
use syntax_pos::{self, DUMMY_SP, Pos, FileName};
3232

3333
use rustc::middle::const_val::ConstVal;
@@ -1787,7 +1787,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
17871787
// predicates field (see rustc_typeck::collect::ty_generics), so remove
17881788
// them.
17891789
let stripped_typarams = gens.types.iter().filter_map(|tp| {
1790-
if tp.name == keywords::SelfType.name() {
1790+
if tp.name == keywords::SelfType.name().as_str() {
17911791
assert_eq!(tp.index, 0);
17921792
None
17931793
} else {
@@ -3367,6 +3367,12 @@ impl Clean<String> for ast::Name {
33673367
}
33683368
}
33693369

3370+
impl Clean<String> for InternedString {
3371+
fn clean(&self, _: &DocContext) -> String {
3372+
self.to_string()
3373+
}
3374+
}
3375+
33703376
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
33713377
pub struct Typedef {
33723378
pub type_: Type,

0 commit comments

Comments
 (0)