Skip to content

Commit 03639a2

Browse files
committed
rustc(codegen): uncache def_symbol_name prefix from symbol_name.
1 parent 70a497a commit 03639a2

File tree

7 files changed

+19
-48
lines changed

7 files changed

+19
-48
lines changed

src/librustc/dep_graph/dep_node.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,7 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
500500
[] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
501501
[] ConstEvalRaw { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
502502
[] CheckMatch(DefId),
503-
[] SymbolName(DefId),
504-
[] InstanceSymbolName { instance: Instance<'tcx> },
503+
[] SymbolName { instance: Instance<'tcx> },
505504
[] SpecializationGraph(DefId),
506505
[] ObjectSafety(DefId),
507506
[] FulfillObligation { param_env: ParamEnv<'tcx>, trait_ref: PolyTraitRef<'tcx> },

src/librustc/ty/query/config.rs

-1
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,6 @@ impl_disk_cacheable_query!(mir_borrowck, |tcx, def_id| {
941941
impl_disk_cacheable_query!(unsafety_check_result, |_, def_id| def_id.is_local());
942942
impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local());
943943
impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local());
944-
impl_disk_cacheable_query!(def_symbol_name, |_, _| true);
945944
impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local());
946945
impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local());
947946
impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true);

src/librustc/ty/query/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ rustc_query_append! { [define_queries!][ <'tcx>
315315

316316
[] fn mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>,
317317

318-
[] fn def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
319318
[] fn symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
320319

321320
[] fn describe_def: DescribeDef(DefId) -> Option<Def>,
@@ -727,7 +726,7 @@ fn mir_shim_dep_node<'tcx>(instance_def: ty::InstanceDef<'tcx>) -> DepConstructo
727726
}
728727

729728
fn symbol_name_dep_node<'tcx>(instance: ty::Instance<'tcx>) -> DepConstructor<'tcx> {
730-
DepConstructor::InstanceSymbolName { instance }
729+
DepConstructor::SymbolName { instance }
731730
}
732731

733732
fn typeck_item_bodies_dep_node<'tcx>(_: CrateNum) -> DepConstructor<'tcx> {

src/librustc/ty/query/on_disk_cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ impl<'sess> OnDiskCache<'sess> {
218218
encode_query_results::<borrowck<'_>, _>(tcx, enc, qri)?;
219219
encode_query_results::<mir_borrowck<'_>, _>(tcx, enc, qri)?;
220220
encode_query_results::<mir_const_qualif<'_>, _>(tcx, enc, qri)?;
221-
encode_query_results::<def_symbol_name<'_>, _>(tcx, enc, qri)?;
222221
encode_query_results::<const_is_rvalue_promotable_to_static<'_>, _>(tcx, enc, qri)?;
223222
encode_query_results::<symbol_name<'_>, _>(tcx, enc, qri)?;
224223
encode_query_results::<check_match<'_>, _>(tcx, enc, qri)?;

src/librustc/ty/query/plumbing.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ pub fn force_from_dep_node<'tcx>(
12171217
DepKind::Layout |
12181218
DepKind::ConstEval |
12191219
DepKind::ConstEvalRaw |
1220-
DepKind::InstanceSymbolName |
1220+
DepKind::SymbolName |
12211221
DepKind::MirShim |
12221222
DepKind::BorrowCheckKrate |
12231223
DepKind::Specializes |
@@ -1304,7 +1304,6 @@ pub fn force_from_dep_node<'tcx>(
13041304
DepKind::TypeckTables => { force!(typeck_tables_of, def_id!()); }
13051305
DepKind::UsedTraitImports => { force!(used_trait_imports, def_id!()); }
13061306
DepKind::HasTypeckTables => { force!(has_typeck_tables, def_id!()); }
1307-
DepKind::SymbolName => { force!(def_symbol_name, def_id!()); }
13081307
DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); }
13091308
DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); }
13101309
DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); }
@@ -1486,7 +1485,6 @@ impl_load_from_cache!(
14861485
BorrowCheck => borrowck,
14871486
MirBorrowCheck => mir_borrowck,
14881487
mir_const_qualif => mir_const_qualif,
1489-
SymbolName => def_symbol_name,
14901488
ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static,
14911489
CheckMatch => check_match,
14921490
type_of => type_of,

src/librustc_codegen_utils/symbol_names.rs

+15-38
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101101
use rustc_mir::monomorphize::item::{InstantiationMode, MonoItem, MonoItemExt};
102102
use rustc_mir::monomorphize::Instance;
103103

104-
use syntax_pos::symbol::Symbol;
104+
use syntax_pos::symbol::{Symbol, InternedString};
105105

106106
use log::debug;
107107

@@ -110,7 +110,6 @@ use std::mem::{self, discriminant};
110110

111111
pub fn provide(providers: &mut Providers<'_>) {
112112
*providers = Providers {
113-
def_symbol_name,
114113
symbol_name,
115114

116115
..*providers
@@ -222,21 +221,13 @@ fn get_symbol_hash<'a, 'tcx>(
222221
hasher.finish()
223222
}
224223

225-
fn def_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::SymbolName {
226-
SymbolPrinter {
227-
tcx,
228-
path: SymbolPath::new(),
229-
keep_within_component: false,
230-
}.print_def_path(def_id, &[]).unwrap().path.into_interned()
231-
}
232-
233-
fn symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
224+
fn symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
234225
ty::SymbolName {
235-
name: Symbol::intern(&compute_symbol_name(tcx, instance)).as_interned_str(),
226+
name: compute_symbol_name(tcx, instance),
236227
}
237228
}
238229

239-
fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> String {
230+
fn compute_symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> InternedString {
240231
let def_id = instance.def_id();
241232
let substs = instance.substs;
242233

@@ -247,11 +238,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
247238
if def_id.is_local() {
248239
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
249240
let disambiguator = tcx.sess.local_crate_disambiguator();
250-
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
241+
return Symbol::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator))
242+
.as_interned_str();
251243
}
252244
if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
253245
let disambiguator = tcx.sess.local_crate_disambiguator();
254-
return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
246+
return Symbol::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator))
247+
.as_interned_str();
255248
}
256249
}
257250

