From 8fd7d49c9552108025e6d79cefd3c27c3d5d6f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Thu, 15 Feb 2018 10:52:26 +0100 Subject: [PATCH] Make HirMap thread-safe --- src/librustc/hir/map/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index e8bcbfbb77a1..1e348e3a31ce 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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>, + inlined_bodies: Lock>, /// The reverse mapping of `node_to_hir_id`. hir_to_node_id: FxHashMap, @@ -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);