salsa/tests/incremental/queries.rs
Niko Matsakis 2d2bdfe7f1 move incremental, storage_varieties to tests
They aren't meant to be things to model oneself after.
2018-09-30 07:01:21 -04:00

38 lines
946 B
Rust

use crate::counter::Counter;
use crate::log::Log;
crate trait CounterContext: salsa::QueryContext {
fn clock(&self) -> &Counter;
fn log(&self) -> &Log;
}
crate trait QueryContext: CounterContext {
salsa::query_prototype! {
fn memoized2() for Memoized2;
fn memoized1() for Memoized1;
fn volatile() for Volatile;
}
}
salsa::query_definition! {
crate Memoized2(query: &impl QueryContext, (): ()) -> usize {
query.log().add("Memoized2 invoked");
query.memoized1().of(())
}
}
salsa::query_definition! {
crate Memoized1(query: &impl QueryContext, (): ()) -> usize {
query.log().add("Memoized1 invoked");
let v = query.volatile().of(());
v / 3
}
}
salsa::query_definition! {
#[storage(volatile)]
crate Volatile(query: &impl QueryContext, (): ()) -> usize {
query.log().add("Volatile invoked");
query.clock().increment()
}
}