mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
rename BaseQueryContext
to just QueryContext
And use it like `salsa::QueryContext` elsewhere.
This commit is contained in:
parent
288fe5b25f
commit
2e40e9d1e5
9 changed files with 21 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
||||||
pub trait CompilerQueryContext: salsa::BaseQueryContext {
|
pub trait CompilerQueryContext: salsa::QueryContext {
|
||||||
fn interner(&self) -> &Interner;
|
fn interner(&self) -> &Interner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::class_table;
|
use crate::class_table;
|
||||||
use crate::compiler::{CompilerQueryContext, Interner};
|
use crate::compiler::{CompilerQueryContext, Interner};
|
||||||
use salsa::query_context_storage;
|
use salsa::query_context_storage;
|
||||||
use salsa::BaseQueryContext;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct QueryContextImpl {
|
pub struct QueryContextImpl {
|
||||||
|
@ -37,7 +36,7 @@ impl CompilerQueryContext for QueryContextImpl {
|
||||||
// Seems like a classic case where specialization could be useful to
|
// Seems like a classic case where specialization could be useful to
|
||||||
// permit behavior refinement.
|
// permit behavior refinement.
|
||||||
|
|
||||||
impl BaseQueryContext for QueryContextImpl {
|
impl salsa::QueryContext for QueryContextImpl {
|
||||||
type QueryDescriptor = salsa::dyn_descriptor::DynDescriptor;
|
type QueryDescriptor = salsa::dyn_descriptor::DynDescriptor;
|
||||||
|
|
||||||
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl queries::CounterContext for QueryContextImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl salsa::BaseQueryContext for QueryContextImpl {
|
impl salsa::QueryContext for QueryContextImpl {
|
||||||
type QueryDescriptor = salsa::dyn_descriptor::DynDescriptor;
|
type QueryDescriptor = salsa::dyn_descriptor::DynDescriptor;
|
||||||
|
|
||||||
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
crate trait CounterContext: salsa::BaseQueryContext {
|
crate trait CounterContext: salsa::QueryContext {
|
||||||
fn increment(&self) -> usize;
|
fn increment(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::BaseQueryContext;
|
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
|
use crate::QueryContext;
|
||||||
use crate::QueryTable;
|
use crate::QueryTable;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::any::{Any, TypeId};
|
use std::any::{Any, TypeId};
|
||||||
|
@ -26,7 +26,7 @@ pub struct DynDescriptor {
|
||||||
impl DynDescriptor {
|
impl DynDescriptor {
|
||||||
pub fn from_key<QC, Q>(_query: &QC, key: &Q::Key) -> DynDescriptor
|
pub fn from_key<QC, Q>(_query: &QC, key: &Q::Key) -> DynDescriptor
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
{
|
{
|
||||||
let type_id = TypeId::of::<Q>();
|
let type_id = TypeId::of::<Q>();
|
||||||
|
|
10
src/lib.rs
10
src/lib.rs
|
@ -26,7 +26,7 @@ pub mod transparent;
|
||||||
|
|
||||||
pub use self::runtime::Runtime;
|
pub use self::runtime::Runtime;
|
||||||
|
|
||||||
pub trait BaseQueryContext: Sized {
|
pub trait QueryContext: Sized {
|
||||||
/// A "query descriptor" packages up all the possible queries and a key.
|
/// A "query descriptor" packages up all the possible queries and a key.
|
||||||
/// It is used to store information about (e.g.) the stack.
|
/// It is used to store information about (e.g.) the stack.
|
||||||
///
|
///
|
||||||
|
@ -39,7 +39,7 @@ pub trait BaseQueryContext: Sized {
|
||||||
fn salsa_runtime(&self) -> &runtime::Runtime<Self>;
|
fn salsa_runtime(&self) -> &runtime::Runtime<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Query<QC: BaseQueryContext>: Debug + Default + Sized + 'static {
|
pub trait Query<QC: QueryContext>: Debug + Default + Sized + 'static {
|
||||||
type Key: Clone + Debug + Hash + Eq + Send;
|
type Key: Clone + Debug + Hash + Eq + Send;
|
||||||
type Value: Clone + Debug + Hash + Eq + Send;
|
type Value: Clone + Debug + Hash + Eq + Send;
|
||||||
type Storage: QueryStorageOps<QC, Self> + Send + Sync;
|
type Storage: QueryStorageOps<QC, Self> + Send + Sync;
|
||||||
|
@ -49,7 +49,7 @@ pub trait Query<QC: BaseQueryContext>: Debug + Default + Sized + 'static {
|
||||||
|
|
||||||
pub trait QueryStorageOps<QC, Q>: Default
|
pub trait QueryStorageOps<QC, Q>: Default
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
{
|
{
|
||||||
fn try_fetch<'q>(
|
fn try_fetch<'q>(
|
||||||
|
@ -63,7 +63,7 @@ where
|
||||||
#[derive(new)]
|
#[derive(new)]
|
||||||
pub struct QueryTable<'me, QC, Q>
|
pub struct QueryTable<'me, QC, Q>
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
{
|
{
|
||||||
pub query: &'me QC,
|
pub query: &'me QC,
|
||||||
|
@ -75,7 +75,7 @@ pub struct CycleDetected;
|
||||||
|
|
||||||
impl<QC, Q> QueryTable<'me, QC, Q>
|
impl<QC, Q> QueryTable<'me, QC, Q>
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
{
|
{
|
||||||
pub fn of(&self, key: Q::Key) -> Q::Value {
|
pub fn of(&self, key: Q::Key) -> Q::Value {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::BaseQueryContext;
|
|
||||||
use crate::CycleDetected;
|
use crate::CycleDetected;
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
|
use crate::QueryContext;
|
||||||
use crate::QueryStorageOps;
|
use crate::QueryStorageOps;
|
||||||
use crate::QueryTable;
|
use crate::QueryTable;
|
||||||
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
|
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
|
||||||
|
@ -20,7 +20,7 @@ use std::hash::Hash;
|
||||||
pub struct MemoizedStorage<QC, Q>
|
pub struct MemoizedStorage<QC, Q>
|
||||||
where
|
where
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
map: RwLock<FxHashMap<Q::Key, QueryState<Q::Value>>>,
|
map: RwLock<FxHashMap<Q::Key, QueryState<Q::Value>>>,
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ enum QueryState<V> {
|
||||||
impl<QC, Q> Default for MemoizedStorage<QC, Q>
|
impl<QC, Q> Default for MemoizedStorage<QC, Q>
|
||||||
where
|
where
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
MemoizedStorage {
|
MemoizedStorage {
|
||||||
|
@ -51,7 +51,7 @@ where
|
||||||
impl<QC, Q> QueryStorageOps<QC, Q> for MemoizedStorage<QC, Q>
|
impl<QC, Q> QueryStorageOps<QC, Q> for MemoizedStorage<QC, Q>
|
||||||
where
|
where
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
fn try_fetch<'q>(
|
fn try_fetch<'q>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
use crate::BaseQueryContext;
|
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
|
use crate::QueryContext;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
pub struct Runtime<QC>
|
pub struct Runtime<QC>
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
execution_stack: RefCell<Vec<QC::QueryDescriptor>>,
|
execution_stack: RefCell<Vec<QC::QueryDescriptor>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<QC> Default for Runtime<QC>
|
impl<QC> Default for Runtime<QC>
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Runtime {
|
Runtime {
|
||||||
|
@ -23,7 +23,7 @@ where
|
||||||
|
|
||||||
impl<QC> Runtime<QC>
|
impl<QC> Runtime<QC>
|
||||||
where
|
where
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
crate fn execute_query_implementation<Q>(
|
crate fn execute_query_implementation<Q>(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::BaseQueryContext;
|
|
||||||
use crate::CycleDetected;
|
use crate::CycleDetected;
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
|
use crate::QueryContext;
|
||||||
use crate::QueryStorageOps;
|
use crate::QueryStorageOps;
|
||||||
use crate::QueryTable;
|
use crate::QueryTable;
|
||||||
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
|
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
|
||||||
|
@ -23,7 +23,7 @@ pub struct TransparentStorage;
|
||||||
impl<QC, Q> QueryStorageOps<QC, Q> for TransparentStorage
|
impl<QC, Q> QueryStorageOps<QC, Q> for TransparentStorage
|
||||||
where
|
where
|
||||||
Q: Query<QC>,
|
Q: Query<QC>,
|
||||||
QC: BaseQueryContext,
|
QC: QueryContext,
|
||||||
{
|
{
|
||||||
fn try_fetch<'q>(
|
fn try_fetch<'q>(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in a new issue