Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion benches/accumulator.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion benches/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion benches/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion benches/incremental.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-macros/src/tracked.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use syn::spanned::Spanned;
use syn::Item;
use syn::spanned::Spanned;

use crate::token_stream_with_error;

Expand Down
2 changes: 1 addition & 1 deletion components/salsa-macros/src/tracked_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {}
}
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-macros/src/update.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
17 changes: 7 additions & 10 deletions examples/calc/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ impl<'db> Parser<'_, 'db> {
// Invoke `f` and, if it returns `None`, then restore the parsing position.
fn probe<T: std::fmt::Debug>(&mut self, f: impl FnOnce(&mut Self) -> Option<T>) -> Option<T> {
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
}
}
}

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions examples/lazy-input/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions src/accumulator/accumulated_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/active_query.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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};

Expand Down
4 changes: 3 additions & 1 deletion src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
4 changes: 2 additions & 2 deletions src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down
4 changes: 2 additions & 2 deletions src/function/backdate.rs
Original file line number Diff line number Diff line change
@@ -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<C> IngredientImpl<C>
Expand Down
2 changes: 1 addition & 1 deletion src/function/delete.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/function/diff_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C> IngredientImpl<C>
Expand Down
132 changes: 66 additions & 66 deletions src/function/eviction/lru.rs
Original file line number Diff line number Diff line change
@@ -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<NonZeroUsize>,
set: Mutex<FxLinkedHashSet<Id>>,
}
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<NonZeroUsize>,
set: Mutex<FxLinkedHashSet<Id>>,
}

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 {}
Loading
Loading