From 12f54d66f4a1ab525f811c3625229bd91b38b646 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 2 Jul 2020 12:54:59 +0000 Subject: [PATCH] move query/query-mut to DatabaseQueryExt --- src/lib.rs | 51 ++++++++++++++++-------------- tests/gc/derived_tests.rs | 2 +- tests/gc/discard_values.rs | 2 +- tests/gc/interned.rs | 2 +- tests/gc/shallow_constant_tests.rs | 2 +- tests/gc/volatile_tests.rs | 2 +- tests/incremental/constants.rs | 2 +- tests/lru.rs | 2 +- tests/on_demand_inputs.rs | 2 +- tests/parallel/stress.rs | 1 + 10 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a020887e..035c7698 100644 --- a/src/lib.rs +++ b/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 { { >::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 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`. diff --git a/tests/gc/derived_tests.rs b/tests/gc/derived_tests.rs index 83ab2dbb..9b57147c 100644 --- a/tests/gc/derived_tests.rs +++ b/tests/gc/derived_tests.rs @@ -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() { diff --git a/tests/gc/discard_values.rs b/tests/gc/discard_values.rs index b1a2d5aa..321b569e 100644 --- a/tests/gc/discard_values.rs +++ b/tests/gc/discard_values.rs @@ -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() { diff --git a/tests/gc/interned.rs b/tests/gc/interned.rs index 9df73b88..95a7603c 100644 --- a/tests/gc/interned.rs +++ b/tests/gc/interned.rs @@ -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)] diff --git a/tests/gc/shallow_constant_tests.rs b/tests/gc/shallow_constant_tests.rs index 98782f00..a8bc9ecd 100644 --- a/tests/gc/shallow_constant_tests.rs +++ b/tests/gc/shallow_constant_tests.rs @@ -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 diff --git a/tests/gc/volatile_tests.rs b/tests/gc/volatile_tests.rs index 86f4b9c3..de39c464 100644 --- a/tests/gc/volatile_tests.rs +++ b/tests/gc/volatile_tests.rs @@ -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; diff --git a/tests/incremental/constants.rs b/tests/incremental/constants.rs index 6064d55f..47989eff 100644 --- a/tests/incremental/constants.rs +++ b/tests/incremental/constants.rs @@ -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 { diff --git a/tests/lru.rs b/tests/lru.rs index 5b4c8fb5..eb19e49d 100644 --- a/tests/lru.rs +++ b/tests/lru.rs @@ -4,7 +4,7 @@ use std::sync::{ Arc, }; -use salsa::Database as _; +use salsa::DatabaseQueryExt as _; #[derive(Debug, PartialEq, Eq)] struct HotPotato(u32); diff --git a/tests/on_demand_inputs.rs b/tests/on_demand_inputs.rs index 1b5c7cf1..0b92bc89 100644 --- a/tests/on_demand_inputs.rs +++ b/tests/on_demand_inputs.rs @@ -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> { diff --git a/tests/parallel/stress.rs b/tests/parallel/stress.rs index 5cea1896..09e2a416 100644 --- a/tests/parallel/stress.rs +++ b/tests/parallel/stress.rs @@ -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;