mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 12:56:33 +00:00
Make salsa buildable on power
rust-analyzer fails in rust-lang/rust repo on the power target, because it doesn't have `AtomicU64`. So, lets just use `AtomicUsize` as a revision number. Semantically this is wrong, as we are not using revision to address arrays, but, practically, it's a nice compromise to build on targets without AtomicU64 and to have large revision numbers on most relevant targets.
This commit is contained in:
parent
bfafe50d8f
commit
44ca713da1
2 changed files with 18 additions and 18 deletions
|
@ -1,9 +1,9 @@
|
||||||
use std::num::NonZeroU64;
|
use std::num::NonZeroUsize;
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
/// Value of the initial revision, as a u64. We don't use 0
|
/// Value of the initial revision, as a u64. We don't use 0
|
||||||
/// because we want to use a `NonZeroU64`.
|
/// because we want to use a `NonZeroUsize`.
|
||||||
const START_U64: u64 = 1;
|
const START: usize = 1;
|
||||||
|
|
||||||
/// A unique identifier for the current version of the database; each
|
/// A unique identifier for the current version of the database; each
|
||||||
/// time an input is changed, the revision number is incremented.
|
/// time an input is changed, the revision number is incremented.
|
||||||
|
@ -12,17 +12,17 @@ const START_U64: u64 = 1;
|
||||||
/// directly as a user of salsa.
|
/// directly as a user of salsa.
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct Revision {
|
pub struct Revision {
|
||||||
generation: NonZeroU64,
|
generation: NonZeroUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Revision {
|
impl Revision {
|
||||||
pub(crate) fn start() -> Self {
|
pub(crate) fn start() -> Self {
|
||||||
Self::from(START_U64)
|
Self::from(START)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from(g: u64) -> Self {
|
pub(crate) fn from(g: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
generation: NonZeroU64::new(g).unwrap(),
|
generation: NonZeroUsize::new(g).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ impl Revision {
|
||||||
Self::from(self.generation.get() + 1)
|
Self::from(self.generation.get() + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_u64(self) -> u64 {
|
fn as_usize(self) -> usize {
|
||||||
self.generation.get()
|
self.generation.get()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,13 @@ impl std::fmt::Debug for Revision {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct AtomicRevision {
|
pub(crate) struct AtomicRevision {
|
||||||
data: AtomicU64,
|
data: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AtomicRevision {
|
impl AtomicRevision {
|
||||||
pub(crate) fn start() -> Self {
|
pub(crate) fn start() -> Self {
|
||||||
Self {
|
Self {
|
||||||
data: AtomicU64::new(START_U64),
|
data: AtomicUsize::new(START),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,13 +58,13 @@ impl AtomicRevision {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn store(&self, r: Revision) {
|
pub(crate) fn store(&self, r: Revision) {
|
||||||
self.data.store(r.as_u64(), Ordering::SeqCst);
|
self.data.store(r.as_usize(), Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Increment by 1, returning previous value.
|
/// Increment by 1, returning previous value.
|
||||||
pub(crate) fn fetch_then_increment(&self) -> Revision {
|
pub(crate) fn fetch_then_increment(&self) -> Revision {
|
||||||
let v = self.data.fetch_add(1, Ordering::SeqCst);
|
let v = self.data.fetch_add(1, Ordering::SeqCst);
|
||||||
assert!(v != u64::max_value(), "revision overflow");
|
assert!(v != usize::max_value(), "revision overflow");
|
||||||
Revision::from(v)
|
Revision::from(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use parking_lot::{Mutex, RwLock};
|
||||||
use rustc_hash::{FxHashMap, FxHasher};
|
use rustc_hash::{FxHashMap, FxHasher};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::hash::{BuildHasherDefault, Hash};
|
use std::hash::{BuildHasherDefault, Hash};
|
||||||
use std::sync::atomic::{AtomicU64, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub(crate) type FxIndexSet<K> = indexmap::IndexSet<K, BuildHasherDefault<FxHasher>>;
|
pub(crate) type FxIndexSet<K> = indexmap::IndexSet<K, BuildHasherDefault<FxHasher>>;
|
||||||
|
@ -558,14 +558,14 @@ struct SharedState<DB: Database> {
|
||||||
storage: DB::DatabaseStorage,
|
storage: DB::DatabaseStorage,
|
||||||
|
|
||||||
/// Stores the next id to use for a snapshotted runtime (starts at 1).
|
/// Stores the next id to use for a snapshotted runtime (starts at 1).
|
||||||
next_id: AtomicU64,
|
next_id: AtomicUsize,
|
||||||
|
|
||||||
/// Whenever derived queries are executing, they acquire this lock
|
/// Whenever derived queries are executing, they acquire this lock
|
||||||
/// in read mode. Mutating inputs (and thus creating a new
|
/// in read mode. Mutating inputs (and thus creating a new
|
||||||
/// revision) requires a write lock (thus guaranteeing that no
|
/// revision) requires a write lock (thus guaranteeing that no
|
||||||
/// derived queries are in progress). Note that this is not needed
|
/// derived queries are in progress). Note that this is not needed
|
||||||
/// to prevent **race conditions** -- the revision counter itself
|
/// to prevent **race conditions** -- the revision counter itself
|
||||||
/// is stored in an `AtomicU64` so it can be cheaply read
|
/// is stored in an `AtomicUsize` so it can be cheaply read
|
||||||
/// without acquiring the lock. Rather, the `query_lock` is used
|
/// without acquiring the lock. Rather, the `query_lock` is used
|
||||||
/// to ensure a higher-level consistency property.
|
/// to ensure a higher-level consistency property.
|
||||||
query_lock: RwLock<()>,
|
query_lock: RwLock<()>,
|
||||||
|
@ -594,7 +594,7 @@ struct SharedState<DB: Database> {
|
||||||
impl<DB: Database> SharedState<DB> {
|
impl<DB: Database> SharedState<DB> {
|
||||||
fn with_durabilities(durabilities: usize) -> Self {
|
fn with_durabilities(durabilities: usize) -> Self {
|
||||||
SharedState {
|
SharedState {
|
||||||
next_id: AtomicU64::new(1),
|
next_id: AtomicUsize::new(1),
|
||||||
storage: Default::default(),
|
storage: Default::default(),
|
||||||
query_lock: Default::default(),
|
query_lock: Default::default(),
|
||||||
revisions: (0..durabilities).map(|_| AtomicRevision::start()).collect(),
|
revisions: (0..durabilities).map(|_| AtomicRevision::start()).collect(),
|
||||||
|
@ -715,7 +715,7 @@ impl<DB: Database> ActiveQuery<DB> {
|
||||||
/// complete, its `RuntimeId` may potentially be re-used.
|
/// complete, its `RuntimeId` may potentially be re-used.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct RuntimeId {
|
pub struct RuntimeId {
|
||||||
counter: u64,
|
counter: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
Loading…
Reference in a new issue