Skip to content

Commit

Permalink
Auto merge of #49695 - michaelwoerister:unhygienic-ty-min, r=<try>
Browse files Browse the repository at this point in the history
Use InternedString instead of Symbol for type parameter types

Reduced alternative to #49266. Let's see if this causes a performance regression.
  • Loading branch information
bors committed Apr 5, 2018
2 parents 56714ac + d7357e2 commit c645af8
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/librustc/infer/type_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use syntax::ast;
use syntax::symbol::InternedString;
use syntax_pos::Span;
use ty::{self, Ty};

Expand Down Expand Up @@ -53,7 +53,7 @@ pub enum TypeVariableOrigin {
MiscVariable(Span),
NormalizeProjectionType(Span),
TypeInference(Span),
TypeParameterDefinition(Span, ast::Name),
TypeParameterDefinition(Span, InternedString),

/// one of the upvars or closure kind parameters in a `ClosureSubsts`
/// (before it has been determined)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

for param in generics.types.iter() {
let name = param.name.as_str().to_string();
let name = param.name.to_string();
let ty = trait_ref.substs.type_for_def(param);
let ty_str = ty.to_string();
flags.push((name.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/on_unimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
let trait_str = tcx.item_path_str(trait_ref.def_id);
let generics = tcx.generics_of(trait_ref.def_id);
let generic_map = generics.types.iter().map(|param| {
(param.name.as_str().to_string(),
(param.name.to_string(),
trait_ref.substs.type_for_def(param).to_string())
}).collect::<FxHashMap<String, String>>();

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ use std::iter;
use std::sync::mpsc;
use std::sync::Arc;
use syntax::abi;
use syntax::ast::{self, Name, NodeId};
use syntax::ast::{self, NodeId};
use syntax::attr;
use syntax::codemap::MultiSpan;
use syntax::feature_gate;
use syntax::symbol::{Symbol, keywords};
use syntax::symbol::{Symbol, keywords, InternedString};
use syntax_pos::Span;

use hir;
Expand Down Expand Up @@ -2263,12 +2263,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn mk_param(self,
index: u32,
name: Name) -> Ty<'tcx> {
name: InternedString) -> Ty<'tcx> {
self.mk_ty(TyParam(ParamTy { idx: index, name: name }))
}

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

pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {
Expand Down
11 changes: 10 additions & 1 deletion src/librustc/ty/maps/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,16 @@ macro_rules! define_maps {
span: Span,
dep_node: DepNode)
-> Result<($V, DepNodeIndex), CycleError<'a, $tcx>> {
debug_assert!(!tcx.dep_graph.dep_node_exists(&dep_node));
// If the following assertion triggers, it can have two reasons:
// 1. Something is wrong with DepNode creation, either here or
// in DepGraph::try_mark_green()
// 2. Two distinct query keys get mapped to the same DepNode
// (see for example #48923)
assert!(!tcx.dep_graph.dep_node_exists(&dep_node),
"Forcing query with already existing DepNode.\n\
- query-key: {:?}\n\
- dep-node: {:?}",
key, dep_node);

profq_msg!(tcx, ProfileQueriesMsg::ProviderBegin);
let res = tcx.cycle_check(span, Query::$name(key), || {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ pub struct FloatVarValue(pub ast::FloatTy);

#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
pub struct TypeParameterDef {
pub name: Name,
pub name: InternedString,
pub def_id: DefId,
pub index: u32,
pub has_default: bool,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::iter;
use std::cmp::Ordering;
use syntax::abi;
use syntax::ast::{self, Name};
use syntax::symbol::keywords;
use syntax::symbol::{keywords, InternedString};

use serialize;

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

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

pub fn for_self() -> ParamTy {
ParamTy::new(0, keywords::SelfType.name())
ParamTy::new(0, keywords::SelfType.name().as_str())
}

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

pub fn is_self(&self) -> bool {
if self.name == keywords::SelfType.name() {
if self.name == keywords::SelfType.name().as_str() {
assert_eq!(self.idx, 0);
true
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
}
TyParam(p) => {
self.hash(p.idx);
self.hash(p.name.as_str());
self.hash(p.name);
}
TyProjection(ref data) => {
self.def_id(data.item_def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {

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

pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use std::ptr;

use syntax_pos::{self, Span, Pos};
use syntax::ast;
use syntax::symbol::Symbol;
use syntax::symbol::{Symbol, InternedString};
use rustc::ty::layout::{self, LayoutOf};

pub mod gdb;
Expand Down Expand Up @@ -393,7 +393,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
substs.types().zip(names).map(|(ty, name)| {
let actual_type = cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
let name = CString::new(name.as_str().as_bytes()).unwrap();
let name = CString::new(name.as_bytes()).unwrap();
unsafe {
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
DIB(cx),
Expand All @@ -412,7 +412,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
return create_DIArray(DIB(cx), &template_params[..]);
}

fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<ast::Name> {
fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec<InternedString> {
let mut names = generics.parent.map_or(vec![], |def_id| {
get_type_parameter_names(cx, cx.tcx.generics_of(def_id))
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
let item_def_id = tcx.hir.local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
tcx.mk_param(index, tcx.hir.name(node_id))
tcx.mk_param(index, tcx.hir.name(node_id).as_str())
}
Def::SelfTy(_, Some(def_id)) => {
// Self in impl (we know the concrete type).
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn equate_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
/// and in libcore/intrinsics.rs
pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
it: &hir::ForeignItem) {
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)));
let param = |n| tcx.mk_param(n, Symbol::intern(&format!("P{}", n)).as_str());
let name = it.name.as_str();
let (n_tps, inputs, output) = if name.starts_with("atomic_") {
let split : Vec<&str> = name.split('_').collect();
Expand Down Expand Up @@ -341,7 +341,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
it: &hir::ForeignItem) {
let param = |n| {
let name = Symbol::intern(&format!("P{}", n));
let name = Symbol::intern(&format!("P{}", n)).as_str();
tcx.mk_param(n, name)
};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ fn reject_shadowing_type_parameters(tcx: TyCtxt, def_id: DefId) {
// local so it should be okay to just unwrap everything.
let trait_def_id = impl_params[&method_param.name];
let trait_decl_span = tcx.def_span(trait_def_id);
error_194(tcx, type_span, trait_decl_span, method_param.name);
error_194(tcx, type_span, trait_decl_span, &method_param.name[..]);
}
}
}
Expand Down Expand Up @@ -753,7 +753,7 @@ fn error_392<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, param_name: ast:
err
}

fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: &str) {
struct_span_err!(tcx.sess, span, E0194,
"type parameter `{}` shadows another type parameter of the same name",
name)
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
let generics = tcx.generics_of(param_owner_def_id);
let index = generics.type_param_to_index[&def_id];
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id).as_str());

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

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

ty::TypeParameterDef {
index: type_start + i as u32,
name: p.name,
name: p.name.as_str(),
def_id: tcx.hir.local_def_id(p.id),
has_default: p.default.is_some(),
object_lifetime_default:
Expand All @@ -934,7 +934,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// add a dummy parameter for the closure kind
types.push(ty::TypeParameterDef {
index: type_start,
name: Symbol::intern("<closure_kind>"),
name: Symbol::intern("<closure_kind>").as_str(),
def_id,
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand All @@ -945,7 +945,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// add a dummy parameter for the closure signature
types.push(ty::TypeParameterDef {
index: type_start + 1,
name: Symbol::intern("<closure_signature>"),
name: Symbol::intern("<closure_signature>").as_str(),
def_id,
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand All @@ -956,7 +956,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
tcx.with_freevars(node_id, |fv| {
types.extend(fv.iter().zip(2..).map(|(_, i)| ty::TypeParameterDef {
index: type_start + i,
name: Symbol::intern("<upvar>"),
name: Symbol::intern("<upvar>").as_str(),
def_id,
has_default: false,
object_lifetime_default: rl::Set1::Empty,
Expand Down Expand Up @@ -1436,7 +1436,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Collect the predicates that were written inline by the user on each
// type parameter (e.g., `<T:Foo>`).
for param in ast_generics.ty_params() {
let param_ty = ty::ParamTy::new(index, param.name).to_ty(tcx);
let param_ty = ty::ParamTy::new(index, param.name.as_str()).to_ty(tcx);
index += 1;

let bounds = compute_bounds(&icx,
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
P(hir::Path {
span: DUMMY_SP,
def: Def::TyParam(param.def_id),
segments: HirVec::from_vec(vec![hir::PathSegment::from_name(param.name)]),
segments: HirVec::from_vec(vec![
hir::PathSegment::from_name(Symbol::intern(&param.name))
]),
}),
)),
span: DUMMY_SP,
Expand Down
8 changes: 7 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use syntax::codemap::Spanned;
use syntax::feature_gate::UnstableFeatures;
use syntax::ptr::P;
use syntax::symbol::keywords;
use syntax::symbol::Symbol;
use syntax::symbol::{Symbol, InternedString};
use syntax_pos::{self, DUMMY_SP, Pos, FileName};

use rustc::middle::const_val::ConstVal;
Expand Down Expand Up @@ -3374,6 +3374,12 @@ impl Clean<String> for ast::Name {
}
}

impl Clean<String> for InternedString {
fn clean(&self, _: &DocContext) -> String {
self.to_string()
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Typedef {
pub type_: Type,
Expand Down

0 comments on commit c645af8

Please sign in to comment.