@@ -268,20 +261,20 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
268261
let attrs = tcx.codegen_fn_attrs(def_id);
269262
if is_foreign {
270263
if let Some(name) = attrs.link_name {
271-
return name.to_string();
264+
return name.as_interned_str();
272265
}
273266
// Don't mangle foreign items.
274-
return tcx.item_name(def_id).to_string();
267+
return tcx.item_name(def_id);
275268
}
276269

277270
if let Some(name) = &attrs.export_name {
278271
// Use provided name
279-
return name.to_string();
272+
return name.as_interned_str();
280273
}
281274

282275
if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
283276
// Don't mangle
284-
return tcx.item_name(def_id).to_string();
277+
return tcx.item_name(def_id);
285278
}
286279

287280
// 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
321314

322315
let mut printer = SymbolPrinter {
323316
tcx,
324-
path: SymbolPath::from_interned(tcx.def_symbol_name(def_id)),
317+
path: SymbolPath::new(),
325318
keep_within_component: false,
326-
};
319+
}.print_def_path(def_id, &[]).unwrap();
327320

328321
if instance.is_vtable_shim() {
329322
let _ = printer.write_str("{{vtable-shim}}");
330323
}
331324

332-
printer.path.finish(hash)
325+
Symbol::intern(&printer.path.finish(hash)).as_interned_str()
333326
}
334327

335328
// Follow C++ namespace-mangling style, see
@@ -361,22 +354,6 @@ impl SymbolPath {
361354
result
362355
}
363356

364-
fn from_interned(symbol: ty::SymbolName) -> Self {
365-
let mut result = SymbolPath {
366-
result: String::with_capacity(64),
367-
temp_buf: String::with_capacity(16),
368-
};
369-
result.result.push_str(&symbol.as_str());
370-
result
371-
}
372-
373-
fn into_interned(mut self) -> ty::SymbolName {
374-
self.finalize_pending_component();
375-
ty::SymbolName {
376-
name: Symbol::intern(&self.result).as_interned_str(),
377-
}
378-
}
379-
380357
fn finalize_pending_component(&mut self) {
381358
if !self.temp_buf.is_empty() {
382359
let _ = write!(self.result, "{}{}", self.temp_buf.len(), self.temp_buf);

src/librustc_mir/transform/lower_128bit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn check_lang_item_type<'a, 'tcx, D>(
138138
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
139139
let expected = [lhs_ty, rhs_ty, place_ty];
140140
assert_eq!(sig.inputs_and_output[..], expected,
141-
"lang item {}", tcx.def_symbol_name(did));
141+
"lang item `{}`", tcx.def_path_str(did));
142142
did
143143
}
144144

0 commit comments

Comments
 (0)