From bf68c81fe8704f3317243fce6159e9a0e02da978 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 21 Mar 2018 14:46:05 +0100 Subject: [PATCH 1/4] Use InternedString instead of Symbol for type parameters. --- src/librustc/infer/type_variable.rs | 4 ++-- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/on_unimplemented.rs | 2 +- src/librustc/ty/context.rs | 8 ++++---- src/librustc/ty/mod.rs | 2 +- src/librustc/ty/sty.rs | 10 +++++----- src/librustc/ty/util.rs | 2 +- src/librustc_trans/debuginfo/mod.rs | 6 +++--- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/intrinsic.rs | 4 ++-- src/librustc_typeck/check/wfcheck.rs | 4 ++-- src/librustc_typeck/collect.rs | 14 +++++++------- 12 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 91df6cabf3a8b..5e96f4eb576f5 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -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}; @@ -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) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index d2bde14732bbc..2af4c3f9fd463 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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(), diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 8c2c1cfa45472..f7ce55c2e1df2 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -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::>(); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index fdda2286da03b..6e524570d8c87 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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; @@ -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> { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 72ba199eb2412..43c5ba46b44c9 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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, diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index ed04d41ba1457..7a9174cbfaf73 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -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; @@ -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 { @@ -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 { diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 22f851a908b25..c170c2a63e829 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -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); diff --git a/src/librustc_trans/debuginfo/mod.rs b/src/librustc_trans/debuginfo/mod.rs index 7664c88679e0e..87d9623e40038 100644 --- a/src/librustc_trans/debuginfo/mod.rs +++ b/src/librustc_trans/debuginfo/mod.rs @@ -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; @@ -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), @@ -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 { + fn get_type_parameter_names(cx: &CodegenCx, generics: &ty::Generics) -> Vec { let mut names = generics.parent.map_or(vec![], |def_id| { get_type_parameter_names(cx, cx.tcx.generics_of(def_id)) }); diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 0e93277983f8d..c4ea543ab36b6 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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). diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 377e3a891840f..da0d4509353b5 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -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(); @@ -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) }; diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 406ff9463a03c..c67327232ea3f 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -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[..]); } } } @@ -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) diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 59156bf0dfeaa..a4f820d1fdcf9 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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 { @@ -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, @@ -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: @@ -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(""), + name: Symbol::intern("").as_str(), def_id, has_default: false, object_lifetime_default: rl::Set1::Empty, @@ -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(""), + name: Symbol::intern("").as_str(), def_id, has_default: false, object_lifetime_default: rl::Set1::Empty, @@ -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(""), + name: Symbol::intern("").as_str(), def_id, has_default: false, object_lifetime_default: rl::Set1::Empty, @@ -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., ``). 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, From 45b537d5b2b4c3b757e1eac8f158b8207cd25399 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 22 Mar 2018 11:47:59 +0100 Subject: [PATCH 2/4] Improve assertion in Query::force(). --- src/librustc/ty/maps/plumbing.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index fa69eb8e5bc66..e3f74a7a45ae4 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -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), || { From 1715cf17347d58266ede2dd2fe267402bcc6b95e Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 3 Apr 2018 16:18:13 +0200 Subject: [PATCH 3/4] Fix rustdoc after changing type param representation. --- src/librustdoc/clean/auto_trait.rs | 4 +++- src/librustdoc/clean/mod.rs | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index fe4f785aa915e..89fbe1b72ea11 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -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(¶m.name)) + ]), }), )), span: DUMMY_SP, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6ada4ccfbddc2..2b6601301e148 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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; @@ -3374,6 +3374,12 @@ impl Clean for ast::Name { } } +impl Clean for InternedString { + fn clean(&self, _: &DocContext) -> String { + self.to_string() + } +} + #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Typedef { pub type_: Type, From d7357e26cc60a9217fe7a5611b0f06ee15a1d6a3 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 4 Apr 2018 17:53:16 +0200 Subject: [PATCH 4/4] Fix error in rustc_driver::test. --- src/librustc_driver/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 9efd8844977f9..971855ee2d007 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -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> {