salsa/examples/hello_world/implementation.rs

47 lines
1.4 KiB
Rust
Raw Normal View History

2018-09-28 18:26:46 +00:00
use crate::class_table;
2018-09-28 15:40:20 +00:00
use crate::compiler::{CompilerQueryContext, Interner};
2018-09-28 18:26:46 +00:00
use salsa::query_context_storage;
2018-09-28 15:40:20 +00:00
use salsa::BaseQueryContext;
#[derive(Default)]
pub struct QueryContextImpl {
runtime: salsa::Runtime<QueryContextImpl>,
2018-09-28 15:40:20 +00:00
storage: QueryContextImplStorage,
interner: Interner,
}
2018-09-28 19:50:34 +00:00
// This is an example of how you "link up" all the queries in your
// application.
2018-09-28 18:26:46 +00:00
query_context_storage! {
struct QueryContextImplStorage for storage in QueryContextImpl {
impl class_table::ClassTableQueryContext {
fn all_classes() for class_table::AllClasses;
fn all_fields() for class_table::AllFields;
fn fields() for class_table::Fields;
}
2018-09-28 15:40:20 +00:00
}
}
2018-09-28 19:50:34 +00:00
// This is an example of how you provide custom bits of stuff that
// your queries may need; in this case, an `Interner` value.
2018-09-28 15:40:20 +00:00
impl CompilerQueryContext for QueryContextImpl {
fn interner(&self) -> &Interner {
&self.interner
}
}
2018-09-28 19:50:34 +00:00
// FIXME: This code... probably should not live here. But maybe we
// just want to provide some helpers or something? I do suspect I want
// people to be able to customize this.
2018-09-28 21:39:21 +00:00
//
// Seems like a classic case where specialization could be useful to
// permit behavior refinement.
2018-09-28 15:40:20 +00:00
impl BaseQueryContext for QueryContextImpl {
type QueryDescriptor = salsa::dyn_descriptor::DynDescriptor;
2018-09-28 15:40:20 +00:00
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
&self.runtime
2018-09-28 15:40:20 +00:00
}
}