mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-13 00:40:22 +00:00
make event generation lazy
Creating events if nobody is listening has always bugged me.
This commit is contained in:
parent
1842b1dfbb
commit
64556e9d28
21 changed files with 37 additions and 24 deletions
|
@ -36,7 +36,8 @@ impl Database {
|
|||
// ANCHOR: db_impl
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
eprintln!("Event: {event:?}");
|
||||
// Log interesting events, if logging is enabled
|
||||
if let Some(logs) = &self.logs {
|
||||
|
|
|
@ -124,8 +124,9 @@ impl Db for Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
// don't log boring events
|
||||
let event = event();
|
||||
if let salsa::EventKind::WillExecute { .. } = event.kind {
|
||||
self.logs.lock().unwrap().push(format!("{:?}", event));
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
|
|||
) {
|
||||
assert!(stale_output_key.is_none());
|
||||
if self.map.remove(&executor).is_some() {
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
kind: EventKind::DidDiscardAccumulated {
|
||||
executor_key: executor,
|
||||
|
|
|
@ -8,8 +8,12 @@ pub trait Database: ZalsaDatabase + AsDynDatabase {
|
|||
///
|
||||
/// By default, the event is logged at level debug using
|
||||
/// the standard `log` facade.
|
||||
fn salsa_event(&self, event: Event) {
|
||||
tracing::debug!("salsa_event: {:?}", event)
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// * `event`, a fn that, if called, will create the event that occurred
|
||||
fn salsa_event(&self, event: &dyn Fn() -> Event) {
|
||||
tracing::debug!("salsa_event: {:?}", event())
|
||||
}
|
||||
|
||||
/// A "synthetic write" causes the system to act *as though* some
|
||||
|
|
|
@ -264,7 +264,7 @@ where
|
|||
|
||||
if let Some(origin) = self.delete_memo(id) {
|
||||
let key = self.database_key_index(id);
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
kind: EventKind::DidDiscard { key },
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
hash::FxHashSet, key::DependencyIndex, local_state::QueryRevisions, AsDynDatabase as _,
|
||||
Database, DatabaseKeyIndex, Event, EventKind,
|
||||
DatabaseKeyIndex, Event, EventKind,
|
||||
};
|
||||
|
||||
use super::{memo::Memo, Configuration, IngredientImpl};
|
||||
|
@ -38,7 +38,9 @@ where
|
|||
}
|
||||
|
||||
fn report_stale_output(db: &C::DbView, key: DatabaseKeyIndex, output: DependencyIndex) {
|
||||
db.salsa_event(Event {
|
||||
let db = db.as_dyn_database();
|
||||
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
kind: EventKind::WillDiscardStaleOutput {
|
||||
execute_key: key,
|
||||
|
@ -46,6 +48,6 @@ where
|
|||
},
|
||||
});
|
||||
|
||||
output.remove_stale_output(db.as_dyn_database(), key);
|
||||
output.remove_stale_output(db, key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ where
|
|||
|
||||
tracing::info!("{:?}: executing query", database_key_index);
|
||||
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
kind: EventKind::WillExecute {
|
||||
database_key: database_key_index,
|
||||
|
|
|
@ -149,7 +149,7 @@ impl<V> Memo<V> {
|
|||
revision_now: Revision,
|
||||
database_key_index: DatabaseKeyIndex,
|
||||
) {
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
kind: EventKind::DidValidateMemoizedValue {
|
||||
database_key: database_key_index,
|
||||
|
|
|
@ -80,7 +80,7 @@ impl<Db: Database> Handle<Db> {
|
|||
let zalsa = self.db().zalsa();
|
||||
zalsa.set_cancellation_flag();
|
||||
|
||||
self.db().salsa_event(Event {
|
||||
self.db().salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
|
||||
kind: EventKind::DidSetCancellationFlag,
|
||||
|
|
|
@ -321,7 +321,7 @@ impl LocalState {
|
|||
/// used instead.
|
||||
pub(crate) fn unwind_if_revision_cancelled(&self, db: &dyn Database) {
|
||||
let thread_id = std::thread::current().id();
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id,
|
||||
|
||||
kind: EventKind::WillCheckCancellation,
|
||||
|
|
|
@ -187,7 +187,7 @@ impl Runtime {
|
|||
assert!(!dg.depends_on(other_id, thread_id));
|
||||
}
|
||||
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id,
|
||||
kind: EventKind::WillBlockOn {
|
||||
other_thread_id: other_id,
|
||||
|
|
|
@ -394,7 +394,7 @@ where
|
|||
/// unspecified results (but not UB). See [`InternedIngredient::delete_index`] for more
|
||||
/// discussion and important considerations.
|
||||
pub(crate) fn delete_entity(&self, db: &dyn crate::Database, id: Id) {
|
||||
db.salsa_event(Event {
|
||||
db.salsa_event(&|| Event {
|
||||
thread_id: std::thread::current().id(),
|
||||
kind: crate::EventKind::DidDiscard {
|
||||
key: self.database_key_index(id),
|
||||
|
|
|
@ -52,7 +52,7 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, _event: salsa::Event) {}
|
||||
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
|
|
|
@ -59,7 +59,7 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, _event: salsa::Event) {}
|
||||
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
|
|
|
@ -50,7 +50,7 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, _event: salsa::Event) {}
|
||||
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
|
|
|
@ -65,7 +65,7 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, _event: salsa::Event) {}
|
||||
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
|
|
|
@ -60,7 +60,8 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
match event.kind {
|
||||
salsa::EventKind::WillDiscardStaleOutput { .. }
|
||||
| salsa::EventKind::DidDiscard { .. } => {
|
||||
|
|
|
@ -54,7 +54,8 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
match event.kind {
|
||||
salsa::EventKind::WillDiscardStaleOutput { .. }
|
||||
| salsa::EventKind::DidDiscard { .. } => {
|
||||
|
|
|
@ -37,7 +37,8 @@ pub(crate) struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
match event.kind {
|
||||
salsa::EventKind::WillBlockOn { .. } => {
|
||||
self.signal(self.knobs().signal_on_will_block.load());
|
||||
|
|
|
@ -25,7 +25,8 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
self.push_log(format!("{event:?}"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,8 @@ struct Database {
|
|||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_event(&self, event: salsa::Event) {
|
||||
fn salsa_event(&self, event: &dyn Fn() -> salsa::Event) {
|
||||
let event = event();
|
||||
match event.kind {
|
||||
salsa::EventKind::WillExecute { .. }
|
||||
| salsa::EventKind::DidValidateMemoizedValue { .. } => {
|
||||
|
|
Loading…
Reference in a new issue