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
5 changes: 3 additions & 2 deletions benches/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
//!
//! This benchmark simulates a (very simplified) version of a real dataflow analysis using fixpoint
//! iteration.
use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion};
use salsa::{CycleRecoveryAction, Database as Db, Setter};
use std::collections::BTreeSet;
use std::iter::IntoIterator;

use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion};
use salsa::{CycleRecoveryAction, Database as Db, Setter};

include!("shims/global_alloc_overwrite.rs");

/// A Use of a symbol.
Expand Down
8 changes: 3 additions & 5 deletions components/salsa-macros/src/accumulator.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use proc_macro2::TokenStream;

use crate::{
hygiene::Hygiene,
options::{AllowedOptions, Options},
token_stream_with_error,
};
use crate::hygiene::Hygiene;
use crate::options::{AllowedOptions, Options};
use crate::token_stream_with_error;

// #[salsa::accumulator(jar = Jar0)]
// struct Accumulator(DataType);
Expand Down
3 changes: 2 additions & 1 deletion components/salsa-macros/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use proc_macro2::TokenStream;
use syn::parse::Nothing;

use crate::{hygiene::Hygiene, token_stream_with_error};
use crate::hygiene::Hygiene;
use crate::token_stream_with_error;

// Source:
//
Expand Down
3 changes: 2 additions & 1 deletion components/salsa-macros/src/fn_util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{hygiene::Hygiene, xform::ChangeLt};
use crate::hygiene::Hygiene;
use crate::xform::ChangeLt;

/// Returns a vector of ids representing the function arguments.
/// Prefers to reuse the names given by the user, if possible.
Expand Down
11 changes: 5 additions & 6 deletions components/salsa-macros/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{
hygiene::Hygiene,
options::Options,
salsa_struct::{SalsaStruct, SalsaStructAllowedOptions},
token_stream_with_error,
};
use proc_macro2::TokenStream;

use crate::hygiene::Hygiene;
use crate::options::Options;
use crate::salsa_struct::{SalsaStruct, SalsaStructAllowedOptions};
use crate::token_stream_with_error;

/// For an entity struct `Foo` with fields `f1: T1, ..., fN: TN`, we generate...
///
/// * the "id struct" `struct Foo(salsa::Id)`
Expand Down
12 changes: 5 additions & 7 deletions components/salsa-macros/src/interned.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{
db_lifetime,
hygiene::Hygiene,
options::Options,
salsa_struct::{SalsaStruct, SalsaStructAllowedOptions},
token_stream_with_error,
};
use proc_macro2::TokenStream;

use crate::hygiene::Hygiene;
use crate::options::Options;
use crate::salsa_struct::{SalsaStruct, SalsaStructAllowedOptions};
use crate::{db_lifetime, token_stream_with_error};

/// For an entity struct `Foo` with fields `f1: T1, ..., fN: TN`, we generate...
///
/// * the "id struct" `struct Foo(salsa::Id)`
Expand Down
3 changes: 2 additions & 1 deletion components/salsa-macros/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::marker::PhantomData;

use syn::{ext::IdentExt, spanned::Spanned};
use syn::ext::IdentExt;
use syn::spanned::Spanned;

/// "Options" are flags that can be supplied to the various salsa related
/// macros. They are listed like `(ref, no_eq, foo=bar)` etc. The commas
Expand Down
7 changes: 3 additions & 4 deletions components/salsa-macros/src/salsa_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
//! * data method `impl Foo { fn data(&self, db: &dyn crate::Db) -> FooData { FooData { f: self.f(db), ... } } }`
//! * this could be optimized, particularly for interned fields

use crate::{
db_lifetime,
options::{AllowedOptions, Options},
};
use proc_macro2::{Ident, Literal, Span, TokenStream};

use crate::db_lifetime;
use crate::options::{AllowedOptions, Options};

pub(crate) struct SalsaStruct<'s, A: SalsaStructAllowedOptions> {
struct_item: &'s syn::ItemStruct,
args: &'s Options<A>,
Expand Down
3 changes: 2 additions & 1 deletion components/salsa-macros/src/supertype.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::token_stream_with_error;
use proc_macro2::TokenStream;

use crate::token_stream_with_error;

/// The implementation of the `supertype` macro.
///
/// For an entity enum `Foo` with variants `Variant1, ..., VariantN`, we generate
Expand Down
3 changes: 2 additions & 1 deletion components/salsa-macros/src/tracked.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use syn::{spanned::Spanned, Item};
use syn::spanned::Spanned;
use syn::Item;

use crate::token_stream_with_error;

