@@ -33,10 +33,11 @@ use hir::svh::Svh;
33
33
use util:: nodemap:: { DefIdMap , FxHashMap } ;
34
34
35
35
use arena:: TypedArena ;
36
- use std:: cell:: RefCell ;
37
36
use std:: io;
38
37
use ty:: TyCtxt ;
39
38
39
+ use rustc_data_structures:: sync:: Lock ;
40
+
40
41
pub mod blocks;
41
42
mod collector;
42
43
mod def_collector;
@@ -264,7 +265,7 @@ pub struct Map<'hir> {
264
265
definitions : & ' hir Definitions ,
265
266
266
267
/// Bodies inlined from other crates are cached here.
267
- inlined_bodies : RefCell < DefIdMap < & ' hir Body > > ,
268
+ inlined_bodies : Lock < DefIdMap < & ' hir Body > > ,
268
269
269
270
/// The reverse mapping of `node_to_hir_id`.
270
271
hir_to_node_id : FxHashMap < HirId , NodeId > ,
@@ -927,8 +928,13 @@ impl<'hir> Map<'hir> {
927
928
}
928
929
929
930
pub fn intern_inlined_body ( & self , def_id : DefId , body : Body ) -> & ' hir Body {
931
+ let mut inlined_bodies = self . inlined_bodies . borrow_mut ( ) ;
932
+ if let Some ( & b) = inlined_bodies. get ( & def_id) {
933
+ debug_assert_eq ! ( & body, b) ;
934
+ return b;
935
+ }
930
936
let body = self . forest . inlined_bodies . alloc ( body) ;
931
- self . inlined_bodies . borrow_mut ( ) . insert ( def_id, body) ;
937
+ inlined_bodies. insert ( def_id, body) ;
932
938
body
933
939
}
934
940
@@ -1189,7 +1195,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
1189
1195
map,
1190
1196
hir_to_node_id,
1191
1197
definitions,
1192
- inlined_bodies : RefCell :: new ( DefIdMap ( ) ) ,
1198
+ inlined_bodies : Lock :: new ( DefIdMap ( ) ) ,
1193
1199
} ;
1194
1200
1195
1201
hir_id_validator:: check_crate ( & map) ;
0 commit comments