Skip to content

Commit

Permalink
Simplify Event construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jan 5, 2025
1 parent 638a094 commit 266f620
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
9 changes: 9 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ pub struct Event {
pub kind: EventKind,
}

impl Event {
pub fn new(kind: EventKind) -> Self {
Self {
thread_id: std::thread::current().id(),
kind,
}
}
}

/// An enum identifying the various kinds of events that can occur.
#[derive(Debug)]
pub enum EventKind {
Expand Down
7 changes: 3 additions & 4 deletions src/function/diff_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ where
fn report_stale_output(db: &C::DbView, key: DatabaseKeyIndex, output: OutputDependencyIndex) {
let db = db.as_dyn_database();

db.salsa_event(&|| Event {
thread_id: std::thread::current().id(),
kind: EventKind::WillDiscardStaleOutput {
db.salsa_event(&|| {
Event::new(EventKind::WillDiscardStaleOutput {
execute_key: key,
output_key: output,
},
})
});

output.remove_stale_output(db, key);
Expand Down
7 changes: 3 additions & 4 deletions src/function/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ where

tracing::info!("{:?}: executing query", database_key_index);

db.salsa_event(&|| Event {
thread_id: std::thread::current().id(),
kind: EventKind::WillExecute {
db.salsa_event(&|| {
Event::new(EventKind::WillExecute {
database_key: database_key_index,
},
})
});

// If we already executed this query once, then use the tracked-struct ids from the
Expand Down
7 changes: 3 additions & 4 deletions src/function/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ impl<V> Memo<V> {
revision_now: Revision,
database_key_index: DatabaseKeyIndex,
) {
db.salsa_event(&|| Event {
thread_id: std::thread::current().id(),
kind: EventKind::DidValidateMemoizedValue {
db.salsa_event(&|| {
Event::new(EventKind::DidValidateMemoizedValue {
database_key: database_key_index,
},
})
});

self.verified_at.store(revision_now);
Expand Down
7 changes: 3 additions & 4 deletions src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,11 @@ impl Runtime {
assert!(!dg.depends_on(other_id, thread_id));
}

db.salsa_event(&|| Event {
thread_id,
kind: EventKind::WillBlockOn {
db.salsa_event(&|| {
Event::new(EventKind::WillBlockOn {
other_thread_id: other_id,
database_key,
},
})
});

let result = local_state.with_query_stack(|stack| {
Expand Down
5 changes: 1 addition & 4 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ impl<Db: Database> Storage<Db> {
fn cancel_others(&self, db: &Db) {
self.zalsa_impl.set_cancellation_flag();

db.salsa_event(&|| Event {
thread_id: std::thread::current().id(),
kind: EventKind::DidSetCancellationFlag,
});
db.salsa_event(&|| Event::new(EventKind::DidSetCancellationFlag));

let mut clones = self.coordinate.clones.lock();
while *clones != 1 {
Expand Down
12 changes: 4 additions & 8 deletions src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,10 @@ 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 {
thread_id: std::thread::current().id(),
kind: crate::EventKind::DidDiscard {
db.salsa_event(&|| {
Event::new(crate::EventKind::DidDiscard {
key: self.database_key_index(id),
},
})
});

let zalsa = db.zalsa();
Expand Down Expand Up @@ -514,10 +513,7 @@ where
key_index: id,
};

db.salsa_event(&|| Event {
thread_id: std::thread::current().id(),
kind: EventKind::DidDiscard { key: executor },
});
db.salsa_event(&|| Event::new(EventKind::DidDiscard { key: executor }));

for stale_output in memo.origin().outputs() {
stale_output.remove_stale_output(db, executor);
Expand Down
7 changes: 1 addition & 6 deletions src/zalsa_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,7 @@ impl ZalsaLocal {
/// `salsa_event` is emitted when this method is called, so that should be
/// used instead.
pub(crate) fn unwind_if_revision_cancelled(&self, db: &dyn Database) {
let thread_id = std::thread::current().id();
db.salsa_event(&|| Event {
thread_id,

kind: EventKind::WillCheckCancellation,
});
db.salsa_event(&|| Event::new(EventKind::WillCheckCancellation));
let zalsa = db.zalsa();
if zalsa.load_cancellation_flag() {
self.unwind_cancelled(zalsa.current_revision());
Expand Down

0 comments on commit 266f620

Please sign in to comment.