@@ -24,6 +24,7 @@ use rustc_target::abi::{Integer, TagEncoding, Variants};
24
24
use smallvec:: SmallVec ;
25
25
26
26
use std:: fmt:: Write ;
27
+ use std:: cell:: RefCell ;
27
28
28
29
// Compute the name of the type as it should be stored in debuginfo. Does not do
29
30
// 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>(
33
34
tcx : TyCtxt < ' tcx > ,
34
35
t : Ty < ' tcx > ,
35
36
qualified : bool ,
36
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
37
+ type_name_cache : & RefCell < FxHashMap < ( Ty < ' tcx > , bool ) , String > > ,
37
38
) -> String {
38
39
let _prof = tcx. prof . generic_activity ( "compute_debuginfo_type_name" ) ;
39
40
@@ -51,10 +52,10 @@ fn push_debuginfo_type_name<'tcx>(
51
52
qualified : bool ,
52
53
output : & mut String ,
53
54
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 > > ,
55
56
) {
56
57
// 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) ) {
58
59
output. push_str ( & type_name. clone ( ) ) ;
59
60
return ;
60
61
}
@@ -423,7 +424,7 @@ fn push_debuginfo_type_name<'tcx>(
423
424
}
424
425
}
425
426
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 ( ) {
427
428
bug ! ( "type name is already in the type name cache!" ) ;
428
429
}
429
430
@@ -438,7 +439,7 @@ fn push_debuginfo_type_name<'tcx>(
438
439
substs : SubstsRef < ' tcx > ,
439
440
output : & mut String ,
440
441
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 > > ,
442
443
) {
443
444
let layout = tcx. layout_of ( tcx. param_env ( def. did ) . and ( ty) ) . expect ( "layout error" ) ;
444
445
@@ -556,7 +557,7 @@ fn push_generic_params_internal<'tcx>(
556
557
substs : SubstsRef < ' tcx > ,
557
558
output : & mut String ,
558
559
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 > > ,
560
561
) -> bool {
561
562
if substs. non_erasable_generics ( ) . next ( ) . is_none ( ) {
562
563
return false ;
@@ -643,7 +644,7 @@ pub fn push_generic_params<'tcx>(
643
644
tcx : TyCtxt < ' tcx > ,
644
645
substs : SubstsRef < ' tcx > ,
645
646
output : & mut String ,
646
- type_name_cache : & mut FxHashMap < ( Ty < ' tcx > , bool ) , String > ,
647
+ type_name_cache : & RefCell < FxHashMap < ( Ty < ' tcx > , bool ) , String > > ,
647
648
) {
648
649
let _prof = tcx. prof . generic_activity ( "compute_debuginfo_type_name" ) ;
649
650
let mut visited = FxHashSet :: default ( ) ;
0 commit comments