mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-13 00:40:22 +00:00
93c30a953d
Switch to a procedural implementation of the `query_group!` macro, residing in the `components/salsa_macros` subcrate. Allow the user to override the invoked function via `salsa::invoke(...)` and the name of the generated query type via `salsa::query_type(...)`. In all tests, replace the `salsa::query_group! { ... }` invocations with the new attribute-style `#[salsa::query_group]` macro, and change them to the new naming scheme for query types (`...Query`). Update README, examples, and documentation.
38 lines
1 KiB
Rust
38 lines
1 KiB
Rust
use crate::compiler;
|
|
use std::sync::Arc;
|
|
|
|
#[salsa::query_group]
|
|
pub trait ClassTableDatabase: compiler::CompilerDatabase {
|
|
/// Get the fields.
|
|
fn fields(&self, class: DefId) -> Arc<Vec<DefId>>;
|
|
|
|
/// Get the list of all classes
|
|
fn all_classes(&self) -> Arc<Vec<DefId>>;
|
|
|
|
/// Get the list of all fields
|
|
fn all_fields(&self) -> Arc<Vec<DefId>>;
|
|
}
|
|
|
|
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
|
|
pub struct DefId(usize);
|
|
|
|
fn all_classes(_: &impl ClassTableDatabase) -> Arc<Vec<DefId>> {
|
|
Arc::new(vec![DefId(0), DefId(10)]) // dummy impl
|
|
}
|
|
|
|
fn fields(_: &impl ClassTableDatabase, class: DefId) -> Arc<Vec<DefId>> {
|
|
Arc::new(vec![DefId(class.0 + 1), DefId(class.0 + 2)]) // dummy impl
|
|
}
|
|
|
|
fn all_fields(db: &impl ClassTableDatabase) -> Arc<Vec<DefId>> {
|
|
Arc::new(
|
|
db.all_classes()
|
|
.iter()
|
|
.cloned()
|
|
.flat_map(|def_id| {
|
|
let fields = db.fields(def_id);
|
|
(0..fields.len()).map(move |i| fields[i])
|
|
})
|
|
.collect(),
|
|
)
|
|
}
|