Skip to content

Commit

Permalink
Move Builder::new impl out of Configuration::builder method
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Aug 6, 2024
1 parent 0848b78 commit fbc7b8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions components/salsa-macro-rules/src/setup_input_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,6 @@ macro_rules! setup_input_struct {

pub fn builder($($required_field_id: $required_field_ty),*) -> <Self as $zalsa_struct::HasBuilder>::Builder
{
// Implement `new` here instead of inside the builder module
// because $Configuration can't be named in `builder`.
impl builder::$Builder {
/// Creates the new input with the set values.
#[must_use]
pub fn new<$Db>(self, db: &$Db) -> $Struct
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);
let ingredient = $Configuration::ingredient(db.as_dyn_database());
let (fields, stamps) = builder::builder_into_inner(self, current_revision);
ingredient.new_input(fields, stamps)
}
}

builder::new_builder($($zalsa::maybe_default!($field_option, $field_ty, $field_id,)),*)
}

Expand Down Expand Up @@ -239,6 +222,23 @@ macro_rules! setup_input_struct {
type Builder = builder::$Builder;
}

// Implement `new` here instead of inside the builder module
// because $Configuration can't be named in `builder`.
impl builder::$Builder {
/// Creates the new input with the set values.
#[must_use]
pub fn new<$Db>(self, db: &$Db) -> $Struct
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);
let ingredient = $Configuration::ingredient(db.as_dyn_database());
let (fields, stamps) = builder::builder_into_inner(self, current_revision);
ingredient.new_input(fields, stamps)
}
}

mod builder {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion tests/tracked_fn_on_input_with_high_durability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn execute() {
assert_eq!(tracked_fn(&db, input_low), 44);
assert_eq!(tracked_fn(&db, input_high), 4400);

// There's currently no good way to verify whether an input was validated using shallow or deep comparison.
// FIXME: There's currently no good way to verify whether an input was validated using shallow or deep comparison.
// All we can do for now is verify that the values were validated.
// Note: It maybe confusing why it validates `input_high` when the write has `Durability::LOW`.
// This is because all values must be validated whenever a write occurs. It doesn't mean that it
Expand Down

0 comments on commit fbc7b8c

Please sign in to comment.