Skip to content

Commit

Permalink
Revert implementing Configuration on struct because self-referentia…
Browse files Browse the repository at this point in the history
…l types stopped compiling
  • Loading branch information
MichaReiser committed Jul 26, 2024
1 parent f4f16e2 commit 2104b0f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
42 changes: 16 additions & 26 deletions components/salsa-macro-rules/src/setup_input_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ macro_rules! setup_input_struct {
use salsa::plumbing as $zalsa;
use $zalsa::input as $zalsa_struct;

type $Configuration = $Struct;
struct $Configuration;

impl $zalsa_struct::Configuration for $Configuration {
const DEBUG_NAME: &'static str = stringify!($Struct);
Expand Down Expand Up @@ -131,13 +131,15 @@ macro_rules! setup_input_struct {
Self::builder(db).new($($field_id,)*)
}

pub fn builder<'db, $Db>(db: &'db $Db) -> private::$Builder<'db>
pub fn builder<'db, $Db>(db: &'db $Db) -> $Builder<'db>
where
// FIXME(rust-lang/rust#65991): The `db` argument *should* have the type `dyn Database`
$Db: ?Sized + salsa::Database,
{
let current_revision = $zalsa::current_revision(db);
private::$Builder::create(current_revision, $Configuration::ingredient(db.as_salsa_database()))
$Builder {
inner: $zalsa_struct::BuilderImpl::new(current_revision, $Configuration::ingredient(db.as_salsa_database())),
}
}

$(
Expand Down Expand Up @@ -214,32 +216,20 @@ macro_rules! setup_input_struct {
}
}

pub struct $Builder<'db> {
#[doc(hidden)]
inner: $zalsa_struct::BuilderImpl<'db, $Configuration>,
}

mod private {
use salsa::plumbing as $zalsa;
use $zalsa::input as $zalsa_struct;

pub struct $Builder<'db> {
inner: $zalsa_struct::BuilderImpl<'db, super::$Struct>,
impl<'db> $Builder<'db> {
/// Sets the durability for all fields.
pub fn durability(mut self, durability: $zalsa::Durability) -> Self {
self.inner.durability(durability);
self
}

impl<'db> $Builder<'db> {
#[doc(hidden)]
pub(super) fn create(revision: $zalsa::Revision, ingredient: &'db $zalsa_struct::IngredientImpl<super::$Struct>) -> Self {
Self {
inner: $zalsa_struct::BuilderImpl::new(revision, ingredient),
}
}

/// Sets the durability for all fields.
pub fn durability(mut self, durability: $zalsa::Durability) -> Self {
self.inner.durability(durability);
self
}

pub fn new(self, $($field_id: $field_ty),*) -> super::$Struct {
self.inner.build(($($field_id,)*))
}
pub fn new(self, $($field_id: $field_ty),*) -> $Struct {
self.inner.build(($($field_id,)*))
}
}

Expand Down
1 change: 0 additions & 1 deletion components/salsa-macro-rules/src/setup_struct_fn.rs

This file was deleted.

8 changes: 4 additions & 4 deletions tests/accumulate-from-tracked-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//! Then mutate the values so that the tracked function re-executes.
//! Check that we accumulate the appropriate, new values.

mod common;
use common::{HasLogger, Logger};

use expect_test::expect;
use salsa::{Accumulator, Setter};
use test_log::test;

use common::{HasLogger, Logger};
use salsa::{Accumulator, Setter};

mod common;
#[salsa::db]
trait Db: salsa::Database + HasLogger {}

Expand Down

0 comments on commit 2104b0f

Please sign in to comment.