mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
Make interners thread-safe
This commit is contained in:
@@ -1080,12 +1080,13 @@ pub fn intern_const_alloc(
|
||||
self,
|
||||
alloc: interpret::Allocation,
|
||||
) -> &'gcx interpret::Allocation {
|
||||
if let Some(alloc) = self.interpret_interner.inner.borrow().allocs.get(&alloc) {
|
||||
let allocs = &mut self.interpret_interner.inner.borrow_mut().allocs;
|
||||
if let Some(alloc) = allocs.get(&alloc) {
|
||||
return alloc;
|
||||
}
|
||||
|
||||
let interned = self.global_arenas.const_allocs.alloc(alloc);
|
||||
if let Some(prev) = self.interpret_interner.inner.borrow_mut().allocs.replace(interned) {
|
||||
if let Some(prev) = allocs.replace(interned) {
|
||||
bug!("Tried to overwrite interned Allocation: {:#?}", prev)
|
||||
}
|
||||
interned
|
||||
@@ -1112,24 +1113,26 @@ pub fn allocate_cached(self, bytes: &[u8]) -> interpret::AllocId {
|
||||
}
|
||||
|
||||
pub fn intern_stability(self, stab: attr::Stability) -> &'gcx attr::Stability {
|
||||
if let Some(st) = self.stability_interner.borrow().get(&stab) {
|
||||
let mut stability_interner = self.stability_interner.borrow_mut();
|
||||
if let Some(st) = stability_interner.get(&stab) {
|
||||
return st;
|
||||
}
|
||||
|
||||
let interned = self.global_interners.arena.alloc(stab);
|
||||
if let Some(prev) = self.stability_interner.borrow_mut().replace(interned) {
|
||||
if let Some(prev) = stability_interner.replace(interned) {
|
||||
bug!("Tried to overwrite interned Stability: {:?}", prev)
|
||||
}
|
||||
interned
|
||||
}
|
||||
|
||||
pub fn intern_layout(self, layout: LayoutDetails) -> &'gcx LayoutDetails {
|
||||
if let Some(layout) = self.layout_interner.borrow().get(&layout) {
|
||||
let mut layout_interner = self.layout_interner.borrow_mut();
|
||||
if let Some(layout) = layout_interner.get(&layout) {
|
||||
return layout;
|
||||
}
|
||||
|
||||
let interned = self.global_arenas.layout.alloc(layout);
|
||||
if let Some(prev) = self.layout_interner.borrow_mut().replace(interned) {
|
||||
if let Some(prev) = layout_interner.replace(interned) {
|
||||
bug!("Tried to overwrite interned Layout: {:?}", prev)
|
||||
}
|
||||
interned
|
||||
|
||||
Reference in New Issue
Block a user