Skip to content

Commit

Permalink
Merge pull request #555 from MichaReiser/append-only-vec
Browse files Browse the repository at this point in the history
Replace `orx-concurrent-vec` with `append-only-vec`
  • Loading branch information
nikomatsakis authored Aug 6, 2024
2 parents 4c8e52a + 9fe3936 commit b098f92
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ crossbeam = "0.8"
dashmap = "6"
hashlink = "0.9"
indexmap = "2"
orx-concurrent-vec = "2"
append-only-vec = "0.1.5"
tracing = "0.1"
parking_lot = "0.12"
rustc-hash = "2"
Expand Down
10 changes: 4 additions & 6 deletions src/views.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::Database;
use append_only_vec::AppendOnlyVec;
use std::{
any::{Any, TypeId},
sync::Arc,
};

use orx_concurrent_vec::ConcurrentVec;

use crate::Database;

/// A `Views` struct is associated with some specific database type
/// (a `DatabaseImpl<U>` for some existential `U`). It contains functions
/// to downcast from that type to `dyn DbView` for various traits `DbView`.
Expand All @@ -26,7 +24,7 @@ use crate::Database;
#[derive(Clone)]
pub struct Views {
source_type_id: TypeId,
view_casters: Arc<ConcurrentVec<ViewCaster>>,
view_casters: Arc<AppendOnlyVec<ViewCaster>>,
}

/// A ViewCaster contains a trait object that can cast from the
Expand Down Expand Up @@ -91,7 +89,7 @@ impl Views {
let source_type_id = TypeId::of::<Db>();
Self {
source_type_id,
view_casters: Default::default(),
view_casters: Arc::new(AppendOnlyVec::new()),
}
}

Expand Down
26 changes: 11 additions & 15 deletions src/zalsa.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use append_only_vec::AppendOnlyVec;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;
use std::any::{Any, TypeId};
use std::marker::PhantomData;
use std::thread::ThreadId;

use orx_concurrent_vec::ConcurrentVec;
use parking_lot::Mutex;
use rustc_hash::FxHashMap;

use crate::cycle::CycleRecoveryStrategy;
use crate::ingredient::{Ingredient, Jar};
use crate::nonce::{Nonce, NonceGenerator};
Expand Down Expand Up @@ -102,10 +101,10 @@ pub struct Zalsa {
/// Vector of ingredients.
///
/// Immutable unless the mutex on `ingredients_map` is held.
ingredients_vec: ConcurrentVec<Box<dyn Ingredient>>,
ingredients_vec: AppendOnlyVec<Box<dyn Ingredient>>,

/// Indices of ingredients that require reset when a new revision starts.
ingredients_requiring_reset: ConcurrentVec<IngredientIndex>,
ingredients_requiring_reset: AppendOnlyVec<IngredientIndex>,

/// The runtime for this particular salsa database handle.
/// Each handle gets its own runtime, but the runtimes have shared state between them.
Expand All @@ -118,8 +117,8 @@ impl Zalsa {
views_of: Views::new::<Db>(),
nonce: NONCE.nonce(),
jar_map: Default::default(),
ingredients_vec: Default::default(),
ingredients_requiring_reset: Default::default(),
ingredients_vec: AppendOnlyVec::new(),
ingredients_requiring_reset: AppendOnlyVec::new(),
runtime: Runtime::default(),
}
}
Expand Down Expand Up @@ -156,7 +155,7 @@ impl Zalsa {
expected_index.as_usize(),
actual_index,
"ingredient `{:?}` was predicted to have index `{:?}` but actually has index `{:?}`",
self.ingredients_vec.get(actual_index).unwrap(),
self.ingredients_vec[actual_index],
expected_index,
actual_index,
);
Expand All @@ -168,7 +167,7 @@ impl Zalsa {
}

pub(crate) fn lookup_ingredient(&self, index: IngredientIndex) -> &dyn Ingredient {
&**self.ingredients_vec.get(index.as_usize()).unwrap()
&*self.ingredients_vec[index.as_usize()]
}

/// **NOT SEMVER STABLE**
Expand All @@ -177,7 +176,7 @@ impl Zalsa {
index: IngredientIndex,
) -> (&mut dyn Ingredient, &mut Runtime) {
(
&mut **self.ingredients_vec.get_mut(index.as_usize()).unwrap(),
&mut *self.ingredients_vec[index.as_usize()],
&mut self.runtime,
)
}
Expand Down Expand Up @@ -210,10 +209,7 @@ impl Zalsa {
let new_revision = self.runtime.new_revision();

for index in self.ingredients_requiring_reset.iter() {
self.ingredients_vec
.get_mut(index.as_usize())
.unwrap()
.reset_for_new_revision();
self.ingredients_vec[index.as_usize()].reset_for_new_revision();
}

new_revision
Expand Down

0 comments on commit b098f92

Please sign in to comment.