Skip to content

Commit

Permalink
Send + Sync requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jul 12, 2024
1 parent a1651c8 commit 65118a0
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 323 deletions.
9 changes: 6 additions & 3 deletions components/salsa-macros/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ impl DbMacro {

fn add_salsa_view_method(&self, input: &mut syn::ItemTrait) -> syn::Result<()> {
input.items.push(parse_quote! {
fn __salsa_add_view__(&self);
#[doc(hidden)]
fn zalsa_add_view(&self);
});
Ok(())
}
Expand All @@ -121,8 +122,10 @@ impl DbMacro {
));
};
input.items.push(parse_quote! {
fn __salsa_add_view__(&self) {
salsa::storage::views(self).add::<dyn #TraitPath>(|t| t, |t| t);
#[doc(hidden)]
#[allow(uncommon_codepoins)]
fn zalsa_add_view(&self) {
salsa::storage::views(self).add::<Self, dyn #TraitPath>(|t| t, |t| t);
}
});
Ok(())
Expand Down
184 changes: 0 additions & 184 deletions components/salsa-macros/src/jar.rs

This file was deleted.

11 changes: 0 additions & 11 deletions components/salsa-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ mod debug;
mod debug_with_db;
mod input;
mod interned;
mod jar;
mod options;
mod salsa_struct;
mod tracked;
Expand All @@ -60,21 +59,11 @@ pub fn accumulator(args: TokenStream, input: TokenStream) -> TokenStream {
accumulator::accumulator(args, input)
}

#[proc_macro_attribute]
pub fn jar(args: TokenStream, input: TokenStream) -> TokenStream {
jar::jar(args, input)
}

#[proc_macro_attribute]
pub fn db(args: TokenStream, input: TokenStream) -> TokenStream {
db::db(args, input)
}

#[proc_macro_attribute]
pub fn db_view(args: TokenStream, input: TokenStream) -> TokenStream {
db_view::db_view(args, input)
}

#[proc_macro_attribute]
pub fn interned(args: TokenStream, input: TokenStream) -> TokenStream {
interned::interned(args, input)
Expand Down
2 changes: 1 addition & 1 deletion src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
pub trait Accumulator: Jar {
const DEBUG_NAME: &'static str;

type Data: Clone + Debug;
type Data: Clone + Debug + Send + Sync;
}

pub struct AccumulatorJar<A: Accumulator> {
Expand Down
20 changes: 1 addition & 19 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use parking_lot::Mutex;

use crate::{storage::DatabaseGen, Durability, Event};

#[salsa_macros::db]
pub trait Database: DatabaseGen {
/// This function is invoked at key points in the salsa
/// runtime. It permits the database to be customized and to
Expand Down Expand Up @@ -37,21 +38,6 @@ pub trait Database: DatabaseGen {
}
}

/// The database view trait allows you to define your own views on the database.
/// This lets you add extra context beyond what is stored in the salsa database itself.
pub trait DatabaseView<Dyn: ?Sized + Any>: Database {
/// Registers this database view in the database.
/// This is normally invoked automatically by tracked functions that require a given view.
fn add_view_to_db(&self);
}

impl<Db: Database> DatabaseView<dyn Database> for Db {
fn add_view_to_db(&self) {
let upcasts = self.views_of_self();
upcasts.add::<dyn Database>(|t| t, |t| t);
}
}

/// Indicates a database that also supports parallel query
/// evaluation. All of Salsa's base query support is capable of
/// parallel execution, but for it to work, your query key/value types
Expand Down Expand Up @@ -194,10 +180,6 @@ impl AttachedDatabase {
}
}

unsafe impl Send for AttachedDatabase where dyn Database: Sync {}

unsafe impl Sync for AttachedDatabase where dyn Database: Sync {}

struct AttachedDb<'db, Db: ?Sized + Database> {
db: &'db Db,
previous: AttachedDatabase,
Expand Down
4 changes: 2 additions & 2 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ pub trait Configuration: 'static {
type SalsaStruct<'db>: SalsaStructInDb<Self::DbView>;

/// The input to the function
type Input<'db>;
type Input<'db>: Send + Sync;

/// The value computed by the function.
type Value<'db>: fmt::Debug;
type Value<'db>: fmt::Debug + Send + Sync;

/// Determines whether this function can recover from being a participant in a cycle
/// (and, if so, how).
Expand Down
6 changes: 3 additions & 3 deletions src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
};

use crate::{
cycle::CycleRecoveryStrategy, key::DependencyIndex, runtime::local_state::QueryOrigin,
storage::IngredientIndex, Database, DatabaseKeyIndex, Id,
cycle::CycleRecoveryStrategy, runtime::local_state::QueryOrigin, storage::IngredientIndex,
Database, DatabaseKeyIndex, Id,
};

use super::Revision;
Expand All @@ -18,7 +18,7 @@ pub trait Jar: Any {
fn create_ingredients(&self, first_index: IngredientIndex) -> Vec<Box<dyn Ingredient>>;
}

pub trait Ingredient: Any + std::fmt::Debug {
pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
/// Has the value for `input` in this ingredient changed after `revision`?
fn maybe_changed_after<'db>(
&'db self,
Expand Down
Loading

0 comments on commit 65118a0

Please sign in to comment.