From 6b5871c5afdb4e3ce67fc846346ad60944a67870 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 30 Sep 2018 10:55:52 -0400 Subject: [PATCH] nicer macro syntax we give bad error messages if misused, though --- src/lib.rs | 53 +++++++++++++++++----------- tests/incremental/memoized_inputs.rs | 10 ++---- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index edaafa4f..ba8e2caa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,22 +304,6 @@ macro_rules! query_definition { } }; - ( - @filter_attrs { - input { #[storage(input)] $($input:tt)* }; - storage { $storage:tt }; - other_attrs { $($other_attrs:tt)* }; - } - ) => { - $crate::query_definition! { - @filter_attrs { - input { $($input)* }; - storage { input }; - other_attrs { $($other_attrs)* }; - } - } - }; - ( @filter_attrs { input { #[$attr:meta] $($input:tt)* }; @@ -336,6 +320,7 @@ macro_rules! query_definition { } }; + // Accept a "fn-like" query definition ( @filter_attrs { input { @@ -368,6 +353,12 @@ macro_rules! query_definition { } }; + ( + @storage_ty[$QC:ident, $Self:ident, default] + ) => { + $crate::query_definition! { @storage_ty[$QC, $Self, memoized] } + }; + ( @storage_ty[$QC:ident, $Self:ident, memoized] ) => { @@ -380,10 +371,32 @@ macro_rules! query_definition { $crate::volatile::VolatileStorage }; + // Accept a "field-like" query definition (input) ( - @storage_ty[$QC:ident, $Self:ident, input] + @filter_attrs { + input { + $v:vis $name:ident: Map<$key_ty:ty, $value_ty:ty>; + }; + storage { default }; + other_attrs { $($attrs:tt)* }; + } ) => { - $crate::input::InputStorage<$QC, $Self> + #[derive(Default, Debug)] + $($attrs)* + $v struct $name; + + impl $crate::Query for $name + where + QC: $crate::QueryContext + { + type Key = $key_ty; + type Value = $value_ty; + type Storage = $crate::input::InputStorage; + + fn execute(_: &QC, _: $key_ty) -> $value_ty { + panic!("execute should never run for an input query") + } + } }; // Various legal start states: @@ -393,7 +406,7 @@ macro_rules! query_definition { $crate::query_definition! { @filter_attrs { input { # $($tokens)* }; - storage { memoized }; + storage { default }; other_attrs { }; } } @@ -404,7 +417,7 @@ macro_rules! query_definition { $crate::query_definition! { @filter_attrs { input { $v $name $($tokens)* }; - storage { memoized }; + storage { default }; other_attrs { }; } } diff --git a/tests/incremental/memoized_inputs.rs b/tests/incremental/memoized_inputs.rs index dce500ad..06802d40 100644 --- a/tests/incremental/memoized_inputs.rs +++ b/tests/incremental/memoized_inputs.rs @@ -19,17 +19,11 @@ salsa::query_definition! { } salsa::query_definition! { - #[storage(input)] - crate Input1(_query: &impl MemoizedInputsContext, _value: ()) -> usize { - panic!("silly") - } + crate Input1: Map<(), usize>; } salsa::query_definition! { - #[storage(input)] - crate Input2(_query: &impl MemoizedInputsContext, _value: ()) -> usize { - panic!("silly") - } + crate Input2: Map<(), usize>; } #[test]