Skip to content

Commit c645af8

Browse files
committed
Auto merge of #49695 - michaelwoerister:unhygienic-ty-min, r=<try>
Use InternedString instead of Symbol for type parameter types Reduced alternative to #49266. Let's see if this causes a performance regression.
2 parents 56714ac + d7357e2 commit c645af8

File tree

16 files changed

+51
-34
lines changed

16 files changed

+51
-34
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
@@ -70,11 +70,11 @@ use std::iter;
7070
use std::sync::mpsc;
7171
use std::sync::Arc;
7272
use syntax::abi;
73-
use syntax::ast::{self, Name, NodeId};
73+
use syntax::ast::{self, NodeId};
7474
use syntax::attr;
7575
use syntax::codemap::MultiSpan;
7676
use syntax::feature_gate;
77-
use syntax::symbol::{Symbol, keywords};
77+
use syntax::symbol::{Symbol, keywords, InternedString};
7878
use syntax_pos::Span;
7979

8080
use hir;
@@ -2263,12 +2263,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22632263

22642264
pub fn mk_param(self,
22652265
index: u32,
2266-
name: Name) -> Ty<'tcx> {
2266+
name: InternedString) -> Ty<'tcx> {
22672267
self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
22682268
}
22692269

22702270
pub fn mk_self_type(self) -> Ty<'tcx> {
2271-
self.mk_param(0, keywords::SelfType.name())
2271+
self.mk_param(0, keywords::SelfType.name().as_str())
22722272
}
22732273

22742274
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
@@ -491,7 +491,16 @@ macro_rules! define_maps {
491491
span: Span,
492492
dep_node: DepNode)
493493
-> Result<($V, DepNodeIndex), CycleError<'a, $tcx>> {
494-
debug_assert!(!tcx.dep_graph.dep_node_exists(&dep_node));
494+
// If the following assertion triggers, it can have two reasons:
495+
// 1. Something is wrong with DepNode creation, either here or
496+
// in DepGraph::try_mark_green()
497+
// 2. Two distinct query keys get mapped to the same DepNode
498+
// (see for example #48923)
499+
assert!(!tcx.dep_graph.dep_node_exists(&dep_node),
500+
"Forcing query with already existing DepNode.\n\
501+
- query-key: {:?}\n\
502+
- dep-node: {:?}",
503+
key, dep_node);
495504

496505
profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
497506
let res = tcx.cycle_check(span, Query::$name(key), || {

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
@@ -649,7 +649,7 @@ fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) {
649649
// local so it should be okay to just unwrap everything.
650650
let trait_def_id = impl_params[&method_param.name];
651651
let trait_decl_span = tcx.def_span(trait_def_id);
652-
error_194(tcx, type_span, trait_decl_span, method_param.name);
652+
error_194(tcx, type_span, trait_decl_span, &method_param.name[..]);
653653
}
654654
}
655655
}
@@ -753,7 +753,7 @@ fn error_392<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, param_name: ast:
753753
err
754754
}
755755

756-
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
756+
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: &str) {
757757
struct_span_err!(tcx.sess, span, E0194,
758758
"type parameter `{}` shadows another type parameter of the same name",
759759
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

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use syntax::codemap::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;
@@ -3374,6 +3374,12 @@ impl Clean<String> for ast::Name {
33743374
}
33753375
}
33763376

3377+
impl Clean<String> for InternedString {
3378+
fn clean(&self, _: &DocContext) -> String {
3379+
self.to_string()
3380+
}
3381+
}
3382+
33773383
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
33783384
pub struct Typedef {
33793385
pub type_: Type,

0 commit comments

Comments
 (0)