From 03639a2bff351315ca59fc080b10de1df60bf910 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 21 Mar 2019 18:06:04 +0200 Subject: [PATCH] rustc(codegen): uncache `def_symbol_name` prefix from `symbol_name`. --- src/librustc/dep_graph/dep_node.rs | 3 +- src/librustc/ty/query/config.rs | 1 - src/librustc/ty/query/mod.rs | 3 +- src/librustc/ty/query/on_disk_cache.rs | 1 - src/librustc/ty/query/plumbing.rs | 4 +- src/librustc_codegen_utils/symbol_names.rs | 53 ++++++---------------- src/librustc_mir/transform/lower_128bit.rs | 2 +- 7 files changed, 19 insertions(+), 48 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 1f4f7d34424..03fa5c04ec7 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -500,8 +500,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx> [] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> }, [] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> }, [] CheckMatch(DefId), - [] SymbolName(DefId), - [] InstanceSymbolName { instance: Instance<'tcx> }, + [] SymbolName { instance: Instance<'tcx> }, [] SpecializationGraph(DefId), [] ObjectSafety(DefId), [] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> }, diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 5cb5a0030f4..bc5caffb934 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -941,7 +941,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| { impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local()); -impl_disk_cacheable_query!(def_symbol_name, |_, _| true); impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true); diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 9c705104d18..f64156beeaa 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -315,7 +315,6 @@ rustc_query_append! { [define_queries!][ <'tcx> [] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>, - [] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName, [] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName, [] fn describe_def: DescribeDef(DefId) -> Option, @@ -727,7 +726,7 @@ fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructo } fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> { - DepConstructor::InstanceSymbolName { instance } + DepConstructor::SymbolName { instance } } fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> { diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index c16f861dedb..1b4c36b8b06 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -218,7 +218,6 @@ impl<'sess> OnDiskCache<'sess> { encode_query_results::, _>(tcx, enc, qri)?; encode_query_results::, _>(tcx, enc, qri)?; encode_query_results::, _>(tcx, enc, qri)?; - encode_query_results::, _>(tcx, enc, qri)?; encode_query_results::, _>(tcx, enc, qri)?; encode_query_results::, _>(tcx, enc, qri)?; encode_query_results::, _>(tcx, enc, qri)?; diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index c35cea7883f..973291d94ac 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -1217,7 +1217,7 @@ pub fn force_from_dep_node<'tcx>( DepKind::Layout | DepKind::ConstEval | DepKind::ConstEvalRaw | - DepKind::InstanceSymbolName | + DepKind::SymbolName | DepKind::MirShim | DepKind::BorrowCheckKrate | DepKind::Specializes | @@ -1304,7 +1304,6 @@ pub fn force_from_dep_node<'tcx>( DepKind::TypeckTables => { force!(typeck_tables_of, def_id!()); } DepKind::UsedTraitImports => { force!(used_trait_imports, def_id!()); } DepKind::HasTypeckTables => { force!(has_typeck_tables, def_id!()); } - DepKind::SymbolName => { force!(def_symbol_name, def_id!()); } DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); } DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); } DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); } @@ -1486,7 +1485,6 @@ impl_load_from_cache!( BorrowCheck => borrowck, MirBorrowCheck => mir_borrowck, mir_const_qualif => mir_const_qualif, - SymbolName => def_symbol_name, ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static, CheckMatch => check_match, type_of => type_of, diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index ebd48f0ae1e..d50a9a1607b 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -101,7 +101,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_mir::monomorphize::item::{InstantiationMode, MonoItem, MonoItemExt}; use rustc_mir::monomorphize::Instance; -use syntax_pos::symbol::Symbol; +use syntax_pos::symbol::{Symbol, InternedString}; use log::debug; @@ -110,7 +110,6 @@ use std::mem::{self, discriminant}; pub fn provide(providers: &mut Providers<'_>) { *providers = Providers { - def_symbol_name, symbol_name, ..*providers @@ -222,21 +221,13 @@ fn get_symbol_hash<'a, 'tcx>( hasher.finish() } -fn def_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::SymbolName { - SymbolPrinter { - tcx, - path: SymbolPath::new(), - keep_within_component: false, - }.print_def_path(def_id, &[]).unwrap().path.into_interned() -} - -fn symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName { +fn symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName { ty::SymbolName { - name: Symbol::intern(&compute_symbol_name(tcx, instance)).as_interned_str(), + name: compute_symbol_name(tcx, instance), } } -fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> String { +fn compute_symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> InternedString { let def_id = instance.def_id(); let substs = instance.substs; @@ -247,11 +238,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance if def_id.is_local() { if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) { let disambiguator = tcx.sess.local_crate_disambiguator(); - return tcx.sess.generate_plugin_registrar_symbol(disambiguator); + return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator)) + .as_interned_str(); } if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) { let disambiguator = tcx.sess.local_crate_disambiguator(); - return tcx.sess.generate_proc_macro_decls_symbol(disambiguator); + return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator)) + .as_interned_str(); } } @@ -268,20 +261,20 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance let attrs = tcx.codegen_fn_attrs(def_id); if is_foreign { if let Some(name) = attrs.link_name { - return name.to_string(); + return name.as_interned_str(); } // Don't mangle foreign items. - return tcx.item_name(def_id).to_string(); + return tcx.item_name(def_id); } if let Some(name) = &attrs.export_name { // Use provided name - return name.to_string(); + return name.as_interned_str(); } if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) { // Don't mangle - return tcx.item_name(def_id).to_string(); + return tcx.item_name(def_id); } // We want to compute the "type" of this item. Unfortunately, some @@ -321,15 +314,15 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance let mut printer = SymbolPrinter { tcx, - path: SymbolPath::from_interned(tcx.def_symbol_name(def_id)), + path: SymbolPath::new(), keep_within_component: false, - }; + }.print_def_path(def_id, &[]).unwrap(); if instance.is_vtable_shim() { let _ = printer.write_str("{{vtable-shim}}"); } - printer.path.finish(hash) + Symbol::intern(&printer.path.finish(hash)).as_interned_str() } // Follow C++ namespace-mangling style, see @@ -361,22 +354,6 @@ impl SymbolPath { result } - fn from_interned(symbol: ty::SymbolName) -> Self { - let mut result = SymbolPath { - result: String::with_capacity(64), - temp_buf: String::with_capacity(16), - }; - result.result.push_str(&symbol.as_str()); - result - } - - fn into_interned(mut self) -> ty::SymbolName { - self.finalize_pending_component(); - ty::SymbolName { - name: Symbol::intern(&self.result).as_interned_str(), - } - } - fn finalize_pending_component(&mut self) { if !self.temp_buf.is_empty() { let _ = write!(self.result, "{}{}", self.temp_buf.len(), self.temp_buf); diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index ad108587247..54fc63f3057 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -138,7 +138,7 @@ fn check_lang_item_type<'a, 'tcx, D>( let place_ty = place.ty(local_decls, tcx).to_ty(tcx); let expected = [lhs_ty, rhs_ty, place_ty]; assert_eq!(sig.inputs_and_output[..], expected, - "lang item {}", tcx.def_symbol_name(did)); + "lang item `{}`", tcx.def_path_str(did)); did }