diff --git a/Cargo.toml b/Cargo.toml index 8199a35df..9aa6ea8ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -113,7 +113,7 @@ members = ["components/salsa-macro-rules", "components/salsa-macros"] [workspace.package] authors = ["Salsa developers"] -edition = "2021" +edition = "2024" license = "Apache-2.0 OR MIT" repository = "https://github.com/salsa-rs/salsa" rust-version = "1.85" diff --git a/benches/accumulator.rs b/benches/accumulator.rs index 041c1f474..f154a3943 100644 --- a/benches/accumulator.rs +++ b/benches/accumulator.rs @@ -1,6 +1,6 @@ use std::hint::black_box; -use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion}; +use codspeed_criterion_compat::{BatchSize, Criterion, criterion_group, criterion_main}; use salsa::Accumulator; #[salsa::input] diff --git a/benches/compare.rs b/benches/compare.rs index 8d9dcdad6..03fa032c0 100644 --- a/benches/compare.rs +++ b/benches/compare.rs @@ -2,7 +2,7 @@ use std::hint::black_box; use std::mem::transmute; use codspeed_criterion_compat::{ - criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, + BatchSize, BenchmarkId, Criterion, criterion_group, criterion_main, }; use salsa::Setter; diff --git a/benches/dataflow.rs b/benches/dataflow.rs index 4d18a2532..a36d1ed3d 100644 --- a/benches/dataflow.rs +++ b/benches/dataflow.rs @@ -5,7 +5,7 @@ use std::collections::BTreeSet; use std::iter::IntoIterator; -use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion}; +use codspeed_criterion_compat::{BatchSize, Criterion, criterion_group, criterion_main}; use salsa::{Database as Db, Setter}; /// A Use of a symbol. diff --git a/benches/incremental.rs b/benches/incremental.rs index 7b2d8b559..9a1ebad11 100644 --- a/benches/incremental.rs +++ b/benches/incremental.rs @@ -1,6 +1,6 @@ use std::hint::black_box; -use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion}; +use codspeed_criterion_compat::{BatchSize, Criterion, criterion_group, criterion_main}; use salsa::Setter; #[salsa::input] diff --git a/components/salsa-macros/src/tracked.rs b/components/salsa-macros/src/tracked.rs index af09197e1..d592d3245 100644 --- a/components/salsa-macros/src/tracked.rs +++ b/components/salsa-macros/src/tracked.rs @@ -1,5 +1,5 @@ -use syn::spanned::Spanned; use syn::Item; +use syn::spanned::Spanned; use crate::token_stream_with_error; diff --git a/components/salsa-macros/src/tracked_fn.rs b/components/salsa-macros/src/tracked_fn.rs index bda35e1a1..ad2d4c2fe 100644 --- a/components/salsa-macros/src/tracked_fn.rs +++ b/components/salsa-macros/src/tracked_fn.rs @@ -148,7 +148,7 @@ impl Macro { return Err(syn::Error::new_spanned( self.args.specify.as_ref().unwrap(), "only functions with a single salsa struct as their input can be specified", - )) + )); } FunctionType::SalsaStruct => {} } diff --git a/components/salsa-macros/src/update.rs b/components/salsa-macros/src/update.rs index b9d653020..e3a78ee1a 100644 --- a/components/salsa-macros/src/update.rs +++ b/components/salsa-macros/src/update.rs @@ -1,5 +1,5 @@ use proc_macro2::{Literal, Span, TokenStream}; -use syn::{parenthesized, parse::ParseStream, spanned::Spanned, Token}; +use syn::{Token, parenthesized, parse::ParseStream, spanned::Spanned}; use synstructure::BindStyle; use crate::{hygiene::Hygiene, kw}; diff --git a/examples/calc/parser.rs b/examples/calc/parser.rs index 45fafb6dd..957039cae 100644 --- a/examples/calc/parser.rs +++ b/examples/calc/parser.rs @@ -69,11 +69,12 @@ impl<'db> Parser<'_, 'db> { // Invoke `f` and, if it returns `None`, then restore the parsing position. fn probe(&mut self, f: impl FnOnce(&mut Self) -> Option) -> Option { let p = self.position; - if let Some(v) = f(self) { - Some(v) - } else { - self.position = p; - None + match f(self) { + Some(v) => Some(v), + _ => { + self.position = p; + None + } } } @@ -307,11 +308,7 @@ impl<'db> Parser<'_, 'db> { self.consume(ch); } - if s.is_empty() { - None - } else { - Some(s) - } + if s.is_empty() { None } else { Some(s) } } /// Parses a number. diff --git a/examples/lazy-input/main.rs b/examples/lazy-input/main.rs index 233d933de..0ffd3406a 100644 --- a/examples/lazy-input/main.rs +++ b/examples/lazy-input/main.rs @@ -4,12 +4,12 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex}; use std::time::Duration; -use crossbeam_channel::{unbounded, Sender}; -use dashmap::mapref::entry::Entry; +use crossbeam_channel::{Sender, unbounded}; use dashmap::DashMap; -use eyre::{eyre, Context, Report, Result}; +use dashmap::mapref::entry::Entry; +use eyre::{Context, Report, Result, eyre}; use notify_debouncer_mini::notify::{RecommendedWatcher, RecursiveMode}; -use notify_debouncer_mini::{new_debouncer, DebounceEventResult, Debouncer}; +use notify_debouncer_mini::{DebounceEventResult, Debouncer, new_debouncer}; use salsa::{Accumulator, Setter, Storage}; // ANCHOR: main diff --git a/src/accumulator/accumulated_map.rs b/src/accumulator/accumulated_map.rs index 19ad63663..d347d1b98 100644 --- a/src/accumulator/accumulated_map.rs +++ b/src/accumulator/accumulated_map.rs @@ -2,10 +2,10 @@ use std::ops; use rustc_hash::FxBuildHasher; +use crate::IngredientIndex; use crate::accumulator::accumulated::Accumulated; use crate::accumulator::{Accumulator, AnyAccumulated}; use crate::sync::atomic::{AtomicBool, Ordering}; -use crate::IngredientIndex; #[derive(Default)] pub struct AccumulatedMap { @@ -80,11 +80,7 @@ impl InputAccumulatedValues { } pub fn or_else(self, other: impl FnOnce() -> Self) -> Self { - if self.is_any() { - Self::Any - } else { - other() - } + if self.is_any() { Self::Any } else { other() } } } diff --git a/src/active_query.rs b/src/active_query.rs index 3d7ea5a27..9eaf82160 100644 --- a/src/active_query.rs +++ b/src/active_query.rs @@ -1,9 +1,10 @@ use std::{fmt, mem, ops}; +use crate::Revision; #[cfg(feature = "accumulator")] use crate::accumulator::{ - accumulated_map::{AccumulatedMap, AtomicInputAccumulatedValues, InputAccumulatedValues}, Accumulator, + accumulated_map::{AccumulatedMap, AtomicInputAccumulatedValues, InputAccumulatedValues}, }; use crate::hash::FxIndexSet; use crate::key::DatabaseKeyIndex; @@ -13,10 +14,9 @@ use crate::tracked_struct::{Disambiguator, DisambiguatorMap, IdentityHash, Ident use crate::zalsa_local::{ QueryEdge, QueryEdgeKind, QueryOrigin, QueryRevisions, QueryRevisionsExtra, }; -use crate::Revision; use crate::{ - cycle::{CycleHeads, IterationCount}, Id, + cycle::{CycleHeads, IterationCount}, }; use crate::{durability::Durability, tracked_struct::Identity}; diff --git a/src/attach.rs b/src/attach.rs index 072b82238..9a9dd0156 100644 --- a/src/attach.rs +++ b/src/attach.rs @@ -54,7 +54,9 @@ impl Attached { Some(current_db) => { let new_db = NonNull::from(db); if !std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()) { - panic!("Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}"); + panic!( + "Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}" + ); } Self { state: None } } diff --git a/src/cycle.rs b/src/cycle.rs index 461c7e010..d2ab35d0e 100644 --- a/src/cycle.rs +++ b/src/cycle.rs @@ -45,11 +45,11 @@ //! hangs (but not deadlocks). use std::iter::FusedIterator; -use thin_vec::{thin_vec, ThinVec}; +use thin_vec::{ThinVec, thin_vec}; use crate::key::DatabaseKeyIndex; -use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering}; use crate::sync::OnceLock; +use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering}; use crate::{Id, Revision}; /// The maximum number of times we'll fixpoint-iterate before panicking. diff --git a/src/event.rs b/src/event.rs index b5ff440fb..d71dc464a 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,7 +1,7 @@ +use crate::Revision; use crate::cycle::IterationCount; use crate::key::DatabaseKeyIndex; use crate::sync::thread::{self, ThreadId}; -use crate::Revision; /// The `Event` struct identifies various notable things that can /// occur during salsa execution. Instances of this struct are given diff --git a/src/function.rs b/src/function.rs index ec9f262d5..2c04f1aaa 100644 --- a/src/function.rs +++ b/src/function.rs @@ -4,8 +4,8 @@ pub(crate) use sync::{ClaimGuard, ClaimResult, Reentrancy, SyncGuard, SyncOwner, use std::any::Any; use std::fmt; use std::ptr::NonNull; -use std::sync::atomic::Ordering; use std::sync::OnceLock; +use std::sync::atomic::Ordering; use crate::cycle::{CycleRecoveryStrategy, IterationCount, ProvisionalStatus}; use crate::database::RawDatabase; @@ -16,8 +16,8 @@ use crate::key::DatabaseKeyIndex; use crate::plumbing::{self, MemoIngredientMap}; use crate::salsa_struct::SalsaStructInDb; use crate::sync::Arc; -use crate::table::memo::MemoTableTypes; use crate::table::Table; +use crate::table::memo::MemoTableTypes; use crate::views::DatabaseDownCaster; use crate::zalsa::{IngredientIndex, JarKind, MemoIngredientIndex, Zalsa}; use crate::zalsa_local::{QueryEdge, QueryOriginRef}; diff --git a/src/function/backdate.rs b/src/function/backdate.rs index 97eb626a0..74ba82c81 100644 --- a/src/function/backdate.rs +++ b/src/function/backdate.rs @@ -1,8 +1,8 @@ +use crate::Backtrace; +use crate::DatabaseKeyIndex; use crate::function::memo::Memo; use crate::function::{Configuration, IngredientImpl}; use crate::zalsa_local::QueryRevisions; -use crate::Backtrace; -use crate::DatabaseKeyIndex; use std::fmt; impl IngredientImpl diff --git a/src/function/delete.rs b/src/function/delete.rs index d061917b0..fea93ece2 100644 --- a/src/function/delete.rs +++ b/src/function/delete.rs @@ -1,7 +1,7 @@ use std::ptr::NonNull; -use crate::function::memo::Memo; use crate::function::Configuration; +use crate::function::memo::Memo; /// Stores the list of memos that have been deleted so they can be freed /// once the next revision starts. See the comment on the field diff --git a/src/function/diff_outputs.rs b/src/function/diff_outputs.rs index 37d71d41d..61a1f009c 100644 --- a/src/function/diff_outputs.rs +++ b/src/function/diff_outputs.rs @@ -3,7 +3,7 @@ use crate::function::memo::Memo; use crate::function::{Configuration, IngredientImpl}; use crate::hash::FxIndexSet; use crate::zalsa::Zalsa; -use crate::zalsa_local::{output_edges, QueryOriginRef, QueryRevisions}; +use crate::zalsa_local::{QueryOriginRef, QueryRevisions, output_edges}; use crate::{DatabaseKeyIndex, Event, EventKind}; impl IngredientImpl diff --git a/src/function/eviction/lru.rs b/src/function/eviction/lru.rs index 8fa0b1cfc..66e589848 100644 --- a/src/function/eviction/lru.rs +++ b/src/function/eviction/lru.rs @@ -1,66 +1,66 @@ -//! Least Recently Used (LRU) eviction policy. -//! -//! This policy tracks the most recently accessed items and evicts -//! the least recently used ones when the cache exceeds its capacity. - -use std::num::NonZeroUsize; - -use crate::hash::FxLinkedHashSet; -use crate::sync::Mutex; -use crate::Id; - -use super::{EvictionPolicy, HasCapacity}; - -/// Least Recently Used eviction policy. -/// -/// When the number of memoized values exceeds the configured capacity, -/// the least recently accessed values are evicted at the start of each -/// new revision. -pub struct Lru { - capacity: Option, - set: Mutex>, -} - -impl Lru { - #[inline(never)] - fn insert(&self, id: Id) { - self.set.lock().insert(id); - } -} - -impl EvictionPolicy for Lru { - fn new(cap: usize) -> Self { - Self { - capacity: NonZeroUsize::new(cap), - set: Mutex::default(), - } - } - - #[inline(always)] - fn record_use(&self, id: Id) { - if self.capacity.is_some() { - self.insert(id); - } - } - - fn set_capacity(&mut self, capacity: usize) { - self.capacity = NonZeroUsize::new(capacity); - if self.capacity.is_none() { - self.set.get_mut().clear(); - } - } - - fn for_each_evicted(&mut self, mut cb: impl FnMut(Id)) { - let Some(cap) = self.capacity else { - return; - }; - let set = self.set.get_mut(); - while set.len() > cap.get() { - if let Some(id) = set.pop_front() { - cb(id); - } - } - } -} - -impl HasCapacity for Lru {} +//! Least Recently Used (LRU) eviction policy. +//! +//! This policy tracks the most recently accessed items and evicts +//! the least recently used ones when the cache exceeds its capacity. + +use std::num::NonZeroUsize; + +use crate::Id; +use crate::hash::FxLinkedHashSet; +use crate::sync::Mutex; + +use super::{EvictionPolicy, HasCapacity}; + +/// Least Recently Used eviction policy. +/// +/// When the number of memoized values exceeds the configured capacity, +/// the least recently accessed values are evicted at the start of each +/// new revision. +pub struct Lru { + capacity: Option, + set: Mutex>, +} + +impl Lru { + #[inline(never)] + fn insert(&self, id: Id) { + self.set.lock().insert(id); + } +} + +impl EvictionPolicy for Lru { + fn new(cap: usize) -> Self { + Self { + capacity: NonZeroUsize::new(cap), + set: Mutex::default(), + } + } + + #[inline(always)] + fn record_use(&self, id: Id) { + if self.capacity.is_some() { + self.insert(id); + } + } + + fn set_capacity(&mut self, capacity: usize) { + self.capacity = NonZeroUsize::new(capacity); + if self.capacity.is_none() { + self.set.get_mut().clear(); + } + } + + fn for_each_evicted(&mut self, mut cb: impl FnMut(Id)) { + let Some(cap) = self.capacity else { + return; + }; + let set = self.set.get_mut(); + while set.len() > cap.get() { + if let Some(id) = set.pop_front() { + cb(id); + } + } + } +} + +impl HasCapacity for Lru {} diff --git a/src/function/eviction/noop.rs b/src/function/eviction/noop.rs index f80fbaab9..ea9046882 100644 --- a/src/function/eviction/noop.rs +++ b/src/function/eviction/noop.rs @@ -1,23 +1,23 @@ -//! No-op eviction policy - cache grows unbounded. -//! -//! This is the default eviction policy when no LRU capacity is specified. - -use crate::{function::EvictionPolicy, Id}; - -/// No eviction - cache grows unbounded. -pub struct NoopEviction; - -impl EvictionPolicy for NoopEviction { - fn new(_cap: usize) -> Self { - Self - } - - #[inline(always)] - fn record_use(&self, _id: Id) {} - - #[inline(always)] - fn set_capacity(&mut self, _capacity: usize) {} - - #[inline(always)] - fn for_each_evicted(&mut self, _cb: impl FnMut(Id)) {} -} +//! No-op eviction policy - cache grows unbounded. +//! +//! This is the default eviction policy when no LRU capacity is specified. + +use crate::{Id, function::EvictionPolicy}; + +/// No eviction - cache grows unbounded. +pub struct NoopEviction; + +impl EvictionPolicy for NoopEviction { + fn new(_cap: usize) -> Self { + Self + } + + #[inline(always)] + fn record_use(&self, _id: Id) {} + + #[inline(always)] + fn set_capacity(&mut self, _capacity: usize) {} + + #[inline(always)] + fn for_each_evicted(&mut self, _cb: impl FnMut(Id)) {} +} diff --git a/src/function/execute.rs b/src/function/execute.rs index 5686a622e..1cd7fa79f 100644 --- a/src/function/execute.rs +++ b/src/function/execute.rs @@ -12,7 +12,7 @@ use crate::sync::thread; use crate::tracked_struct::Identity; use crate::zalsa::{MemoIngredientIndex, Zalsa}; use crate::zalsa_local::{ActiveQueryGuard, QueryEdge, QueryEdgeKind, QueryRevisions}; -use crate::{tracing, Cancelled, Cycle}; +use crate::{Cancelled, Cycle, tracing}; use crate::{DatabaseKeyIndex, Event, EventKind, Id}; impl IngredientImpl @@ -111,11 +111,7 @@ where memo_ingredient_index, ); - if claim_guard.drop() { - None - } else { - Some(memo) - } + if claim_guard.drop() { None } else { Some(memo) } } fn execute_maybe_iterate<'db>( @@ -150,7 +146,9 @@ where // b) It's guaranteed that this query will panic again anyway. // That's why we simply propagate the panic here. It simplifies our lives and it also avoids duplicate panic messages. if old_memo.value.is_none() { - tracing::warn!("Propagating panic for cycle head that panicked in an earlier execution in that revision"); + tracing::warn!( + "Propagating panic for cycle head that panicked in an earlier execution in that revision" + ); Cancelled::PropagatedPanic.throw(); } @@ -228,7 +226,9 @@ where // If not, return because this query is not a cycle head. if !depends_on_self { let Some(outer_cycle) = outer_cycle else { - panic!("cycle participant with non-empty cycle heads and that doesn't depend on itself must have an outer cycle responsible to finalize the query later (query: {database_key_index:?}, cycle heads: {cycle_heads:?})."); + panic!( + "cycle participant with non-empty cycle heads and that doesn't depend on itself must have an outer cycle responsible to finalize the query later (query: {database_key_index:?}, cycle heads: {cycle_heads:?})." + ); }; // For FallbackImmediate, use the fallback value instead of the computed value @@ -780,7 +780,10 @@ fn assert_no_new_cycle_heads( ) { for head in new_cycle_heads { if !cycle_heads.contains(&head.database_key_index) { - panic!("Cycle recovery function for {me:?} introduced a cycle, depending on {:?}. This is not allowed.", head.database_key_index); + panic!( + "Cycle recovery function for {me:?} introduced a cycle, depending on {:?}. This is not allowed.", + head.database_key_index + ); } } } diff --git a/src/function/inputs.rs b/src/function/inputs.rs index 78b1adb36..2f3944cb9 100644 --- a/src/function/inputs.rs +++ b/src/function/inputs.rs @@ -1,7 +1,7 @@ +use crate::Id; use crate::function::{Configuration, IngredientImpl}; use crate::zalsa::Zalsa; use crate::zalsa_local::QueryOriginRef; -use crate::Id; impl IngredientImpl where diff --git a/src/function/maybe_changed_after.rs b/src/function/maybe_changed_after.rs index 1741d99e6..e6ea963eb 100644 --- a/src/function/maybe_changed_after.rs +++ b/src/function/maybe_changed_after.rs @@ -150,7 +150,7 @@ where zalsa_local, database_key_index, C::CYCLE_STRATEGY, - )) + )); } }; // Load the current memo, if any. diff --git a/src/function/memo.rs b/src/function/memo.rs index ef73a4a6a..d6a45d143 100644 --- a/src/function/memo.rs +++ b/src/function/memo.rs @@ -4,7 +4,7 @@ use std::mem::transmute; use std::ptr::NonNull; use crate::cycle::{ - empty_cycle_heads, CycleHeads, CycleHeadsIterator, IterationCount, ProvisionalStatus, + CycleHeads, CycleHeadsIterator, IterationCount, ProvisionalStatus, empty_cycle_heads, }; use crate::function::{Configuration, IngredientImpl}; use crate::ingredient::WaitForResult; @@ -235,14 +235,14 @@ where #[cfg(feature = "persistence")] mod persistence { - use crate::function::memo::Memo; use crate::function::Configuration; + use crate::function::memo::Memo; use crate::revision::AtomicRevision; use crate::zalsa_local::persistence::MappedQueryRevisions; use crate::zalsa_local::{QueryOrigin, QueryRevisions}; - use serde::ser::SerializeStruct; use serde::Deserialize; + use serde::ser::SerializeStruct; /// A reference to the fields of a [`Memo`], with its [`QueryRevisions`] transformed. pub(crate) struct MappedMemo<'memo, 'db, C: Configuration> { diff --git a/src/function/sync.rs b/src/function/sync.rs index f01932a37..0dfceca85 100644 --- a/src/function/sync.rs +++ b/src/function/sync.rs @@ -6,8 +6,8 @@ use crate::plumbing::ZalsaLocal; use crate::runtime::{ BlockOnTransferredOwner, BlockResult, BlockTransferredResult, Running, WaitResult, }; -use crate::sync::thread::{self}; use crate::sync::Mutex; +use crate::sync::thread::{self}; use crate::tracing; use crate::zalsa::Zalsa; use crate::{Id, IngredientIndex}; @@ -90,7 +90,7 @@ impl SyncTable { BlockResult::Cycle => ClaimResult::Cycle { inner: false }, BlockResult::Running(running) => ClaimResult::Running(running), }, - } + }; } }; @@ -149,7 +149,7 @@ impl SyncTable { BlockResult::Cycle => ClaimResult::Cycle { inner: false }, BlockResult::Running(running) => ClaimResult::Running(running), }, - } + }; } }; diff --git a/src/ingredient.rs b/src/ingredient.rs index 9e9fec6a1..c792dc9d9 100644 --- a/src/ingredient.rs +++ b/src/ingredient.rs @@ -7,9 +7,9 @@ use crate::function::VerifyResult; use crate::hash::{FxHashSet, FxIndexSet}; use crate::runtime::Running; use crate::sync::Arc; -use crate::table::memo::MemoTableTypes; use crate::table::Table; -use crate::zalsa::{transmute_data_mut_ptr, transmute_data_ptr, IngredientIndex, JarKind, Zalsa}; +use crate::table::memo::MemoTableTypes; +use crate::zalsa::{IngredientIndex, JarKind, Zalsa, transmute_data_mut_ptr, transmute_data_ptr}; use crate::zalsa_local::{QueryEdge, QueryOriginRef}; use crate::{DatabaseKeyIndex, Id, Revision}; @@ -78,7 +78,9 @@ pub trait Ingredient: Any + fmt::Debug + Send + Sync { _zalsa: &'db Zalsa, _input: Id, ) -> Option> { - unreachable!("provisional_status should only be called on cycle heads and only functions can be cycle heads"); + unreachable!( + "provisional_status should only be called on cycle heads and only functions can be cycle heads" + ); } /// Invoked when the current thread needs to wait for a result for the given `key_index`. @@ -163,7 +165,9 @@ pub trait Ingredient: Any + fmt::Debug + Send + Sync { /// /// Returns `false` if the Memo doesn't exist or if called on a non-cycle head. fn cycle_converged(&self, _zalsa: &Zalsa, _input: Id) -> bool { - unreachable!("cycle_converged should only be called on cycle heads and only functions can be cycle heads"); + unreachable!( + "cycle_converged should only be called on cycle heads and only functions can be cycle heads" + ); } /// Updates the iteration count for the (nested) cycle head `_input` to `iteration_count`. @@ -175,11 +179,15 @@ pub trait Ingredient: Any + fmt::Debug + Send + Sync { _input: Id, _iteration_count: IterationCount, ) { - unreachable!("increment_iteration_count should only be called on cycle heads and only functions can be cycle heads"); + unreachable!( + "increment_iteration_count should only be called on cycle heads and only functions can be cycle heads" + ); } fn finalize_cycle_head(&self, _zalsa: &Zalsa, _input: Id) { - unreachable!("finalize_cycle_head should only be called on cycle heads and only functions can be cycle heads"); + unreachable!( + "finalize_cycle_head should only be called on cycle heads and only functions can be cycle heads" + ); } /// Flattens the dependencies of a query with cycle handling that participates in a cycle. diff --git a/src/ingredient_cache.rs b/src/ingredient_cache.rs index 6e36c2cff..a6e8a1243 100644 --- a/src/ingredient_cache.rs +++ b/src/ingredient_cache.rs @@ -2,10 +2,10 @@ pub use imp::IngredientCache; #[cfg(feature = "inventory")] mod imp { + use crate::IngredientIndex; use crate::plumbing::Ingredient; use crate::sync::atomic::{self, AtomicU32, Ordering}; use crate::zalsa::Zalsa; - use crate::IngredientIndex; use std::marker::PhantomData; @@ -99,11 +99,11 @@ mod imp { #[cfg(not(feature = "inventory"))] mod imp { + use crate::IngredientIndex; use crate::nonce::Nonce; use crate::plumbing::Ingredient; use crate::sync::atomic::{AtomicU64, Ordering}; use crate::zalsa::{StorageNonce, Zalsa}; - use crate::IngredientIndex; use std::marker::PhantomData; use std::mem; diff --git a/src/input.rs b/src/input.rs index 7f5ead361..753ebb193 100644 --- a/src/input.rs +++ b/src/input.rs @@ -483,14 +483,14 @@ mod persistence { use std::fmt; use serde::ser::{SerializeMap, SerializeStruct}; - use serde::{de, Deserialize}; + use serde::{Deserialize, de}; use super::{Configuration, IngredientImpl, Value}; + use crate::Id; use crate::input::singleton::SingletonChoice; use crate::plumbing::Ingredient; use crate::table::memo::MemoTable; use crate::zalsa::Zalsa; - use crate::Id; pub struct SerializeIngredient<'db, C> where diff --git a/src/input/singleton.rs b/src/input/singleton.rs index c069a7fd1..a3ee8b93e 100644 --- a/src/input/singleton.rs +++ b/src/input/singleton.rs @@ -1,5 +1,5 @@ -use crate::sync::atomic::{AtomicU64, Ordering}; use crate::Id; +use crate::sync::atomic::{AtomicU64, Ordering}; mod sealed { pub trait Sealed {} diff --git a/src/interned.rs b/src/interned.rs index f959bcd24..575cb2e9b 100644 --- a/src/interned.rs +++ b/src/interned.rs @@ -8,7 +8,7 @@ use std::num::NonZeroUsize; use std::path::{Path, PathBuf}; use crossbeam_utils::CachePadded; -use intrusive_collections::{intrusive_adapter, LinkedList, LinkedListLink, UnsafeRef}; +use intrusive_collections::{LinkedList, LinkedListLink, UnsafeRef, intrusive_adapter}; use rustc_hash::FxBuildHasher; use crate::durability::Durability; @@ -19,8 +19,8 @@ use crate::ingredient::Ingredient; use crate::plumbing::{self, Jar, ZalsaLocal}; use crate::revision::AtomicRevision; use crate::sync::{Arc, Mutex, OnceLock}; -use crate::table::memo::{MemoTable, MemoTableTypes, MemoTableWithTypesMut}; use crate::table::Slot; +use crate::table::memo::{MemoTable, MemoTableTypes, MemoTableWithTypesMut}; use crate::zalsa::{IngredientIndex, JarKind, Zalsa}; use crate::zalsa_local::QueryEdge; use crate::{DatabaseKeyIndex, Event, EventKind, Id, Revision}; @@ -1478,7 +1478,7 @@ mod persistence { use intrusive_collections::LinkedListLink; use serde::ser::{SerializeMap, SerializeStruct}; - use serde::{de, Deserialize}; + use serde::{Deserialize, de}; use super::{Configuration, IngredientImpl, Value, ValueShared}; use crate::plumbing::Ingredient; diff --git a/src/key.rs b/src/key.rs index d1188b912..00a7611f4 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,8 +1,8 @@ use std::fmt; +use crate::Id; use crate::function::VerifyResult; use crate::zalsa::{IngredientIndex, Zalsa}; -use crate::Id; // ANCHOR: DatabaseKeyIndex /// An integer that uniquely identifies a particular query instance within the diff --git a/src/lib.rs b/src/lib.rs index 8d2fd379a..b2fffd91f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ mod zalsa_local; mod nonce; #[cfg(feature = "macros")] -pub use salsa_macros::{accumulator, db, input, interned, tracked, Supertype, Update}; +pub use salsa_macros::{Supertype, Update, accumulator, db, input, interned, tracked}; #[cfg(feature = "salsa_unstable")] pub use self::database::IngredientInfo; @@ -96,7 +96,7 @@ pub mod plumbing { pub use crate::accumulator::Accumulator; pub use crate::attach::{attach, with_attached_database}; pub use crate::cycle::CycleRecoveryStrategy; - pub use crate::database::{current_revision, Database}; + pub use crate::database::{Database, current_revision}; pub use crate::durability::Durability; pub use crate::id::{AsId, FromId, FromIdWithDb, Id}; pub use crate::ingredient::{Ingredient, Jar, Location}; @@ -108,17 +108,17 @@ pub mod plumbing { NewMemoIngredientIndices, }; pub use crate::revision::{AtomicRevision, Revision}; - pub use crate::runtime::{stamp, Runtime, Stamp}; + pub use crate::runtime::{Runtime, Stamp, stamp}; pub use crate::salsa_struct::SalsaStructInDb; pub use crate::storage::{HasStorage, Storage}; pub use crate::table::memo::MemoTableWithTypes; pub use crate::tracked_struct::TrackedStructInDb; pub use crate::update::helper::{Dispatch as UpdateDispatch, Fallback as UpdateFallback}; - pub use crate::update::{always_update, Update}; + pub use crate::update::{Update, always_update}; pub use crate::views::DatabaseDownCaster; pub use crate::zalsa::{ - register_jar, transmute_data_ptr, views, ErasedJar, HasJar, IngredientIndex, JarKind, - Zalsa, ZalsaDatabase, + ErasedJar, HasJar, IngredientIndex, JarKind, Zalsa, ZalsaDatabase, register_jar, + transmute_data_ptr, views, }; pub use crate::zalsa_local::ZalsaLocal; diff --git a/src/runtime.rs b/src/runtime.rs index 5b36bf205..4ec8fee03 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -2,9 +2,9 @@ use self::dependency_graph::DependencyGraph; use crate::durability::Durability; use crate::function::{SyncGuard, SyncOwner}; use crate::key::DatabaseKeyIndex; +use crate::sync::Mutex; use crate::sync::atomic::{AtomicBool, Ordering}; use crate::sync::thread::{self, ThreadId}; -use crate::sync::Mutex; use crate::table::Table; use crate::zalsa::Zalsa; use crate::{Cancelled, Event, EventKind, Revision}; @@ -296,7 +296,9 @@ impl Runtime { let dg = self.dependency_graph.lock(); if dg.depends_on(other_id, thread_id) { - crate::tracing::debug!("block_on: cycle detected for {database_key:?} in thread {thread_id:?} on {other_id:?}"); + crate::tracing::debug!( + "block_on: cycle detected for {database_key:?} in thread {thread_id:?} on {other_id:?}" + ); return BlockResult::Cycle; } diff --git a/src/runtime/dependency_graph.rs b/src/runtime/dependency_graph.rs index 9b8cbe221..e2bf2c8a6 100644 --- a/src/runtime/dependency_graph.rs +++ b/src/runtime/dependency_graph.rs @@ -5,10 +5,10 @@ use smallvec::SmallVec; use crate::function::{SyncGuard, SyncOwner}; use crate::key::DatabaseKeyIndex; -use crate::runtime::dependency_graph::edge::EdgeCondvar; use crate::runtime::WaitResult; -use crate::sync::thread::ThreadId; +use crate::runtime::dependency_graph::edge::EdgeCondvar; use crate::sync::MutexGuard; +use crate::sync::thread::ThreadId; use crate::tracing; type QueryDependents = FxHashMap>; diff --git a/src/table/memo.rs b/src/table/memo.rs index dd0d71e58..cb1b79147 100644 --- a/src/table/memo.rs +++ b/src/table/memo.rs @@ -3,10 +3,10 @@ use std::fmt::Debug; use std::mem; use std::ptr::{self, NonNull}; +use crate::DatabaseKeyIndex; use crate::sync::atomic::{AtomicPtr, Ordering}; use crate::zalsa::MemoIngredientIndex; use crate::zalsa::Zalsa; -use crate::DatabaseKeyIndex; /// The "memo table" stores the memoized results of tracked function calls. /// Every tracked function must take a salsa struct as its first argument diff --git a/src/tracked_struct.rs b/src/tracked_struct.rs index 5a67e5a7b..344dc84e6 100644 --- a/src/tracked_struct.rs +++ b/src/tracked_struct.rs @@ -790,14 +790,14 @@ where // We want to set `updated_at` to `None`, signalling that other field values // cannot be read. The current value should be `Some(R0)` for some older revision. - match unsafe { (*data).updated_at.swap(None) }{ + match unsafe { (*data).updated_at.swap(None) } { None => { panic!("cannot delete write-locked id `{id:?}`; value leaked across threads"); } Some(r) if r == zalsa.current_revision() => panic!( "cannot delete read-locked id `{id:?}`; value leaked across threads or user functions not deterministic" ), - Some(_) => () + Some(_) => (), } // SAFETY: We have acquired the write lock by swapping `None` into `updated_at` @@ -1288,7 +1288,7 @@ mod persistence { use std::fmt; use serde::ser::{SerializeMap, SerializeStruct}; - use serde::{de, Deserialize}; + use serde::{Deserialize, de}; use super::{Configuration, IngredientImpl, Value}; use crate::plumbing::Ingredient; diff --git a/src/update.rs b/src/update.rs index 2dd2d4561..2f402a88b 100644 --- a/src/update.rs +++ b/src/update.rs @@ -27,7 +27,7 @@ use crate::sync::Arc; pub mod helper { use std::marker::PhantomData; - use super::{update_fallback, Update}; + use super::{Update, update_fallback}; pub struct Dispatch(PhantomData); diff --git a/src/views.rs b/src/views.rs index d58f349f0..48fad6e04 100644 --- a/src/views.rs +++ b/src/views.rs @@ -5,7 +5,7 @@ use std::{ ptr::NonNull, }; -use crate::{database::RawDatabase, Database}; +use crate::{Database, database::RawDatabase}; /// A `Views` struct is associated with some specific database type /// (a `DatabaseImpl` for some existential `U`). It contains functions diff --git a/src/zalsa.rs b/src/zalsa.rs index 9686a6d32..e68f4e7fb 100644 --- a/src/zalsa.rs +++ b/src/zalsa.rs @@ -9,8 +9,8 @@ use crate::hash::TypeIdHasher; use crate::ingredient::{Ingredient, Jar}; use crate::plumbing::SalsaStructInDb; use crate::runtime::Runtime; -use crate::table::memo::MemoTableWithTypes; use crate::table::Table; +use crate::table::memo::MemoTableWithTypes; use crate::views::Views; use crate::zalsa_local::ZalsaLocal; use crate::{Database, Durability, Id, Revision}; diff --git a/src/zalsa_local.rs b/src/zalsa_local.rs index 1f3399fda..466df5881 100644 --- a/src/zalsa_local.rs +++ b/src/zalsa_local.rs @@ -3,19 +3,19 @@ use std::fmt; use std::fmt::Formatter; use std::panic::UnwindSafe; use std::ptr::{self, NonNull}; -use std::sync::atomic::{AtomicU8, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicU8, Ordering}; use rustc_hash::FxHashMap; use thin_vec::ThinVec; #[cfg(feature = "accumulator")] use crate::accumulator::{ - accumulated_map::{AccumulatedMap, AtomicInputAccumulatedValues}, Accumulator, + accumulated_map::{AccumulatedMap, AtomicInputAccumulatedValues}, }; use crate::active_query::{CompletedQuery, QueryStack}; -use crate::cycle::{empty_cycle_heads, AtomicIterationCount, CycleHeads, IterationCount}; +use crate::cycle::{AtomicIterationCount, CycleHeads, IterationCount, empty_cycle_heads}; use crate::durability::Durability; use crate::key::DatabaseKeyIndex; use crate::runtime::Stamp; diff --git a/tests/accumulate-reuse-workaround.rs b/tests/accumulate-reuse-workaround.rs index db26b7e3c..3bbd85f8d 100644 --- a/tests/accumulate-reuse-workaround.rs +++ b/tests/accumulate-reuse-workaround.rs @@ -27,16 +27,13 @@ fn compute(db: &dyn LogDatabase, input: List) -> u32 { // always pushes 0 Integers(0).accumulate(db); - let result = if let Some(next) = input.next(db) { + // return value changes + if let Some(next) = input.next(db) { let next_integers = accumulated(db, next); - let v = input.value(db) + next_integers.iter().sum::(); - v + input.value(db) + next_integers.iter().sum::() } else { input.value(db) - }; - - // return value changes - result + } } #[salsa::tracked(returns(ref))] diff --git a/tests/accumulate-reuse.rs b/tests/accumulate-reuse.rs index 6b63e2de9..7c24412c8 100644 --- a/tests/accumulate-reuse.rs +++ b/tests/accumulate-reuse.rs @@ -27,16 +27,13 @@ fn compute(db: &dyn LogDatabase, input: List) -> u32 { // always pushes 0 Integers(0).accumulate(db); - let result = if let Some(next) = input.next(db) { + // return value changes + if let Some(next) = input.next(db) { let next_integers = compute::accumulated::(db, next); - let v = input.value(db) + next_integers.iter().map(|i| i.0).sum::(); - v + input.value(db) + next_integers.iter().map(|i| i.0).sum::() } else { input.value(db) - }; - - // return value changes - result + } } #[test] diff --git a/tests/cycle_initial_call_back_into_cycle.rs b/tests/cycle_initial_call_back_into_cycle.rs index ab7a473a2..03bc02d9b 100644 --- a/tests/cycle_initial_call_back_into_cycle.rs +++ b/tests/cycle_initial_call_back_into_cycle.rs @@ -10,11 +10,7 @@ fn initial_value(db: &dyn salsa::Database) -> u32 { #[salsa::tracked(cycle_initial=cycle_initial)] fn query(db: &dyn salsa::Database) -> u32 { let val = query(db); - if val < 5 { - val + 1 - } else { - val - } + if val < 5 { val + 1 } else { val } } fn cycle_initial(db: &dyn salsa::Database, _id: salsa::Id) -> u32 { diff --git a/tests/cycle_initial_call_query.rs b/tests/cycle_initial_call_query.rs index 92540f3a3..f608face5 100644 --- a/tests/cycle_initial_call_query.rs +++ b/tests/cycle_initial_call_query.rs @@ -10,11 +10,7 @@ fn initial_value(_db: &dyn salsa::Database) -> u32 { #[salsa::tracked(cycle_initial= |db, _| initial_value(db))] fn query(db: &dyn salsa::Database) -> u32 { let val = query(db); - if val < 5 { - val + 1 - } else { - val - } + if val < 5 { val + 1 } else { val } } #[test_log::test] diff --git a/tests/cycle_nested_converges_never.rs b/tests/cycle_nested_converges_never.rs index 0738d5905..85152b208 100644 --- a/tests/cycle_nested_converges_never.rs +++ b/tests/cycle_nested_converges_never.rs @@ -25,11 +25,7 @@ fn query_a(db: &dyn salsa::Database) -> CycleValue { let b = query_b(db); tracing::info!("query_b: {b:?}"); - if b < CycleValue(1) { - query_c(db) - } else { - b - } + if b < CycleValue(1) { query_c(db) } else { b } } #[salsa::tracked(cycle_initial=initial)] diff --git a/tests/cycle_output.rs b/tests/cycle_output.rs index 06bcea373..966a0d7d5 100644 --- a/tests/cycle_output.rs +++ b/tests/cycle_output.rs @@ -28,11 +28,7 @@ fn query_a(db: &dyn Db, input: InputValue) -> u32 { let read = read_value(db, output); assert_eq!(read, val); query_d(db); - if val > 2 { - val - } else { - val + input.value(db) - } + if val > 2 { val } else { val + input.value(db) } } #[salsa::tracked(cycle_initial=cycle_initial)] diff --git a/tests/cycle_recovery_call_back_into_cycle.rs b/tests/cycle_recovery_call_back_into_cycle.rs index c0bbf00c1..2b7334b1d 100644 --- a/tests/cycle_recovery_call_back_into_cycle.rs +++ b/tests/cycle_recovery_call_back_into_cycle.rs @@ -14,11 +14,7 @@ fn fallback_value(db: &dyn ValueDatabase) -> u32 { #[salsa::tracked(cycle_fn=cycle_fn, cycle_initial=cycle_initial)] fn query(db: &dyn ValueDatabase) -> u32 { let val = query(db); - if val < 5 { - val + 1 - } else { - val - } + if val < 5 { val + 1 } else { val } } fn cycle_initial(_db: &dyn ValueDatabase, _id: salsa::Id) -> u32 { diff --git a/tests/cycle_recovery_call_query.rs b/tests/cycle_recovery_call_query.rs index 40ad279f7..1e1d71bc1 100644 --- a/tests/cycle_recovery_call_query.rs +++ b/tests/cycle_recovery_call_query.rs @@ -10,11 +10,7 @@ fn fallback_value(_db: &dyn salsa::Database) -> u32 { #[salsa::tracked(cycle_fn = |db, _, _, _| fallback_value(db), cycle_initial = |_, _| 0)] fn query(db: &dyn salsa::Database) -> u32 { let val = query(db); - if val < 5 { - val + 1 - } else { - val - } + if val < 5 { val + 1 } else { val } } #[test_log::test] diff --git a/tests/cycle_recovery_dependencies.rs b/tests/cycle_recovery_dependencies.rs index 2d17703eb..d1eb320c1 100644 --- a/tests/cycle_recovery_dependencies.rs +++ b/tests/cycle_recovery_dependencies.rs @@ -24,11 +24,7 @@ fn entry(db: &dyn salsa::Database, input: Input) -> u32 { #[salsa::tracked(cycle_fn=cycle_fn, cycle_initial=cycle_initial)] fn query(db: &dyn salsa::Database, input: Input) -> u32 { let val = query(db, input); - if val < 5 { - val + 1 - } else { - val - } + if val < 5 { val + 1 } else { val } } fn cycle_initial(_db: &dyn salsa::Database, _id: salsa::Id, _input: Input) -> u32 { diff --git a/tests/cycle_regression_455.rs b/tests/cycle_regression_455.rs index 2957e5284..15d9b1119 100644 --- a/tests/cycle_regression_455.rs +++ b/tests/cycle_regression_455.rs @@ -20,11 +20,7 @@ fn cycle_initial(_db: &dyn Database, _id: salsa::Id, _input: MyTracked) -> u32 { fn memoized_b<'db>(db: &'db dyn Database, tracked: MyTracked<'db>) -> u32 { let incr = tracked.field(db); let a = memoized_a(db, tracked); - if a > 8 { - a - } else { - a + incr - } + if a > 8 { a } else { a + incr } } #[salsa::input] diff --git a/tests/lru.rs b/tests/lru.rs index 1d417267a..59fc2c285 100644 --- a/tests/lru.rs +++ b/tests/lru.rs @@ -3,8 +3,8 @@ //! Test that a `tracked` fn with lru options //! compiles and executes successfully. -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; mod common; use common::LogDatabase; diff --git a/tests/parallel/cycle_a_t1_b_t2_fallback.rs b/tests/parallel/cycle_a_t1_b_t2_fallback.rs index b49fa0448..6c19819bb 100644 --- a/tests/parallel/cycle_a_t1_b_t2_fallback.rs +++ b/tests/parallel/cycle_a_t1_b_t2_fallback.rs @@ -51,8 +51,8 @@ fn cycle_result_b(_db: &dyn KnobsDatabase, _id: salsa::Id) -> u32 { #[test_log::test] fn the_test() { - use crate::sync::thread; use crate::Knobs; + use crate::sync::thread; crate::sync::check(|| { tracing::debug!("Starting new run"); diff --git a/tests/parallel/setup.rs b/tests/parallel/setup.rs index b36160c78..7fc10c06b 100644 --- a/tests/parallel/setup.rs +++ b/tests/parallel/setup.rs @@ -3,8 +3,8 @@ use salsa::{Database, Storage}; use super::signal::Signal; -use super::sync::atomic::{AtomicUsize, Ordering}; use super::sync::Arc; +use super::sync::atomic::{AtomicUsize, Ordering}; /// Various "knobs" and utilities used by tests to force /// a certain behavior. diff --git a/tests/tracked_with_struct_db.rs b/tests/tracked_with_struct_db.rs index 323f9facf..a253d7af0 100644 --- a/tests/tracked_with_struct_db.rs +++ b/tests/tracked_with_struct_db.rs @@ -28,8 +28,7 @@ enum MyList<'db> { #[salsa::tracked] fn create_tracked_list(db: &dyn Database, input: MyInput) -> MyTracked<'_> { let t0 = MyTracked::new(db, input, MyList::None); - let t1 = MyTracked::new(db, input, MyList::Next(t0)); - t1 + MyTracked::new(db, input, MyList::Next(t0)) } #[test]