Make HirMap thread-safe
This commit is contained in:
parent
dc0fb52fcc
commit
8fd7d49c95
1 changed files with 10 additions and 4 deletions
|
|
@ -33,10 +33,11 @@ use hir::svh::Svh;
|
|||
use util::nodemap::{DefIdMap, FxHashMap};
|
||||
|
||||
use arena::TypedArena;
|
||||
use std::cell::RefCell;
|
||||
use std::io;
|
||||
use ty::TyCtxt;
|
||||
|
||||
use rustc_data_structures::sync::Lock;
|
||||
|
||||
pub mod blocks;
|
||||
mod collector;
|
||||
mod def_collector;
|
||||
|
|
@ -264,7 +265,7 @@ pub struct Map<'hir> {
|
|||
definitions: &'hir Definitions,
|
||||
|
||||
/// Bodies inlined from other crates are cached here.
|
||||
inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
|
||||
inlined_bodies: Lock<DefIdMap<&'hir Body>>,
|
||||
|
||||
/// The reverse mapping of `node_to_hir_id`.
|
||||
hir_to_node_id: FxHashMap<HirId, NodeId>,
|
||||
|
|
@ -927,8 +928,13 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
|
||||
pub fn intern_inlined_body(&self, def_id: DefId, body: Body) -> &'hir Body {
|
||||
let mut inlined_bodies = self.inlined_bodies.borrow_mut();
|
||||
if let Some(&b) = inlined_bodies.get(&def_id) {
|
||||
debug_assert_eq!(&body, b);
|
||||
return b;
|
||||
}
|
||||
let body = self.forest.inlined_bodies.alloc(body);
|
||||
self.inlined_bodies.borrow_mut().insert(def_id, body);
|
||||
inlined_bodies.insert(def_id, body);
|
||||
body
|
||||
}
|
||||
|
||||
|
|
@ -1189,7 +1195,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
|
|||
map,
|
||||
hir_to_node_id,
|
||||
definitions,
|
||||
inlined_bodies: RefCell::new(DefIdMap()),
|
||||
inlined_bodies: Lock::new(DefIdMap()),
|
||||
};
|
||||
|
||||
hir_id_validator::check_crate(&map);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue