From dac95a3ad8507fcad5fa64656ededd4cffc5b996 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 6 Jun 2022 17:27:46 -0400 Subject: [PATCH] =?UTF-8?q?rename=20AllocationMap=20=E2=86=92=20RangeObjec?= =?UTF-8?q?tMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/concurrency/mod.rs | 2 +- ...{allocation_map.rs => range_object_map.rs} | 25 +++++++++---------- src/concurrency/weak_memory.rs | 6 ++--- 3 files changed, 16 insertions(+), 17 deletions(-) rename src/concurrency/{allocation_map.rs => range_object_map.rs} (93%) diff --git a/src/concurrency/mod.rs b/src/concurrency/mod.rs index ad1586bbf0f..5f8bba80272 100644 --- a/src/concurrency/mod.rs +++ b/src/concurrency/mod.rs @@ -1,3 +1,3 @@ -mod allocation_map; pub mod data_race; +mod range_object_map; pub mod weak_memory; diff --git a/src/concurrency/allocation_map.rs b/src/concurrency/range_object_map.rs similarity index 93% rename from src/concurrency/allocation_map.rs rename to src/concurrency/range_object_map.rs index 62469dcaf43..2bb32803023 100644 --- a/src/concurrency/allocation_map.rs +++ b/src/concurrency/range_object_map.rs @@ -1,7 +1,6 @@ -//! Implements a map from allocation ranges to data. -//! This is somewhat similar to RangeMap, but the ranges -//! and data are discrete and non-splittable. An allocation in the -//! map will always have the same range until explicitly removed +//! Implements a map from allocation ranges to data. This is somewhat similar to RangeMap, but the +//! ranges and data are discrete and non-splittable -- they represent distinct "objects". An +//! allocation in the map will always have the same range until explicitly removed use rustc_target::abi::Size; use std::ops::{Index, IndexMut, Range}; @@ -20,7 +19,7 @@ struct Elem { type Position = usize; #[derive(Clone, Debug)] -pub struct AllocationMap { +pub struct RangeObjectMap { v: Vec>, } @@ -34,7 +33,7 @@ pub enum AccessType { ImperfectlyOverlapping(Range), } -impl AllocationMap { +impl RangeObjectMap { pub fn new() -> Self { Self { v: Vec::new() } } @@ -135,7 +134,7 @@ pub fn remove_from_pos(&mut self, pos: Position) { } } -impl Index for AllocationMap { +impl Index for RangeObjectMap { type Output = T; fn index(&self, pos: Position) -> &Self::Output { @@ -143,7 +142,7 @@ fn index(&self, pos: Position) -> &Self::Output { } } -impl IndexMut for AllocationMap { +impl IndexMut for RangeObjectMap { fn index_mut(&mut self, pos: Position) -> &mut Self::Output { &mut self.v[pos].data } @@ -159,7 +158,7 @@ mod tests { fn empty_map() { // FIXME: make Size::from_bytes const let four = Size::from_bytes(4); - let map = AllocationMap::<()>::new(); + let map = RangeObjectMap::<()>::new(); // Correctly tells where we should insert the first element (at position 0) assert_eq!(map.find_offset(Size::from_bytes(3)), Err(0)); @@ -173,7 +172,7 @@ fn empty_map() { fn no_overlapping_inserts() { let four = Size::from_bytes(4); - let mut map = AllocationMap::<&str>::new(); + let mut map = RangeObjectMap::<&str>::new(); // |_|_|_|_|#|#|#|#|_|_|_|_|... // 0 1 2 3 4 5 6 7 8 9 a b c d @@ -187,7 +186,7 @@ fn no_overlapping_inserts() { fn boundaries() { let four = Size::from_bytes(4); - let mut map = AllocationMap::<&str>::new(); + let mut map = RangeObjectMap::<&str>::new(); // |#|#|#|#|_|_|... // 0 1 2 3 4 5 @@ -215,7 +214,7 @@ fn boundaries() { fn perfectly_overlapping() { let four = Size::from_bytes(4); - let mut map = AllocationMap::<&str>::new(); + let mut map = RangeObjectMap::<&str>::new(); // |#|#|#|#|_|_|... // 0 1 2 3 4 5 @@ -241,7 +240,7 @@ fn perfectly_overlapping() { fn straddling() { let four = Size::from_bytes(4); - let mut map = AllocationMap::<&str>::new(); + let mut map = RangeObjectMap::<&str>::new(); // |_|_|_|_|#|#|#|#|_|_|_|_|... // 0 1 2 3 4 5 6 7 8 9 a b c d diff --git a/src/concurrency/weak_memory.rs b/src/concurrency/weak_memory.rs index da36fcd2fb3..be3963a93f0 100644 --- a/src/concurrency/weak_memory.rs +++ b/src/concurrency/weak_memory.rs @@ -85,8 +85,8 @@ use crate::{AtomicReadOp, AtomicRwOp, AtomicWriteOp, Tag, VClock, VTimestamp, VectorIdx}; use super::{ - allocation_map::{AccessType, AllocationMap}, data_race::{GlobalState, ThreadClockSet}, + range_object_map::{AccessType, RangeObjectMap}, }; pub type AllocExtra = StoreBufferAlloc; @@ -101,7 +101,7 @@ pub struct StoreBufferAlloc { /// Store buffer of each atomic object in this allocation // Behind a RefCell because we need to allocate/remove on read access - store_buffers: RefCell>, + store_buffers: RefCell>, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -134,7 +134,7 @@ struct StoreElement { impl StoreBufferAlloc { pub fn new_allocation() -> Self { - Self { store_buffers: RefCell::new(AllocationMap::new()) } + Self { store_buffers: RefCell::new(RangeObjectMap::new()) } } /// Checks if the range imperfectly overlaps with existing buffers