Skip to content

Commit 8fd7d49

Browse files
committed
Make HirMap thread-safe
1 parent dc0fb52 commit 8fd7d49

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/librustc/hir/map/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ use hir::svh::Svh;
3333
use util::nodemap::{DefIdMap, FxHashMap};
3434

3535
use arena::TypedArena;
36-
use std::cell::RefCell;
3736
use std::io;
3837
use ty::TyCtxt;
3938

39+
use rustc_data_structures::sync::Lock;
40+
4041
pub mod blocks;
4142
mod collector;
4243
mod def_collector;
@@ -264,7 +265,7 @@ pub struct Map<'hir> {
264265
definitions: &'hir Definitions,
265266

266267
/// Bodies inlined from other crates are cached here.
267-
inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
268+
inlined_bodies: Lock<DefIdMap<&'hir Body>>,
268269

269270
/// The reverse mapping of `node_to_hir_id`.
270271
hir_to_node_id: FxHashMap<HirId, NodeId>,
@@ -927,8 +928,13 @@ impl<'hir> Map<'hir> {
927928
}
928929

929930
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+
}
930936
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);
932938
body
933939
}
934940

@@ -1189,7 +1195,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
11891195
map,
11901196
hir_to_node_id,
11911197
definitions,
1192-
inlined_bodies: RefCell::new(DefIdMap()),
1198+
inlined_bodies: Lock::new(DefIdMap()),
11931199
};
11941200

11951201
hir_id_validator::check_crate(&map);

0 commit comments

Comments
 (0)