Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion components/salsa-macro-rules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! of this crate.

mod macro_if;
mod maybe_backdate;
mod maybe_default;
mod return_mode;
mod setup_accumulator_impl;
Expand Down
35 changes: 0 additions & 35 deletions components/salsa-macro-rules/src/maybe_backdate.rs

This file was deleted.

8 changes: 4 additions & 4 deletions components/salsa-macro-rules/src/maybe_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#[macro_export]
macro_rules! maybe_default {
(
($return_mode:ident, $maybe_backdate:ident, default),
($return_mode:ident, default),
$field_ty:ty,
$field_ref_expr:expr,
) => {
<$field_ty>::default()
};

(
($return_mode:ident, $maybe_backdate:ident, required),
($return_mode:ident, required),
$field_ty:ty,
$field_ref_expr:expr,
) => {
Expand All @@ -22,11 +22,11 @@ macro_rules! maybe_default {

#[macro_export]
macro_rules! maybe_default_tt {
(($return_mode:ident, $maybe_backdate:ident, default) => $($t:tt)*) => {
(($return_mode:ident, default) => $($t:tt)*) => {
$($t)*
};

(($return_mode:ident, $maybe_backdate:ident, required) => $($t:tt)*) => {
(($return_mode:ident, required) => $($t:tt)*) => {

};
}
24 changes: 12 additions & 12 deletions components/salsa-macro-rules/src/return_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@
#[macro_export]
macro_rules! return_mode_expression {
(
(copy, $maybe_backdate:ident, $maybe_default:ident),
(copy, $maybe_default:ident),
$field_ty:ty,
$field_ref_expr:expr,
) => {
*$field_ref_expr
};

(
(clone, $maybe_backdate:ident, $maybe_default:ident),
(clone, $maybe_default:ident),
$field_ty:ty,
$field_ref_expr:expr,
) => {
::core::clone::Clone::clone($field_ref_expr)
};

(
(ref, $maybe_backdate:ident, $maybe_default:ident),
(ref, $maybe_default:ident),
$field_ty:ty,
$field_ref_expr:expr,
) => {
$field_ref_expr
};

(
(deref, $maybe_backdate:ident, $maybe_default:ident),
(deref, $maybe_default:ident),
$field_ty:ty,
$field_ref_expr:expr,
) => {
::core::ops::Deref::deref($field_ref_expr)
};

(
(as_ref, $maybe_backdate:ident, $maybe_default:ident),
(as_ref, $maybe_default:ident),
$field_ty:ty,
$field_ref_expr:expr,
) => {
::salsa::SalsaAsRef::as_ref($field_ref_expr)
};

(
(as_deref, $maybe_backdate:ident, $maybe_default:ident),
(as_deref, $maybe_default:ident),
$field_ty:ty,
$field_ref_expr:expr,
) => {
Expand All @@ -55,47 +55,47 @@ macro_rules! return_mode_expression {
#[macro_export]
macro_rules! return_mode_ty {
(
(copy, $maybe_backdate:ident, $maybe_default:ident),
(copy, $maybe_default:ident),
$db_lt:lifetime,
$field_ty:ty
) => {
$field_ty
};

(
(clone, $maybe_backdate:ident, $maybe_default:ident),
(clone, $maybe_default:ident),
$db_lt:lifetime,
$field_ty:ty
) => {
$field_ty
};

(
(ref, $maybe_backdate:ident, $maybe_default:ident),
(ref, $maybe_default:ident),
$db_lt:lifetime,
$field_ty:ty
) => {
& $db_lt $field_ty
};

(
(deref, $maybe_backdate:ident, $maybe_default:ident),
(deref, $maybe_default:ident),
$db_lt:lifetime,
$field_ty:ty
) => {
& $db_lt <$field_ty as ::core::ops::Deref>::Target
};

(
(as_ref, $maybe_backdate:ident, $maybe_default:ident),
(as_ref, $maybe_default:ident),
$db_lt:lifetime,
$field_ty:ty
) => {
<$field_ty as ::salsa::SalsaAsRef>::AsRef<$db_lt>
};

(
(as_deref, $maybe_backdate:ident, $maybe_default:ident),
(as_deref, $maybe_default:ident),
$db_lt:lifetime,
$field_ty:ty
) => {
Expand Down
4 changes: 2 additions & 2 deletions components/salsa-macro-rules/src/setup_tracked_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ macro_rules! setup_tracked_fn {
$vis fn $fn_name<$db_lt>(
$db: &$db_lt dyn $Db,
$($input_id: $input_ty,)*
) -> salsa::plumbing::return_mode_ty!(($return_mode, __, __), $db_lt, $output_ty) {
) -> salsa::plumbing::return_mode_ty!(($return_mode, __), $db_lt, $output_ty) {
use salsa::plumbing as $zalsa;

struct $Configuration;
Expand Down Expand Up @@ -391,7 +391,7 @@ macro_rules! setup_tracked_fn {
}
};

$zalsa::return_mode_expression!(($return_mode, __, __), $output_ty, result,)
$zalsa::return_mode_expression!(($return_mode, __), $output_ty, result,)
})
}

Expand Down
25 changes: 6 additions & 19 deletions components/salsa-macro-rules/src/setup_tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,17 @@ macro_rules! setup_tracked_struct {

// A set of "field options" for each tracked field.
//
// Each field option is a tuple `(return_mode, maybe_backdate)` where:
// Each field option is a tuple `(return_mode, maybe_default)` where:
//
// * `return_mode` is an identifier as specified in `salsa_macros::options::Option::returns`
// * `maybe_backdate` is either the identifier `backdate` or `no_backdate`
// * `maybe_default` is either the identifier `default` or `required`
//
// These are used to drive conditional logic for each field via recursive macro invocation
// (see e.g. @return_mode below).
tracked_options: [$($tracked_option:tt),*],

// A set of "field options" for each untracked field.
//
// Each field option is a tuple `(return_mode, maybe_backdate)` where:
//
// * `return_mode` is an identifier as specified in `salsa_macros::options::Option::returns`
// * `maybe_backdate` is either the identifier `backdate` or `no_backdate`
//
// These are used to drive conditional logic for each field via recursive macro invocation
// (see e.g. @return_mode below).
// (see docs for `tracked_options`).
untracked_options: [$($untracked_option:tt),*],

// Attrs for each field.
Expand Down Expand Up @@ -163,15 +156,9 @@ macro_rules! setup_tracked_struct {
use $zalsa::UpdateFallback as _;
unsafe {
$(
$crate::maybe_backdate!(
$tracked_option,
$tracked_maybe_update,
(*old_fields).$absolute_tracked_index,
new_fields.$absolute_tracked_index,
revisions[$relative_tracked_index],
current_revision,
$zalsa,
);
if $tracked_maybe_update(std::ptr::addr_of_mut!((*old_fields).$absolute_tracked_index), new_fields.$absolute_tracked_index) {
revisions[$relative_tracked_index] = current_revision;
}
)*;

// If any untracked field has changed, return `true`, indicating that the tracked struct
Expand Down
8 changes: 1 addition & 7 deletions components/salsa-macros/src/salsa_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,12 @@ impl<'s> SalsaField<'s> {
fn options(&self) -> TokenStream {
let returns = &self.returns;

let backdate_ident = if self.has_no_eq_attr {
syn::Ident::new("no_backdate", Span::call_site())
} else {
syn::Ident::new("backdate", Span::call_site())
};

let default_ident = if self.has_default_attr {
syn::Ident::new("default", Span::call_site())
} else {
syn::Ident::new("required", Span::call_site())
};

quote!((#returns, #backdate_ident, #default_ident))
quote!((#returns, #default_ident))
}
}
25 changes: 13 additions & 12 deletions components/salsa-macros/src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use syn::spanned::Spanned;
use crate::db_lifetime;
use crate::hygiene::Hygiene;
use crate::options::Options;
use crate::salsa_struct::{SalsaStruct, SalsaStructAllowedOptions};
use crate::salsa_struct::{SalsaField, SalsaStruct, SalsaStructAllowedOptions};

/// For an entity struct `Foo` with fields `f1: T1, ..., fN: TN`, we generate...
///
Expand Down Expand Up @@ -124,22 +124,23 @@ impl Macro {
let tracked_field_unused_attrs = salsa_struct.tracked_field_attrs();
let untracked_field_unused_attrs = salsa_struct.untracked_field_attrs();

let tracked_maybe_update = salsa_struct.tracked_fields_iter().map(|(_, field)| {
let field_to_maybe_update = |(_, field): (usize, &SalsaField<'_>)| {
let field_ty = &field.field.ty;
if let Some((with_token, maybe_update)) = &field.maybe_update_attr {
if field.has_no_eq_attr {
quote! {{#zalsa::always_update::<#field_ty>}}
} else if let Some((with_token, maybe_update)) = &field.maybe_update_attr {
quote_spanned! { with_token.span() => ({ let maybe_update: unsafe fn(*mut #field_ty, #field_ty) -> bool = #maybe_update; maybe_update }) }
} else {
quote! {(#zalsa::UpdateDispatch::<#field_ty>::maybe_update)}
}
});
let untracked_maybe_update = salsa_struct.untracked_fields_iter().map(|(_, field)| {
let field_ty = &field.field.ty;
if let Some((with_token, maybe_update)) = &field.maybe_update_attr {
quote_spanned! { with_token.span() => ({ let maybe_update: unsafe fn(*mut #field_ty, #field_ty) -> bool = #maybe_update; maybe_update }) }
} else {
quote! {(#zalsa::UpdateDispatch::<#field_ty>::maybe_update)}
}
});
};

let tracked_maybe_update = salsa_struct
.tracked_fields_iter()
.map(field_to_maybe_update);
let untracked_maybe_update = salsa_struct
.untracked_fields_iter()
.map(field_to_maybe_update);

let num_tracked_fields = salsa_struct.num_tracked_fields();
let generate_debug_impl = salsa_struct.generate_debug_impl();
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ pub mod plumbing {
pub use std::option::Option::{self, None, Some};

pub use salsa_macro_rules::{
macro_if, maybe_backdate, maybe_default, maybe_default_tt, return_mode_expression,
return_mode_ty, setup_accumulator_impl, setup_input_struct, setup_interned_struct,
macro_if, maybe_default, maybe_default_tt, return_mode_expression, return_mode_ty,
setup_accumulator_impl, setup_input_struct, setup_interned_struct,
setup_tracked_assoc_fn_body, setup_tracked_fn, setup_tracked_method_body,
setup_tracked_struct, unexpected_cycle_initial, unexpected_cycle_recovery,
};
Expand Down
24 changes: 12 additions & 12 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::path::PathBuf;
use rayon::iter::Either;

use crate::sync::Arc;
use crate::Revision;

/// This is used by the macro generated code.
/// If possible, uses `Update` trait, but else requires `'static`.
Expand Down Expand Up @@ -100,17 +99,18 @@ where
}
}

/// Helper for generated code. Updates `*old_pointer` with `new_value`
/// and updates `*old_revision` with `new_revision.` Used for fields
/// tagged with `#[no_eq]`
pub fn always_update<T>(
old_revision: &mut Revision,
new_revision: Revision,
old_pointer: &mut T,
new_value: T,
) {
*old_revision = new_revision;
*old_pointer = new_value;
/// Helper for generated code. Updates `*old_pointer` with `new_value`.
/// Used for fields tagged with `#[no_eq]`
///
/// # Safety
///
/// See `Update::maybe_update`
pub unsafe fn always_update<T>(old_pointer: *mut T, new_value: T) -> bool {
unsafe {
*old_pointer = new_value;
}

true
}

/// # Safety
Expand Down