Merge pull request #648 from Veykril/veykril/push-wltsrnxssltn
Some checks failed
Book / Book (push) Has been cancelled
Test / Test (push) Has been cancelled
Test / Miri (push) Has been cancelled
Test / Benchmarks (push) Has been cancelled
Book / Deploy (push) Has been cancelled

Simplify Event construction
This commit is contained in:
Lukas Wirth 2025-01-05 17:31:42 +00:00 committed by GitHub
commit 28d95f237b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 27 additions and 34 deletions

View file

@ -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 {

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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| {

View file

@ -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 {

View file

@ -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();
@ -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);

View file

@ -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());