replace $crate with salsa in proc macro and make hello_world run

This commit is contained in:
Cormac Relf 2019-01-22 00:45:38 +11:00 committed by Niko Matsakis
parent 1526206e4b
commit 3b15a09b8e
3 changed files with 17 additions and 15 deletions

View file

@ -108,7 +108,7 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
impl ::salsa::plumbing::DatabaseOps for #database_name {
fn for_each_query(
&self,
mut op: impl FnMut(&dyn $crate::plumbing::QueryStorageMassOps<Self>),
mut op: impl FnMut(&dyn salsa::plumbing::QueryStorageMassOps<Self>),
) {
#for_each_ops
}
@ -123,9 +123,9 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
{
for_each_query_desc.extend(quote! {
__SalsaQueryDescriptorKind::#query_name(key) => {
let runtime = $crate::Database::salsa_runtime(db);
let runtime = salsa::Database::salsa_runtime(db);
let storage = &runtime.storage().#query_name;
<_ as $crate::plumbing::QueryStorageOps<#database_name, #query_type>>::maybe_changed_since(
<_ as salsa::plumbing::QueryStorageOps<#database_name, #query_type>>::maybe_changed_since(
storage,
db,
revision,
@ -141,7 +141,7 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
fn maybe_changed_since(
&self,
db: &#database_name,
revision: $crate::plumbing::Revision,
revision: salsa::plumbing::Revision,
) -> bool {
match &self.kind {
#for_each_query_desc
@ -157,13 +157,13 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
} in each_query()
{
for_each_query_table.extend(quote! {
impl $crate::plumbing::GetQueryTable<#query_type> for #database_name {
impl salsa::plumbing::GetQueryTable<#query_type> for #database_name {
fn get_query_table(
db: &Self,
) -> $crate::QueryTable<'_, Self, #query_type> {
$crate::QueryTable::new(
) -> salsa::QueryTable<'_, Self, #query_type> {
salsa::QueryTable::new(
db,
&$crate::Database::salsa_runtime(db)
&salsa::Database::salsa_runtime(db)
.storage()
.#query_name,
)
@ -171,11 +171,11 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
fn get_query_table_mut(
db: &mut Self,
) -> $crate::QueryTableMut<'_, Self, #query_type> {
) -> salsa::QueryTableMut<'_, Self, #query_type> {
let db = &*db;
$crate::QueryTableMut::new(
salsa::QueryTableMut::new(
db,
&$crate::Database::salsa_runtime(db)
&salsa::Database::salsa_runtime(db)
.storage()
.#query_name,
)
@ -183,8 +183,8 @@ pub(crate) fn database_storage(input: TokenStream) -> TokenStream {
fn descriptor(
db: &Self,
key: <#query_type as $crate::Query<Self>>::Key,
) -> <Self as $crate::plumbing::DatabaseStorageTypes>::QueryDescriptor {
key: <#query_type as salsa::Query<Self>>::Key,
) -> <Self as salsa::plumbing::DatabaseStorageTypes>::QueryDescriptor {
__SalsaQueryDescriptor {
kind: __SalsaQueryDescriptorKind::#query_name(key),
}

View file

@ -85,7 +85,9 @@ salsa::database_storage! {
fn main() {
let mut db = DatabaseStruct::default();
println!("Initially, the length is {}.", db.length(()));
// You cannot access input_string yet, because it does not have a value. If you do, it will
// panic. You could create an Option interface by maintaining a HashSet of inserted keys.
// println!("Initially, the length is {}.", db.length(()));
db.query_mut(InputString)
.set((), Arc::new(format!("Hello, world")));

View file

@ -500,7 +500,7 @@ where
/// [`salsa::Runtime`]: struct.Runtime.html
/// [hw]: https://github.com/salsa-rs/salsa/tree/master/examples/hello_world
#[macro_export]
macro_rules! database_storage {
macro_rules! database_storage_old {
(
$(#[$attr:meta])*
$v:vis struct $Storage:ident for $Database:ty {