mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-02-02 17:52:19 +00:00
add runtime_mut and synthetic_write to HasJarsDyn
This commit is contained in:
parent
ea0df0fc03
commit
f5b0ff59d3
3 changed files with 24 additions and 12 deletions
|
@ -120,6 +120,10 @@ fn has_jars_dyn_impl(input: &syn::ItemStruct, storage: &syn::Ident) -> syn::Item
|
||||||
self.#storage.runtime()
|
self.#storage.runtime()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn runtime_mut(&mut self) ->&mut salsa::Runtime {
|
||||||
|
self.#storage.runtime_mut()
|
||||||
|
}
|
||||||
|
|
||||||
fn maybe_changed_after(
|
fn maybe_changed_after(
|
||||||
&self,
|
&self,
|
||||||
input: salsa::key::DependencyIndex,
|
input: salsa::key::DependencyIndex,
|
||||||
|
@ -159,10 +163,15 @@ fn has_jars_dyn_impl(input: &syn::ItemStruct, storage: &syn::Ident) -> syn::Item
|
||||||
let ingredient = self.#storage.ingredient(ingredient);
|
let ingredient = self.#storage.ingredient(ingredient);
|
||||||
ingredient.salsa_struct_deleted(self, id);
|
ingredient.salsa_struct_deleted(self, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_index(&self, index: salsa::key::DependencyIndex, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt_index(&self, index: salsa::key::DependencyIndex, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let ingredient = self.#storage.ingredient(index.ingredient_index());
|
let ingredient = self.#storage.ingredient(index.ingredient_index());
|
||||||
ingredient.fmt_index(index.key_index(), fmt)
|
ingredient.fmt_index(index.key_index(), fmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn synthetic_write(&mut self, durability: salsa::Durability) {
|
||||||
|
self.runtime_mut().synthetic_write(durability);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::jar::Jar;
|
||||||
use crate::key::DependencyIndex;
|
use crate::key::DependencyIndex;
|
||||||
use crate::runtime::local_state::QueryOrigin;
|
use crate::runtime::local_state::QueryOrigin;
|
||||||
use crate::runtime::Runtime;
|
use crate::runtime::Runtime;
|
||||||
use crate::{Database, DatabaseKeyIndex, Id, IngredientIndex};
|
use crate::{Database, DatabaseKeyIndex, Id, IngredientIndex, Durability};
|
||||||
|
|
||||||
use super::routes::Routes;
|
use super::routes::Routes;
|
||||||
use super::{ParallelDatabase, Revision};
|
use super::{ParallelDatabase, Revision};
|
||||||
|
@ -203,6 +203,8 @@ pub trait HasJar<J> {
|
||||||
pub trait HasJarsDyn {
|
pub trait HasJarsDyn {
|
||||||
fn runtime(&self) -> &Runtime;
|
fn runtime(&self) -> &Runtime;
|
||||||
|
|
||||||
|
fn runtime_mut(&mut self) -> &mut Runtime;
|
||||||
|
|
||||||
fn maybe_changed_after(&self, input: DependencyIndex, revision: Revision) -> bool;
|
fn maybe_changed_after(&self, input: DependencyIndex, revision: Revision) -> bool;
|
||||||
|
|
||||||
fn cycle_recovery_strategy(&self, input: IngredientIndex) -> CycleRecoveryStrategy;
|
fn cycle_recovery_strategy(&self, input: IngredientIndex) -> CycleRecoveryStrategy;
|
||||||
|
@ -226,6 +228,8 @@ pub trait HasJarsDyn {
|
||||||
fn salsa_struct_deleted(&self, ingredient: IngredientIndex, id: Id);
|
fn salsa_struct_deleted(&self, ingredient: IngredientIndex, id: Id);
|
||||||
|
|
||||||
fn fmt_index(&self, index: DependencyIndex, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
|
fn fmt_index(&self, index: DependencyIndex, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
|
||||||
|
|
||||||
|
fn synthetic_write(&mut self, durability: Durability);
|
||||||
}
|
}
|
||||||
// ANCHOR_END: HasJarsDyn
|
// ANCHOR_END: HasJarsDyn
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ use std::sync::{
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use salsa::Database;
|
|
||||||
use salsa_2022_tests::{HasLogger, Logger};
|
use salsa_2022_tests::{HasLogger, Logger};
|
||||||
use test_log::test;
|
use test_log::test;
|
||||||
|
use salsa::storage::HasJarsDyn;
|
||||||
|
|
||||||
#[salsa::jar(db = Db)]
|
#[salsa::jar(db = Db)]
|
||||||
struct Jar(MyInput, get_hot_potato, get_hot_potato2, get_volatile);
|
struct Jar(MyInput, get_hot_potato, get_hot_potato2, get_volatile);
|
||||||
|
@ -61,12 +61,12 @@ fn get_volatile(db: &dyn Db, _input: MyInput) -> usize {
|
||||||
|
|
||||||
#[salsa::db(Jar)]
|
#[salsa::db(Jar)]
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct DatabaseImpl {
|
struct Database {
|
||||||
storage: salsa::Storage<Self>,
|
storage: salsa::Storage<Self>,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl salsa::Database for DatabaseImpl {
|
impl salsa::Database for Database {
|
||||||
fn salsa_runtime(&self) -> &salsa::Runtime {
|
fn salsa_runtime(&self) -> &salsa::Runtime {
|
||||||
self.storage.runtime()
|
self.storage.runtime()
|
||||||
}
|
}
|
||||||
|
@ -76,9 +76,9 @@ impl salsa::Database for DatabaseImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Db for DatabaseImpl {}
|
impl Db for Database {}
|
||||||
|
|
||||||
impl HasLogger for DatabaseImpl {
|
impl HasLogger for Database {
|
||||||
fn logger(&self) -> &Logger {
|
fn logger(&self) -> &Logger {
|
||||||
&self.logger
|
&self.logger
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ fn load_n_potatoes() -> usize {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lru_works() {
|
fn lru_works() {
|
||||||
let mut db = DatabaseImpl::default();
|
let mut db = Database::default();
|
||||||
assert_eq!(load_n_potatoes(), 0);
|
assert_eq!(load_n_potatoes(), 0);
|
||||||
|
|
||||||
for i in 0..128u32 {
|
for i in 0..128u32 {
|
||||||
|
@ -106,7 +106,7 @@ fn lru_works() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lru_doesnt_break_volatile_queries() {
|
fn lru_doesnt_break_volatile_queries() {
|
||||||
let mut db = DatabaseImpl::default();
|
let mut db = Database::default();
|
||||||
|
|
||||||
// Create all inputs first, so that there are no revision changes among calls to `get_volatile`
|
// Create all inputs first, so that there are no revision changes among calls to `get_volatile`
|
||||||
let inputs: Vec<MyInput> = (0..128usize)
|
let inputs: Vec<MyInput> = (0..128usize)
|
||||||
|
@ -126,7 +126,7 @@ fn lru_doesnt_break_volatile_queries() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lru_can_be_changed_at_runtime() {
|
fn lru_can_be_changed_at_runtime() {
|
||||||
let mut db = DatabaseImpl::default();
|
let mut db = Database::default();
|
||||||
assert_eq!(load_n_potatoes(), 0);
|
assert_eq!(load_n_potatoes(), 0);
|
||||||
|
|
||||||
let inputs: Vec<(u32, MyInput)> = (0..128).map(|i| (i, MyInput::new(&mut db, i))).collect();
|
let inputs: Vec<(u32, MyInput)> = (0..128).map(|i| (i, MyInput::new(&mut db, i))).collect();
|
||||||
|
@ -169,7 +169,7 @@ fn lru_can_be_changed_at_runtime() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lru_keeps_dependency_info() {
|
fn lru_keeps_dependency_info() {
|
||||||
let mut db = DatabaseImpl::default();
|
let mut db = Database::default();
|
||||||
let capacity = 32;
|
let capacity = 32;
|
||||||
|
|
||||||
// Invoke `get_hot_potato2` 33 times. This will (in turn) invoke
|
// Invoke `get_hot_potato2` 33 times. This will (in turn) invoke
|
||||||
|
@ -183,8 +183,7 @@ fn lru_keeps_dependency_info() {
|
||||||
assert_eq!(x as usize, i);
|
assert_eq!(x as usize, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.salsa_runtime_mut()
|
db.synthetic_write(salsa::Durability::HIGH);
|
||||||
.synthetic_write(salsa::Durability::HIGH);
|
|
||||||
|
|
||||||
// We want to test that calls to `get_hot_potato2` are still considered
|
// We want to test that calls to `get_hot_potato2` are still considered
|
||||||
// clean. Check that no new executions occur as we go here.
|
// clean. Check that no new executions occur as we go here.
|
||||||
|
|
Loading…
Reference in a new issue