Expand Down
7 changes: 5 additions & 2 deletions components/salsa-macros/src/tracked_fn.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use proc_macro2::{Literal, Span, TokenStream};
use quote::ToTokens;
use syn::{spanned::Spanned, ItemFn};
use syn::spanned::Spanned;
use syn::ItemFn;

use crate::{db_lifetime, fn_util, hygiene::Hygiene, options::Options};
use crate::hygiene::Hygiene;
use crate::options::Options;
use crate::{db_lifetime, fn_util};

// Source:
//
Expand Down
7 changes: 5 additions & 2 deletions components/salsa-macros/src/tracked_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ use std::collections::HashSet;

use proc_macro2::TokenStream;
use quote::ToTokens;
use syn::{parse::Nothing, visit_mut::VisitMut};
use syn::parse::Nothing;
use syn::visit_mut::VisitMut;

use crate::{hygiene::Hygiene, tracked_fn::FnArgs, xform::ChangeSelfPath};
use crate::hygiene::Hygiene;
use crate::tracked_fn::FnArgs;
use crate::xform::ChangeSelfPath;

pub(crate) fn tracked_impl(
args: proc_macro::TokenStream,
Expand Down
11 changes: 5 additions & 6 deletions components/salsa-macros/src/tracked_struct.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{
db_lifetime,
hygiene::Hygiene,
options::Options,
salsa_struct::{SalsaStruct, SalsaStructAllowedOptions},
};
use proc_macro2::TokenStream;

use crate::db_lifetime;
use crate::hygiene::Hygiene;
use crate::options::Options;
use crate::salsa_struct::{SalsaStruct, SalsaStructAllowedOptions};

/// For an entity struct `Foo` with fields `f1: T1, ..., fN: TN`, we generate...
///
/// * the "id struct" `struct Foo(salsa::Id)`
Expand Down
4 changes: 3 additions & 1 deletion components/salsa-macros/src/xform.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::collections::HashSet;

use quote::ToTokens;
use syn::{punctuated::Punctuated, spanned::Spanned, visit_mut::VisitMut};
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::visit_mut::VisitMut;

pub(crate) struct ChangeLt<'a> {
from: Option<&'a str>,
Expand Down
4 changes: 3 additions & 1 deletion examples/calc/compile.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{ir::SourceProgram, parser::parse_statements, type_check::type_check_program};
use crate::ir::SourceProgram;
use crate::parser::parse_statements;
use crate::type_check::type_check_program;

#[salsa::tracked]
pub fn compile(db: &dyn crate::Db, source_program: SourceProgram) {
Expand Down
11 changes: 7 additions & 4 deletions examples/calc/type_check.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::ir::{
Diagnostic, Expression, Function, FunctionId, Program, Span, StatementData, VariableId,
};
#[cfg(test)]
use expect_test::expect;
use salsa::Accumulator;
#[cfg(test)]
use test_log::test;

use crate::ir::{
Diagnostic, Expression, Function, FunctionId, Program, Span, StatementData, VariableId,
};

// ANCHOR: parse_statements
#[salsa::tracked]
pub fn type_check_program<'db>(db: &'db dyn crate::Db, program: Program<'db>) {
Expand Down Expand Up @@ -112,7 +113,9 @@ fn check_string(
) {
use salsa::{Database, Setter};

use crate::{db::CalcDatabaseImpl, ir::SourceProgram, parser::parse_statements};
use crate::db::CalcDatabaseImpl;
use crate::ir::SourceProgram;
use crate::parser::parse_statements;

// Create the database
let mut db = CalcDatabaseImpl::default();
Expand Down
18 changes: 7 additions & 11 deletions examples/lazy-input/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#![allow(unreachable_patterns)]
// FIXME(rust-lang/rust#129031): regression in nightly
use std::{
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::time::Duration;

use crossbeam_channel::{unbounded, Sender};
use dashmap::{mapref::entry::Entry, DashMap};
use dashmap::mapref::entry::Entry;
use dashmap::DashMap;
use eyre::{eyre, Context, Report, Result};
use notify_debouncer_mini::{
new_debouncer,
notify::{RecommendedWatcher, RecursiveMode},
DebounceEventResult, Debouncer,
};
use notify_debouncer_mini::notify::{RecommendedWatcher, RecursiveMode};
use notify_debouncer_mini::{new_debouncer, DebounceEventResult, Debouncer};
use salsa::{Accumulator, Setter, Storage};

// ANCHOR: main
Expand Down
59 changes: 12 additions & 47 deletions src/accumulator.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
//! Basic test of accumulator functionality.

use std::{
any::{Any, TypeId},
fmt,
marker::PhantomData,
panic::UnwindSafe,
};

use accumulated::Accumulated;
use accumulated::AnyAccumulated;

use crate::{
function::VerifyResult,
ingredient::{fmt_index, Ingredient, Jar},
plumbing::IngredientIndices,
zalsa::{IngredientIndex, Zalsa},
zalsa_local::QueryOrigin,
Database, DatabaseKeyIndex, Id, Revision,
};
use std::any::{Any, TypeId};
use std::fmt;
use std::marker::PhantomData;
use std::panic::UnwindSafe;

use accumulated::{Accumulated, AnyAccumulated};

use crate::function::VerifyResult;
use crate::ingredient::{fmt_index, Ingredient, Jar};
use crate::plumbing::IngredientIndices;
use crate::zalsa::{IngredientIndex, Zalsa};
use crate::{Database, Id, Revision};

mod accumulated;
pub(crate) mod accumulated_map;
Expand Down Expand Up @@ -109,35 +103,6 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
panic!("nothing should ever depend on an accumulator directly")
}

fn is_provisional_cycle_head<'db>(&'db self, _db: &'db dyn Database, _input: Id) -> bool {
false
}

fn wait_for(&self, _db: &dyn Database, _key_index: Id) -> bool {
true
}

fn origin(&self, _db: &dyn Database, _key_index: crate::Id) -> Option<QueryOrigin> {
None
}

fn mark_validated_output(
&self,
_db: &dyn Database,
_executor: DatabaseKeyIndex,
_output_key: crate::Id,
) {
}

fn remove_stale_output(
&self,
_db: &dyn Database,
_executor: DatabaseKeyIndex,
_stale_output_key: crate::Id,
_provisional: bool,
) {
}

fn fmt_index(&self, index: crate::Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt_index(A::DEBUG_NAME, index, fmt)
}
Expand Down
2 changes: 1 addition & 1 deletion src/accumulator/accumulated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::any::Any;
use std::fmt::Debug;

use super::Accumulator;
use crate::accumulator::Accumulator;

#[derive(Clone, Debug)]
pub(crate) struct Accumulated<A: Accumulator> {
Expand Down
10 changes: 4 additions & 6 deletions src/accumulator/accumulated_map.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::{
ops,
sync::atomic::{AtomicBool, Ordering},
};
use std::ops;
use std::sync::atomic::{AtomicBool, Ordering};

use rustc_hash::FxHashMap;

use crate::accumulator::accumulated::Accumulated;
use crate::accumulator::{Accumulator, AnyAccumulated};
use crate::IngredientIndex;

use super::{accumulated::Accumulated, Accumulator, AnyAccumulated};

#[derive(Default)]
pub struct AccumulatedMap {
map: FxHashMap<IngredientIndex, Box<dyn AnyAccumulated>>,
Expand Down
24 changes: 10 additions & 14 deletions src/active_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@ use std::ops::Not;
use std::sync::atomic::AtomicBool;
use std::{mem, ops};

use super::zalsa_local::{QueryEdges, QueryOrigin, QueryRevisions};
use crate::accumulator::accumulated_map::AtomicInputAccumulatedValues;
use crate::runtime::Stamp;
use crate::tracked_struct::{DisambiguatorMap, IdentityHash, IdentityMap};
use crate::zalsa_local::QueryEdge;
use crate::{
accumulator::accumulated_map::{AccumulatedMap, InputAccumulatedValues},
cycle::CycleHeads,
durability::Durability,
hash::FxIndexSet,
key::DatabaseKeyIndex,
tracked_struct::Disambiguator,
Revision,
use crate::accumulator::accumulated_map::{
AccumulatedMap, AtomicInputAccumulatedValues, InputAccumulatedValues,
};
use crate::{Accumulator, IngredientIndex};
use crate::cycle::CycleHeads;
use crate::durability::Durability;
use crate::hash::FxIndexSet;
use crate::key::DatabaseKeyIndex;
use crate::runtime::Stamp;
use crate::tracked_struct::{Disambiguator, DisambiguatorMap, IdentityHash, IdentityMap};
use crate::zalsa_local::{QueryEdge, QueryEdges, QueryOrigin, QueryRevisions};
use crate::{Accumulator, IngredientIndex, Revision};

#[derive(Debug)]
pub(crate) struct ActiveQuery {
Expand Down
3 changes: 2 additions & 1 deletion src/attach.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{cell::Cell, ptr::NonNull};
use std::cell::Cell;
use std::ptr::NonNull;

use crate::Database;

Expand Down
6 changes: 2 additions & 4 deletions src/cancelled.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{
fmt,
panic::{self, UnwindSafe},
};
use std::fmt;
use std::panic::{self, UnwindSafe};

/// A panic payload indicating that execution of a salsa query was cancelled.
///
Expand Down
Loading