cleanup: Remove unnecessary Array abstraction (#821)

This commit is contained in:
Lukas Wirth 2025-04-28 09:33:31 +02:00 committed by GitHub
parent 9a9fb4e51b
commit 4fa0ee8dfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 13 additions and 49 deletions

View file

@ -83,7 +83,7 @@ macro_rules! setup_input_struct {
type Fields = ($($field_ty,)*);
/// A array of [`StampedValue<()>`](`StampedValue`) tuples, one per each of the value fields.
type Stamps = $zalsa::Array<$zalsa::Stamp, $N>;
type Stamps = [$zalsa::Stamp; $N];
}
impl $Configuration {
@ -284,10 +284,8 @@ macro_rules! setup_input_struct {
}
}
pub(super) fn builder_into_inner(builder: $Builder, revision: $zalsa::Revision) -> (($($field_ty,)*), $zalsa::Array<$zalsa::Stamp, $N>) {
let stamps = $zalsa::Array::new([
$($zalsa::stamp(revision, builder.durabilities[$field_index])),*
]);
pub(super) fn builder_into_inner(builder: $Builder, revision: $zalsa::Revision) -> (($($field_ty,)*), [$zalsa::Stamp; $N]) {
let stamps = [$($zalsa::stamp(revision, builder.durabilities[$field_index])),*];
(builder.fields, stamps)
}

View file

@ -121,7 +121,7 @@ macro_rules! setup_tracked_struct {
type Fields<$db_lt> = ($($field_ty,)*);
type Revisions = $zalsa::Array<$Revision, $N>;
type Revisions = [$Revision; $N];
type Struct<$db_lt> = $Struct<$db_lt>;
@ -138,7 +138,7 @@ macro_rules! setup_tracked_struct {
}
fn new_revisions(current_revision: $Revision) -> Self::Revisions {
$zalsa::Array::new([current_revision; $N])
[current_revision; $N]
}
unsafe fn update_fields<$db_lt>(

View file

@ -1,27 +0,0 @@
use std::fmt::Debug;
use std::ops::{Deref, DerefMut};
#[derive(Copy, Clone, Debug)]
pub struct Array<T, const N: usize> {
data: [T; N],
}
impl<T, const N: usize> Array<T, N> {
pub fn new(data: [T; N]) -> Self {
Self { data }
}
}
impl<T, const N: usize> Deref for Array<T, N> {
type Target = [T];
fn deref(&self) -> &Self::Target {
&self.data
}
}
impl<T, const N: usize> DerefMut for Array<T, N> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.data
}
}

View file

@ -1,6 +1,6 @@
use std::any::{Any, TypeId};
use std::fmt;
use std::ops::DerefMut;
use std::ops::IndexMut;
use std::sync::Arc;
pub mod input_field;
@ -34,7 +34,7 @@ pub trait Configuration: Any {
type Fields: Send + Sync;
/// A array of [`StampedValue<()>`](`StampedValue`) tuples, one per each of the value fields.
type Stamps: Send + Sync + fmt::Debug + DerefMut<Target = [Stamp]>;
type Stamps: Send + Sync + fmt::Debug + IndexMut<usize, Output = Stamp>;
}
pub struct JarImpl<C: Configuration> {

View file

@ -3,7 +3,6 @@
mod accumulator;
mod active_query;
mod array;
mod attach;
mod cancelled;
mod cycle;
@ -50,7 +49,7 @@ pub use self::input::setter::Setter;
pub use self::key::DatabaseKeyIndex;
pub use self::revision::Revision;
pub use self::runtime::Runtime;
pub use self::storage::Storage;
pub use self::storage::{Storage, StorageHandle};
pub use self::update::Update;
pub use self::zalsa::IngredientIndex;
pub use crate::attach::with_attached_database;
@ -77,7 +76,6 @@ pub mod plumbing {
};
pub use crate::accumulator::Accumulator;
pub use crate::array::Array;
pub use crate::attach::{attach, with_attached_database};
pub use crate::cycle::{CycleRecoveryAction, CycleRecoveryStrategy};
pub use crate::database::{current_revision, Database};

View file

@ -4,7 +4,7 @@ use std::any::TypeId;
use std::fmt;
use std::hash::Hash;
use std::marker::PhantomData;
use std::ops::DerefMut;
use std::ops::Index;
use std::sync::Arc;
use crossbeam_queue::SegQueue;
@ -45,7 +45,7 @@ pub trait Configuration: Sized + 'static {
/// When a struct is re-recreated in a new revision, the corresponding
/// entries for each field are updated to the new revision if their
/// values have changed (or if the field is marked as `#[no_eq]`).
type Revisions: Send + Sync + DerefMut<Target = [Revision]>;
type Revisions: Send + Sync + Index<usize, Output = Revision>;
type Struct<'db>: Copy;
@ -151,7 +151,7 @@ pub trait TrackedStructInDb: SalsaStructInDb {
///
/// This ingredient only stores the "id" fields. It is a kind of "dressed up" interner;
/// the active query + values of id fields are hashed to create the tracked
/// struct id. The value fields are stored in [`crate::function::FunctionIngredient`]
/// struct id. The value fields are stored in [`crate::function::IngredientImpl`]
/// instances keyed by the tracked struct id. Unlike normal interners, tracked
/// struct indices can be deleted and reused aggressively: when a tracked
/// function re-executes, any tracked structs that it created before but did
@ -676,11 +676,6 @@ where
///
/// Note that this function returns the entire tuple of value fields.
/// The caller is responsible for selecting the appropriate element.
///
/// This function takes two indices:
/// - `field_index` is the absolute index of the field on the tracked struct.
/// - `relative_tracked_index` is the index of the field relative only to other
/// tracked fields.
pub fn tracked_field<'db>(
&'db self,
db: &'db dyn crate::Database,

View file

@ -12,7 +12,7 @@ use crate::{Database, Id};
/// This ingredient only stores the "id" fields.
/// It is a kind of "dressed up" interner;
/// the active query + values of id fields are hashed to create the tracked struct id.
/// The value fields are stored in [`crate::function::FunctionIngredient`] instances keyed by the tracked struct id.
/// The value fields are stored in [`crate::function::IngredientImpl`] instances keyed by the tracked struct id.
/// Unlike normal interners, tracked struct indices can be deleted and reused aggressively:
/// when a tracked function re-executes,
/// any tracked structs that it created before but did not create this time can be deleted.
@ -23,7 +23,7 @@ where
/// Index of this ingredient in the database (used to construct database-ids, etc).
ingredient_index: IngredientIndex,
/// The absolute index of this field on the tracked struct.
/// The index of this field on the tracked struct relative to all other tracked fields.
field_index: usize,
phantom: PhantomData<fn() -> Value<C>>,
}