Skip to content

Commit c53c12c

Browse files
committed
Changed argument type; moved cache insertion.
1 parent 6412f3f commit c53c12c

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_middle::ty::{self, AdtDef, ExistentialProjection, Ty, TyCtxt};
2323
use rustc_target::abi::{Integer, TagEncoding, Variants};
2424
use smallvec::SmallVec;
2525

26-
use std::cell::RefCell;
2726
use std::fmt::Write;
2827

2928
// Compute the name of the type as it should be stored in debuginfo. Does not do
@@ -34,13 +33,16 @@ pub fn compute_debuginfo_type_name<'tcx>(
3433
tcx: TyCtxt<'tcx>,
3534
t: Ty<'tcx>,
3635
qualified: bool,
37-
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
36+
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
3837
) -> String {
3938
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
4039

4140
let mut result = String::with_capacity(64);
4241
let mut visited = FxHashSet::default();
4342
push_debuginfo_type_name(tcx, t, qualified, &mut result, &mut visited, type_name_cache);
43+
if type_name_cache.insert((t, qualified), result.clone()).is_some() {
44+
bug!("type name is already in the type name cache!");
45+
}
4446
result
4547
}
4648

@@ -52,11 +54,11 @@ fn push_debuginfo_type_name<'tcx>(
5254
qualified: bool,
5355
output: &mut String,
5456
visited: &mut FxHashSet<Ty<'tcx>>,
55-
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
57+
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
5658
) {
5759
// Check if we have seen this type and qualifier before.
58-
if let Some(type_name) = type_name_cache.borrow().get(&(&t, qualified)) {
59-
output.push_str(&type_name.clone());
60+
if let Some(type_name) = type_name_cache.get(&(t, qualified)) {
61+
output.push_str(&type_name[..]);
6062
return;
6163
}
6264

@@ -424,10 +426,6 @@ fn push_debuginfo_type_name<'tcx>(
424426
}
425427
}
426428

427-
if type_name_cache.borrow_mut().insert((&t, qualified), output.clone()).is_some() {
428-
bug!("type name is already in the type name cache!");
429-
}
430-
431429
/// MSVC names enums differently than other platforms so that the debugging visualization
432430
// format (natvis) is able to understand enums and render the active variant correctly in the
433431
// debugger. For more information, look in `src/etc/natvis/intrinsic.natvis` and
@@ -439,7 +437,7 @@ fn push_debuginfo_type_name<'tcx>(
439437
substs: SubstsRef<'tcx>,
440438
output: &mut String,
441439
visited: &mut FxHashSet<Ty<'tcx>>,
442-
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
440+
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
443441
) {
444442
let layout = tcx.layout_of(tcx.param_env(def.did).and(ty)).expect("layout error");
445443

@@ -557,7 +555,7 @@ fn push_generic_params_internal<'tcx>(
557555
substs: SubstsRef<'tcx>,
558556
output: &mut String,
559557
visited: &mut FxHashSet<Ty<'tcx>>,
560-
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
558+
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
561559
) -> bool {
562560
if substs.non_erasable_generics().next().is_none() {
563561
return false;
@@ -644,7 +642,7 @@ pub fn push_generic_params<'tcx>(
644642
tcx: TyCtxt<'tcx>,
645643
substs: SubstsRef<'tcx>,
646644
output: &mut String,
647-
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
645+
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
648646
) {
649647
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
650648
let mut visited = FxHashSet::default();

0 commit comments

Comments
 (0)