mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-07-24 05:36:31 +00:00
move query/query-mut to DatabaseQueryExt
This commit is contained in:
parent
28b642e8c0
commit
12f54d66f4
10 changed files with 37 additions and 31 deletions
51
src/lib.rs
51
src/lib.rs
|
@ -62,6 +62,32 @@ pub trait Database: plumbing::DatabaseStorageTypes + plumbing::DatabaseOps {
|
|||
self.for_each_query(|query_storage| query_storage.sweep(self, strategy));
|
||||
}
|
||||
|
||||
/// 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 salsa_event(&self, event_fn: Event) {
|
||||
#![allow(unused_variables)]
|
||||
}
|
||||
|
||||
/// This function is invoked when a dependent query is being computed by the
|
||||
/// other thread, and that thread panics.
|
||||
fn on_propagated_panic(&self) -> ! {
|
||||
panic!("concurrent salsa query panicked")
|
||||
}
|
||||
|
||||
/// Gives access to the underlying salsa runtime.
|
||||
fn salsa_runtime(&self) -> &Runtime {
|
||||
self.ops_salsa_runtime()
|
||||
}
|
||||
|
||||
/// Gives access to the underlying salsa runtime.
|
||||
fn salsa_runtime_mut(&mut self) -> &mut Runtime {
|
||||
self.ops_salsa_runtime_mut()
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait that gives access to the `query` and `query_mut` methods.
|
||||
pub trait DatabaseQueryExt: Database {
|
||||
/// 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
|
||||
|
@ -111,31 +137,10 @@ pub trait Database: plumbing::DatabaseStorageTypes + plumbing::DatabaseOps {
|
|||
{
|
||||
<Self as plumbing::GetQueryTable<Q>>::get_query_table_mut(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 salsa_event(&self, event_fn: Event) {
|
||||
#![allow(unused_variables)]
|
||||
}
|
||||
|
||||
/// This function is invoked when a dependent query is being computed by the
|
||||
/// other thread, and that thread panics.
|
||||
fn on_propagated_panic(&self) -> ! {
|
||||
panic!("concurrent salsa query panicked")
|
||||
}
|
||||
|
||||
/// Gives access to the underlying salsa runtime.
|
||||
fn salsa_runtime(&self) -> &Runtime {
|
||||
self.ops_salsa_runtime()
|
||||
}
|
||||
|
||||
/// Gives access to the underlying salsa runtime.
|
||||
fn salsa_runtime_mut(&mut self) -> &mut Runtime {
|
||||
self.ops_salsa_runtime_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB: Database> DatabaseQueryExt for DB {}
|
||||
|
||||
/// The `Event` struct identifies various notable things that can
|
||||
/// occur during salsa execution. Instances of this struct are given
|
||||
/// to `salsa_event`.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::db;
|
||||
use crate::group::*;
|
||||
use salsa::debug::DebugQueryTable;
|
||||
use salsa::{Database, Durability, SweepStrategy};
|
||||
use salsa::{Database, DatabaseQueryExt, Durability, SweepStrategy};
|
||||
|
||||
#[test]
|
||||
fn compute_one_write_low() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::db;
|
||||
use crate::group::{FibonacciQuery, GcDatabase};
|
||||
use salsa::debug::DebugQueryTable;
|
||||
use salsa::{Database, Durability, SweepStrategy};
|
||||
use salsa::{Database, DatabaseQueryExt, Durability, SweepStrategy};
|
||||
|
||||
#[test]
|
||||
fn sweep_default() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::db;
|
||||
use salsa::debug::DebugQueryTable;
|
||||
use salsa::{Database, Durability, InternId, SweepStrategy};
|
||||
use salsa::{Database, DatabaseQueryExt, Durability, InternId, SweepStrategy};
|
||||
|
||||
/// Query group for tests for how interned keys interact with GC.
|
||||
#[salsa::query_group(Intern)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::db;
|
||||
use crate::group::{FibonacciQuery, GcDatabase};
|
||||
use salsa::debug::DebugQueryTable;
|
||||
use salsa::{Database, Durability, SweepStrategy};
|
||||
use salsa::{Database, DatabaseQueryExt, Durability, SweepStrategy};
|
||||
|
||||
// For constant values (like `fibonacci`), we only keep the values
|
||||
// that were used in the latest revision, not the sub-values that
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::db;
|
||||
use salsa::{Database, SweepStrategy};
|
||||
use salsa::{Database, DatabaseQueryExt, SweepStrategy};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::implementation::{TestContext, TestContextImpl};
|
||||
use salsa::debug::DebugQueryTable;
|
||||
use salsa::{Database, Durability};
|
||||
use salsa::{DatabaseQueryExt, Durability};
|
||||
|
||||
#[salsa::query_group(Constants)]
|
||||
pub(crate) trait ConstantsDatabase: TestContext {
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::sync::{
|
|||
Arc,
|
||||
};
|
||||
|
||||
use salsa::Database as _;
|
||||
use salsa::DatabaseQueryExt as _;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct HotPotato(u32);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use std::{cell::Cell, collections::HashMap, rc::Rc};
|
||||
|
||||
use salsa::{Database as _, Durability};
|
||||
use salsa::{Database as _, DatabaseQueryExt as _, Durability};
|
||||
|
||||
#[salsa::query_group(QueryGroupStorage)]
|
||||
trait QueryGroup: salsa::Database + AsRef<HashMap<u32, u32>> {
|
||||
|
|
|
@ -2,6 +2,7 @@ use rand::seq::SliceRandom;
|
|||
use rand::Rng;
|
||||
|
||||
use salsa::Database;
|
||||
use salsa::DatabaseQueryExt;
|
||||
use salsa::ParallelDatabase;
|
||||
use salsa::Snapshot;
|
||||
use salsa::SweepStrategy;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue