about summary refs log tree commit diff
path: root/src/librustc/hir
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-04-10 09:00:27 +0000
committerbors <bors@rust-lang.org>2018-04-10 09:00:27 +0000
commit67712d79451b042b6fca2167c1a57d91d86f663b (patch)
tree4027dafb2a803d522019bc41052763d61b056f5c /src/librustc/hir
parenta1c21ed7e21642b85947ba5d030bbaeffbe377de (diff)
parent1e3f6388361e1489d27679d6b9e8ba16681e3d26 (diff)
downloadrust-67712d79451b042b6fca2167c1a57d91d86f663b.tar.gz
rust-67712d79451b042b6fca2167c1a57d91d86f663b.zip
Auto merge of #49390 - Zoxc:sync-syntax, r=michaelwoerister
More thread-safety changes

r? @michaelwoerister
Diffstat (limited to 'src/librustc/hir')
-rw-r--r--src/librustc/hir/map/mod.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs
index e8bcbfbb77a..1e348e3a31c 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<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);