2018-09-29 08:50:08 +00:00
|
|
|
use crate::queries;
|
|
|
|
use std::cell::Cell;
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct QueryContextImpl {
|
2018-09-29 09:31:26 +00:00
|
|
|
runtime: salsa::Runtime<QueryContextImpl>,
|
2018-09-29 08:50:08 +00:00
|
|
|
storage: QueryContextImplStorage,
|
|
|
|
counter: Cell<usize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
salsa::query_context_storage! {
|
|
|
|
struct QueryContextImplStorage for storage in QueryContextImpl {
|
|
|
|
impl queries::QueryContext {
|
|
|
|
fn memoized() for queries::Memoized;
|
|
|
|
fn transparent() for queries::Transparent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl queries::CounterContext for QueryContextImpl {
|
|
|
|
fn increment(&self) -> usize {
|
|
|
|
let v = self.counter.get();
|
|
|
|
self.counter.set(v + 1);
|
|
|
|
v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl salsa::BaseQueryContext for QueryContextImpl {
|
|
|
|
type QueryDescriptor = salsa::dyn_descriptor::DynDescriptor;
|
|
|
|
|
2018-09-29 09:31:26 +00:00
|
|
|
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
|
|
|
&self.runtime
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|
|
|
|
}
|