salsa/event.rs
1use crate::Revision;
2use crate::key::DatabaseKeyIndex;
3use crate::sync::thread::{self, ThreadId};
4
5/// The `Event` struct identifies various notable things that can
6/// occur during salsa execution. Instances of this struct are given
7/// to `salsa_event`.
8#[derive(Debug)]
9pub struct Event {
10 /// The id of the thread that triggered the event.
11 pub thread_id: ThreadId,
12
13 /// What sort of event was it.
14 pub kind: EventKind,
15}
16
17impl Event {
18 pub fn new(kind: EventKind) -> Self {
19 Self {
20 thread_id: thread::current().id(),
21 kind,
22 }
23 }
24}
25
26/// An enum identifying the various kinds of events that can occur.
27#[derive(Debug)]
28pub enum EventKind {
29 /// Occurs when we found that all inputs to a memoized value are
30 /// up-to-date and hence the value can be re-used without
31 /// executing the closure.
32 ///
33 /// Executes before the "re-used" value is returned.
34 DidValidateMemoizedValue {
35 /// The database-key for the affected value. Implements `Debug`.
36 database_key: DatabaseKeyIndex,
37 },
38
39 /// Indicates that another thread (with id `other_thread_id`) is processing the
40 /// given query (`database_key`), so we will block until they
41 /// finish.
42 ///
43 /// Executes after we have registered with the other thread but
44 /// before they have answered us.
45 WillBlockOn {
46 /// The id of the thread we will block on.
47 other_thread_id: ThreadId,
48
49 /// The database-key for the affected value. Implements `Debug`.
50 database_key: DatabaseKeyIndex,
51 },
52
53 /// Indicates that the function for this query will be executed.
54 /// This is either because it has never executed before or because
55 /// its inputs may be out of date.
56 WillExecute {
57 /// The database-key for the affected value. Implements `Debug`.
58 database_key: DatabaseKeyIndex,
59 },
60
61 /// Salsa starts a new fixpoint iteration for the cycle with `database_key` as its
62 /// outermost cycle.
63 WillIterateCycle {
64 /// The database-key for the cycle head. Implements `Debug`.
65 database_key: DatabaseKeyIndex,
66 iteration: u8,
67 },
68
69 /// Salsa completed a fixpoint iteration for the cycle with `database_key` as its
70 /// outermost cycle.
71 DidFinalizeCycle {
72 database_key: DatabaseKeyIndex,
73 iteration: u8,
74 },
75
76 /// Indicates that `unwind_if_cancelled` was called and salsa will check if
77 /// the current revision has been cancelled.
78 WillCheckCancellation,
79
80 /// Indicates that one [`Handle`](`crate::Handle`) has set the cancellation flag.
81 /// When other active handles execute salsa methods, they will observe this flag
82 /// and panic with a sentinel value of type [`Cancelled`](`crate::Cancelled`).
83 DidSetCancellationFlag,
84
85 /// Discovered that a query used to output a given output but no longer does.
86 WillDiscardStaleOutput {
87 /// Key for the query that is executing and which no longer outputs the given value.
88 execute_key: DatabaseKeyIndex,
89
90 /// Key for the query that is no longer output
91 output_key: DatabaseKeyIndex,
92 },
93
94 /// Tracked structs or memoized data were discarded (freed).
95 DidDiscard {
96 /// Value being discarded.
97 key: DatabaseKeyIndex,
98 },
99
100 /// Discarded accumulated data from a given fn
101 DidDiscardAccumulated {
102 /// The key of the fn that accumulated results
103 executor_key: DatabaseKeyIndex,
104
105 /// Accumulator that was accumulated into
106 accumulator: DatabaseKeyIndex,
107 },
108
109 /// Indicates that a value was newly interned.
110 DidInternValue {
111 // The key of the interned value.
112 key: DatabaseKeyIndex,
113
114 // The revision the value was interned in.
115 revision: Revision,
116 },
117
118 /// Indicates that a value was interned by reusing an existing slot.
119 DidReuseInternedValue {
120 // The key of the interned value.
121 key: DatabaseKeyIndex,
122
123 // The revision the value was interned in.
124 revision: Revision,
125 },
126
127 /// Indicates that a previously interned value was read in a new revision.
128 DidValidateInternedValue {
129 // The key of the interned value.
130 key: DatabaseKeyIndex,
131
132 // The revision the value was interned in.
133 revision: Revision,
134 },
135}