diff --git a/components/salsa-2022-macros/src/db_lifetime.rs b/components/salsa-2022-macros/src/db_lifetime.rs index d6bafaa08..2074d4085 100644 --- a/components/salsa-2022-macros/src/db_lifetime.rs +++ b/components/salsa-2022-macros/src/db_lifetime.rs @@ -16,7 +16,7 @@ pub(crate) fn default_db_lifetime(span: Span) -> syn::Lifetime { /// Require that either there are no generics or exactly one lifetime parameter. pub(crate) fn require_optional_db_lifetime(generics: &syn::Generics) -> syn::Result<()> { - if generics.params.len() == 0 { + if generics.params.is_empty() { return Ok(()); } @@ -27,7 +27,7 @@ pub(crate) fn require_optional_db_lifetime(generics: &syn::Generics) -> syn::Res /// Require that either there is exactly one lifetime parameter. pub(crate) fn require_db_lifetime(generics: &syn::Generics) -> syn::Result<()> { - if generics.params.len() == 0 { + if generics.params.is_empty() { return Err(syn::Error::new_spanned( generics, "this definition must have a `'db` lifetime", diff --git a/components/salsa-2022-macros/src/debug.rs b/components/salsa-2022-macros/src/debug.rs index 22ba85618..e7ec53ada 100644 --- a/components/salsa-2022-macros/src/debug.rs +++ b/components/salsa-2022-macros/src/debug.rs @@ -31,8 +31,7 @@ pub(crate) fn dump_tokens(input_name: impl ToString, tokens: TokenStream) -> Tok .unwrap() .write_all(token_string.as_bytes())?; rustfmt.wait_with_output() - }) - .and_then(|output| Ok(eprintln!("{}", String::from_utf8_lossy(&output.stdout)))) + }).map(|output| eprintln!("{}", String::from_utf8_lossy(&output.stdout))) .or_else(|_| Ok(eprintln!("{token_string}"))); } diff --git a/components/salsa-2022-macros/src/debug_with_db.rs b/components/salsa-2022-macros/src/debug_with_db.rs index 17c5c535f..c840527f8 100644 --- a/components/salsa-2022-macros/src/debug_with_db.rs +++ b/components/salsa-2022-macros/src/debug_with_db.rs @@ -62,7 +62,7 @@ pub(crate) fn debug_with_db(input: syn::DeriveInput) -> syn::Result syn::Result variant.fold( quote!(#fmt.debug_tuple(#variant_name)), |tokens, binding| { - let binding_data = binding_tokens(&binding); + let binding_data = binding_tokens(binding); quote!(#tokens . field(#binding_data)) }, ), diff --git a/components/salsa-2022-macros/src/input.rs b/components/salsa-2022-macros/src/input.rs index de273d480..e31b36821 100644 --- a/components/salsa-2022-macros/src/input.rs +++ b/components/salsa-2022-macros/src/input.rs @@ -55,7 +55,7 @@ impl InputStruct { let inherent_impl = self.input_inherent_impl(); let ingredients_for_impl = self.input_ingredients(); let as_id_impl = self.as_id_impl(); - let from_id_impl = self.from_id_impl(); + let from_id_impl = self.impl_of_from_id(); let salsa_struct_in_db_impl = self.salsa_struct_in_db_impl(); let as_debug_with_db_impl = self.as_debug_with_db_impl(); let debug_impl = self.debug_impl(); diff --git a/components/salsa-2022-macros/src/interned.rs b/components/salsa-2022-macros/src/interned.rs index f7f9b6836..7c0bde7d7 100644 --- a/components/salsa-2022-macros/src/interned.rs +++ b/components/salsa-2022-macros/src/interned.rs @@ -62,7 +62,7 @@ impl InternedStruct { let configuration_impl = self.configuration_impl(&data_struct.ident, &config_struct.ident); let ingredients_for_impl = self.ingredients_for_impl(&config_struct.ident); let as_id_impl = self.as_id_impl(); - let from_id_impl = self.from_id_impl(); + let from_id_impl = self.impl_of_from_id(); let lookup_id_impl = self.lookup_id_impl(); let send_sync_impls = self.send_sync_impls(); let named_fields_impl = self.inherent_impl_for_named_fields(); diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index 3e2f1003a..329813f5b 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -177,7 +177,7 @@ impl SalsaStruct { // FIXME: this should be a comma separated list but I couldn't // be bothered to remember how syn does this. let args: syn::Ident = attr.parse_args()?; - if args.to_string() == "DebugWithDb" { + if args == "DebugWithDb" { Ok(vec![Customization::DebugWithDb]) } else { Err(syn::Error::new_spanned(args, "unrecognized customization")) @@ -446,7 +446,7 @@ impl SalsaStruct { } /// Generate `impl salsa::id::AsId for Foo` - pub(crate) fn from_id_impl(&self) -> Option { + pub(crate) fn impl_of_from_id(&self) -> Option { match self.the_struct_kind() { TheStructKind::Id => { let ident = self.the_ident(); diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 907ee3779..29744200e 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -50,7 +50,7 @@ pub(crate) fn tracked_fn( *item_fn.block = getter_fn(&args, &mut item_fn.sig, item_fn.block.span(), &config_ty)?; Ok(crate::debug::dump_tokens( - &fn_ident, + fn_ident, quote! { #fn_struct diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index 1349c440e..bdd87048d 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -16,7 +16,7 @@ pub(crate) fn tracked( let tokens = SalsaStruct::with_struct(args, struct_item, "tracked_struct") .and_then(|el| TrackedStruct(el).generate_tracked())?; - Ok(crate::debug::dump_tokens(&struct_name, tokens)) + Ok(crate::debug::dump_tokens(struct_name, tokens)) } struct TrackedStruct(SalsaStruct); @@ -65,7 +65,7 @@ impl TrackedStruct { let update_impl = self.update_impl(); let as_id_impl = self.as_id_impl(); let send_sync_impls = self.send_sync_impls(); - let from_id_impl = self.from_id_impl(); + let from_id_impl = self.impl_of_from_id(); let lookup_id_impl = self.lookup_id_impl(); let debug_impl = self.debug_impl(); let as_debug_with_db_impl = self.as_debug_with_db_impl(); @@ -250,8 +250,6 @@ impl TrackedStruct { let field_tys = self.all_field_tys(); let constructor_name = self.constructor_name(); - let data = syn::Ident::new("__data", Span::call_site()); - let salsa_id = self.access_salsa_id_from_self(); let lt_db = self.maybe_elided_db_lifetime(); diff --git a/components/salsa-2022/src/function/memo.rs b/components/salsa-2022/src/function/memo.rs index 45182b6ed..a40c21e5a 100644 --- a/components/salsa-2022/src/function/memo.rs +++ b/components/salsa-2022/src/function/memo.rs @@ -58,7 +58,7 @@ impl MemoMap { /// Removes any existing memo for the given key. #[must_use] - pub(super) fn remove<'db>(&'db self, key: Id) -> Option>>> { + pub(super) fn remove(&self, key: Id) -> Option>>> { unsafe { self.map.remove(&key).map(|o| self.to_self(o.1)) } } diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index 7839b64fe..2fc7c79ad 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -9,7 +9,6 @@ use crate::durability::Durability; use crate::id::{AsId, LookupId}; use crate::ingredient::{fmt_index, IngredientRequiresReset}; use crate::key::DependencyIndex; -use crate::plumbing::transmute_lifetime; use crate::runtime::local_state::QueryOrigin; use crate::runtime::Runtime; use crate::{DatabaseKeyIndex, Id}; @@ -30,7 +29,7 @@ pub trait Configuration: Sized { /// created or, if a struct is being reused, after we have updated its /// fields (or confirmed it is green and no updates are required). /// - /// # Unsafety + /// # Safety /// /// Requires that `ptr` represents a "confirmed" value in this revision, /// which means that it will remain valid and immutable for the remainder of this @@ -40,7 +39,7 @@ pub trait Configuration: Sized { /// Deref the struct to yield the underlying value struct. /// Since we are still part of the `'db` lifetime in which the struct was created, /// this deref is safe, and the value-struct fields are immutable and verified. - fn deref_struct<'db>(s: Self::Struct<'db>) -> &'db ValueStruct; + fn deref_struct(s: Self::Struct<'_>) -> &ValueStruct; } pub trait InternedData: Sized + Eq + Hash + Clone {} @@ -152,7 +151,7 @@ where } } - pub fn interned_value<'db>(&'db self, id: Id) -> C::Struct<'db> { + pub fn interned_value(&self, id: Id) -> C::Struct<'_> { let r = self.value_map.get(&id).unwrap(); // SAFETY: Items are only removed from the `value_map` with an `&mut self` reference. @@ -162,7 +161,7 @@ where /// Lookup the data for an interned value based on its id. /// Rarely used since end-users generally carry a struct with a pointer directly /// to the interned item. - pub fn data<'db>(&'db self, id: Id) -> &'db C::Data<'db> { + pub fn data(&self, id: Id) -> &C::Data<'_> { C::deref_struct(self.interned_value(id)).data() } @@ -284,7 +283,7 @@ impl ValueStruct where C: Configuration, { - pub fn data<'db>(&'db self) -> &'db C::Data<'db> { + pub fn data(&self) -> &C::Data<'_> { // SAFETY: The lifetime of `self` is tied to the interning ingredient; // we never remove data without an `&mut self` access to the interning ingredient. unsafe { self.to_self_ref(&self.fields) } diff --git a/components/salsa-2022/src/runtime/active_query.rs b/components/salsa-2022/src/runtime/active_query.rs index 1af86f823..4e966ca9c 100644 --- a/components/salsa-2022/src/runtime/active_query.rs +++ b/components/salsa-2022/src/runtime/active_query.rs @@ -172,7 +172,7 @@ impl ActiveQuery { pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) { self.changed_at = cycle_query.changed_at; self.durability = cycle_query.durability; - self.input_outputs = cycle_query.input_outputs.clone(); + self.input_outputs.clone_from(&cycle_query.input_outputs); } pub(super) fn disambiguate(&mut self, hash: u64) -> Disambiguator { diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 59197899c..32287eb3f 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -44,7 +44,7 @@ pub trait Configuration: Sized { /// created or, if a struct is being reused, after we have updated its /// fields (or confirmed it is green and no updates are required). /// - /// # Unsafety + /// # Safety /// /// Requires that `ptr` represents a "confirmed" value in this revision, /// which means that it will remain valid and immutable for the remainder of this @@ -54,7 +54,7 @@ pub trait Configuration: Sized { /// Deref the struct to yield the underlying value struct. /// Since we are still part of the `'db` lifetime in which the struct was created, /// this deref is safe, and the value-struct fields are immutable and verified. - fn deref_struct<'db>(s: Self::Struct<'db>) -> &'db ValueStruct; + fn deref_struct(s: Self::Struct<'_>) -> &ValueStruct; fn id_fields(fields: &Self::Fields<'_>) -> impl Hash; @@ -68,7 +68,7 @@ pub trait Configuration: Sized { /// Update the field data and, if the value has changed, /// the appropriate entry in the `revisions` array. /// - /// # Safety requirements and conditions + /// # Safety /// /// Requires the same conditions as the `maybe_update` /// method on [the `Update` trait](`crate::update::Update`). diff --git a/components/salsa-2022/src/tracked_struct/struct_map.rs b/components/salsa-2022/src/tracked_struct/struct_map.rs index 57c90c747..4bf982062 100644 --- a/components/salsa-2022/src/tracked_struct/struct_map.rs +++ b/components/salsa-2022/src/tracked_struct/struct_map.rs @@ -9,7 +9,6 @@ use dashmap::mapref::one::RefMut; use crate::{ alloc::Alloc, hash::{FxDashMap, FxHasher}, - plumbing::transmute_lifetime, Id, Runtime, }; diff --git a/components/salsa-2022/src/update.rs b/components/salsa-2022/src/update.rs index 5a013a86e..53b75d46b 100644 --- a/components/salsa-2022/src/update.rs +++ b/components/salsa-2022/src/update.rs @@ -23,6 +23,12 @@ pub mod helper { pub struct Dispatch(PhantomData); + impl Default for Dispatch { + fn default() -> Self { + Self::new() + } + } + impl Dispatch { pub fn new() -> Self { Dispatch(PhantomData) @@ -33,11 +39,17 @@ pub mod helper { where D: Update, { + /// # Safety + /// + /// See the `maybe_update` method in the [`Update`][] trait. pub unsafe fn maybe_update(old_pointer: *mut D, new_value: D) -> bool { unsafe { D::maybe_update(old_pointer, new_value) } } } + /// # Safety + /// + /// Impl will fulfill the postconditions of `maybe_update` pub unsafe trait Fallback { /// Same safety conditions as `Update::maybe_update` unsafe fn maybe_update(old_pointer: *mut T, new_value: T) -> bool; @@ -92,6 +104,8 @@ pub fn always_update( *old_pointer = new_value; } +/// # Safety +/// /// The `unsafe` on the trait is to assert that `maybe_update` ensures /// the properties it is intended to ensure. pub unsafe trait Update { @@ -99,7 +113,7 @@ pub unsafe trait Update { /// /// True if the value should be considered to have changed in the new revision. /// - /// # Unsafe contract + /// # Safety /// /// ## Requires /// diff --git a/salsa-2022-tests/tests/interned-struct-with-lifetime.rs b/salsa-2022-tests/tests/interned-struct-with-lifetime.rs index a8fa3e4c3..e44f498e4 100644 --- a/salsa-2022-tests/tests/interned-struct-with-lifetime.rs +++ b/salsa-2022-tests/tests/interned-struct-with-lifetime.rs @@ -23,8 +23,8 @@ struct InternedPair<'db> { #[salsa::tracked] fn intern_stuff(db: &dyn Db) -> String { - let s1 = InternedString::new(db, format!("Hello, ")); - let s2 = InternedString::new(db, format!("World, ")); + let s1 = InternedString::new(db, "Hello, ".to_string()); + let s2 = InternedString::new(db, "World, ".to_string()); let s3 = InternedPair::new(db, (s1, s2)); format!("{:?}", s3.debug(db)) } diff --git a/salsa-2022-tests/tests/preverify-struct-with-leaked-data.rs b/salsa-2022-tests/tests/preverify-struct-with-leaked-data.rs index 9365a0011..7d542a65f 100644 --- a/salsa-2022-tests/tests/preverify-struct-with-leaked-data.rs +++ b/salsa-2022-tests/tests/preverify-struct-with-leaked-data.rs @@ -9,7 +9,7 @@ use salsa_2022_tests::{HasLogger, Logger}; use test_log::test; thread_local! { - static COUNTER: Cell = Cell::new(0); + static COUNTER: Cell = const { Cell::new(0) }; } #[salsa::jar(db = Db)] diff --git a/src/lib.rs b/src/lib.rs index f5d14ea18..71d2b9461 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,9 +119,9 @@ pub struct Event { impl Event { /// Returns a type that gives a user-readable debug output. /// Use like `println!("{:?}", index.debug(db))`. - pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me + pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me where - D: plumbing::DatabaseOps, + D: ?Sized + plumbing::DatabaseOps, { EventDebug { event: self, db } } @@ -201,9 +201,9 @@ pub enum EventKind { impl EventKind { /// Returns a type that gives a user-readable debug output. /// Use like `println!("{:?}", index.debug(db))`. - pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me + pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me where - D: plumbing::DatabaseOps, + D: ?Sized + plumbing::DatabaseOps, { EventKindDebug { kind: self, db } } @@ -402,9 +402,9 @@ impl DatabaseKeyIndex { /// Returns a type that gives a user-readable debug output. /// Use like `println!("{:?}", index.debug(db))`. - pub fn debug(self, db: &D) -> impl std::fmt::Debug + '_ + pub fn debug(self, db: &D) -> impl std::fmt::Debug + '_ where - D: plumbing::DatabaseOps, + D: ?Sized + plumbing::DatabaseOps, { DatabaseKeyIndexDebug { index: self, db } } diff --git a/src/runtime.rs b/src/runtime.rs index d0b616a43..73cc14884 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -628,7 +628,7 @@ impl ActiveQuery { pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) { self.changed_at = cycle_query.changed_at; self.durability = cycle_query.durability; - self.dependencies = cycle_query.dependencies.clone(); + self.dependencies.clone_from(&cycle_query.dependencies); } }