Skip to content

Commit 9425877

Browse files
committed
Changed &mut to RefCell
1 parent 95dd85a commit 9425877

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ macro_rules! return_if_metadata_created_in_meantime {
375375
}
376376

377377
fn check_type_name_cache(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, qualified: bool) -> String {
378-
let type_name_cache = &mut *debug_context(cx).type_name_cache.borrow_mut();
379-
compute_debuginfo_type_name(cx.tcx, ty, qualified, type_name_cache)
378+
compute_debuginfo_type_name(cx.tcx, ty, qualified, &debug_context(cx).type_name_cache)
380379
}
381380

382381
fn fixed_vec_metadata(

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
438438
substs: SubstsRef<'tcx>,
439439
name_to_append_suffix_to: &mut String,
440440
) -> &'ll DIArray {
441-
let type_name_cache = &mut *debug_context(cx).type_name_cache.borrow_mut();
442441
type_names::push_generic_params(
443442
cx.tcx,
444443
cx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substs),
445444
name_to_append_suffix_to,
446-
type_name_cache,
445+
&debug_context(cx).type_name_cache,
447446
);
448447

449448
if substs.types().next().is_none() {

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_target::abi::{Integer, TagEncoding, Variants};
2424
use smallvec::SmallVec;
2525

2626
use std::fmt::Write;
27+
use std::cell::RefCell;
2728

2829
// Compute the name of the type as it should be stored in debuginfo. Does not do
2930
// any caching, i.e., calling the function twice with the same type will also do
@@ -33,7 +34,7 @@ pub fn compute_debuginfo_type_name<'tcx>(
3334
tcx: TyCtxt<'tcx>,
3435
t: Ty<'tcx>,
3536
qualified: bool,
36-
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
37+
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
3738
) -> String {
3839
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
3940

@@ -51,10 +52,10 @@ fn push_debuginfo_type_name<'tcx>(
5152
qualified: bool,
5253
output: &mut String,
5354
visited: &mut FxHashSet<Ty<'tcx>>,
54-
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
55+
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
5556
) {
5657
// Check if we have seen this type and qualifier before.
57-
if let Some(type_name) = type_name_cache.get(&(&t, qualified)) {
58+
if let Some(type_name) = type_name_cache.borrow().get(&(&t, qualified)) {
5859
output.push_str(&type_name.clone());
5960
return;
6061
}
@@ -423,7 +424,7 @@ fn push_debuginfo_type_name<'tcx>(
423424
}
424425
}
425426

426-
if type_name_cache.insert((&t, qualified), output.clone()).is_some() {
427+
if type_name_cache.borrow_mut().insert((&t, qualified), output.clone()).is_some() {
427428
bug!("type name is already in the type name cache!");
428429
}
429430

@@ -438,7 +439,7 @@ fn push_debuginfo_type_name<'tcx>(
438439
substs: SubstsRef<'tcx>,
439440
output: &mut String,
440441
visited: &mut FxHashSet<Ty<'tcx>>,
441-
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
442+
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
442443
) {
443444
let layout = tcx.layout_of(tcx.param_env(def.did).and(ty)).expect("layout error");
444445

@@ -556,7 +557,7 @@ fn push_generic_params_internal<'tcx>(
556557
substs: SubstsRef<'tcx>,
557558
output: &mut String,
558559
visited: &mut FxHashSet<Ty<'tcx>>,
559-
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
560+
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
560561
) -> bool {
561562
if substs.non_erasable_generics().next().is_none() {
562563
return false;
@@ -643,7 +644,7 @@ pub fn push_generic_params<'tcx>(
643644
tcx: TyCtxt<'tcx>,
644645
substs: SubstsRef<'tcx>,
645646
output: &mut String,
646-
type_name_cache: &mut FxHashMap<(Ty<'tcx>, bool), String>,
647+
type_name_cache: &RefCell<FxHashMap<(Ty<'tcx>, bool), String>>,
647648
) {
648649
let _prof = tcx.prof.generic_activity("compute_debuginfo_type_name");
649650
let mut visited = FxHashSet::default();

0 commit comments

Comments
 (0)