[−][src]Trait salsa::Database
The base trait which your "query context" must implement. Gives access to the salsa runtime, which you must embed into your query context (along with whatever other state you may require).
Required methods
fn salsa_runtime(&self) -> &Runtime<Self>
Gives access to the underlying salsa runtime.
Provided methods
fn sweep_all(&self, strategy: SweepStrategy)
Iterates through all query storage and removes any values that have not been used since the last revision was created. The intended use-cycle is that you first execute all of your "main" queries; this will ensure that all query values they consume are marked as used. You then invoke this method to remove other values that were not needed for your main query results.
fn query<Q>(&self, query: Q) -> QueryTable<Self, Q> where
Q: Query<Self>,
Self: GetQueryTable<Q>,
Q: Query<Self>,
Self: GetQueryTable<Q>,
Get access to extra methods pertaining to a given query. For
example, you can use this to run the GC (sweep
) across a
single input. You can also use it to invoke a query, though
it's more common to use the trait method on the database
itself.
fn query_mut<Q>(&mut self, query: Q) -> QueryTableMut<Self, Q> where
Q: Query<Self>,
Self: GetQueryTable<Q>,
Q: Query<Self>,
Self: GetQueryTable<Q>,
Like query
, but gives access to methods for setting the
value of an input.
Threads, cancellation, and blocking
Mutating the value of a query cannot be done while there are
still other queries executing. If you are using your database
within a single thread, this is not a problem: you only have
&self
access to the database, but this method requires &mut self
.
However, if you have used snapshot
to create other threads,
then attempts to set
will block the current thread until
those snapshots are dropped (usually when those threads
complete). This also implies that if you create a snapshot but
do not send it to another thread, then invoking set
will
deadlock.
Before blocking, the thread that is attempting to set
will
also set a cancellation flag. In the threads operating on
snapshots, you can use the is_current_revision_canceled
method to check for this flag and bring those operations to a
close, thus allowing the set
to succeed. Ignoring this flag
may lead to "starvation", meaning that the thread attempting
to set
has to wait a long, long time. =)
fn salsa_event(&self, event_fn: impl Fn() -> Event<Self>)
This function is invoked at key points in the salsa runtime. It permits the database to be customized and to inject logging or other custom behavior.
fn on_propagated_panic(&self) -> !
This function is invoked when a dependent query is being computed by the other thread, and that thread panics.