fix : remove _{ } syntax from benchmark macro (#7822)

* commented use of common

* hack to pass tests

* another hack

* remove all commented code

* fix the easy tests

* temp hack

* follow through comma hack until better solution

* patch macro

* missed one

* update benchmarks

* update docs

* fix docs

* removed too much

* fix changes

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Stanly Johnson
2021-01-06 07:21:02 +05:30
committed by GitHub
parent 3f629f743b
commit d2ac8bd941
28 changed files with 74 additions and 185 deletions
+23 -74
View File
@@ -88,24 +88,18 @@ pub use sp_storage::TrackedStorageKey;
/// benchmarks! {
/// where_clause { where T::A: From<u32> } // Optional line to give additional bound on `T`.
///
/// // common parameter; just one for this example.
/// // will be `1`, `MAX_LENGTH` or any value inbetween
/// _ {
/// let l in 1 .. MAX_LENGTH => initialize_l(l);
/// }
///
/// // first dispatchable: foo; this is a user dispatchable and operates on a `u8` vector of
/// // size `l`, which we allow to be initialized as usual.
/// // size `l`
/// foo {
/// let caller = account::<T>(b"caller", 0, benchmarks_seed);
/// let l = ...;
/// let l in 1 .. MAX_LENGTH => initialize_l(l);
/// }: _(Origin::Signed(caller), vec![0u8; l])
///
/// // second dispatchable: bar; this is a root dispatchable and accepts a `u8` vector of size
/// // `l`. We don't want it pre-initialized like before so we override using the `=> ()` notation.
/// // `l`.
/// // In this case, we explicitly name the call using `bar` instead of `_`.
/// bar {
/// let l = _ .. _ => ();
/// let l in 1 .. MAX_LENGTH => initialize_l(l);
/// }: bar(Origin::Root, vec![0u8; l])
///
/// // third dispatchable: baz; this is a user dispatchable. It isn't dependent on length like the
@@ -176,18 +170,11 @@ pub use sp_storage::TrackedStorageKey;
#[macro_export]
macro_rules! benchmarks {
(
$( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )?
_ {
$(
let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr;
)*
}
$( $rest:tt )*
) => {
$crate::benchmarks_iter!(
{ }
{ $( $( $where_ty: $where_bound ),* )? }
{ $( { $common , $common_from , $common_to , $common_instancer } )* }
{ }
( )
( )
$( $rest )*
@@ -199,18 +186,11 @@ macro_rules! benchmarks {
#[macro_export]
macro_rules! benchmarks_instance {
(
$( where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? } )?
_ {
$(
let $common:ident in $common_from:tt .. $common_to:expr => $common_instancer:expr;
)*
}
$( $rest:tt )*
) => {
$crate::benchmarks_iter!(
{ I }
{ $( $( $where_ty: $where_bound ),* )? }
{ $( { $common , $common_from , $common_to , $common_instancer } )* }
{ }
( )
( )
$( $rest )*
@@ -221,11 +201,27 @@ macro_rules! benchmarks_instance {
#[macro_export]
#[doc(hidden)]
macro_rules! benchmarks_iter {
// detect and extract where clause:
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
where_clause { where $( $where_ty:ty: $where_bound:path ),* $(,)? }
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $where_ty: $where_bound ),* }
( $( $names )* )
( $( $names_extra )* )
$( $rest )*
}
};
// detect and extract extra tag:
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
#[extra]
@@ -235,7 +231,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* )
( $( $names_extra )* $name )
$name
@@ -246,7 +241,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* ) // This contains $( $( { $instance } )? $name:ident )*
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* )
@@ -256,7 +250,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* )
( $( $names_extra )* )
$name { $( $code )* }: $name ( $origin $( , $arg )* )
@@ -268,7 +261,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* )
@@ -278,7 +270,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* )
( $( $names_extra )* )
$name { $( $code )* }: {
@@ -296,7 +287,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: $eval:block
@@ -307,7 +297,6 @@ macro_rules! benchmarks_iter {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( $common )* }
{ }
{ $eval }
{ $( $code )* }
@@ -324,7 +313,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter!(
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* { $( $instance )? } $name )
( $( $names_extra )* )
$( $rest )*
@@ -334,7 +322,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
) => {
@@ -354,7 +341,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* )
@@ -363,7 +349,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* )
( $( $names_extra )* )
$name { $( $code )* }: _ ( $origin $( , $arg )* )
@@ -375,7 +360,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* )
@@ -384,7 +368,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* )
( $( $names_extra )* )
$name { $( $code )* }: $dispatch ( $origin $( , $arg )* )
@@ -396,7 +379,6 @@ macro_rules! benchmarks_iter {
(
{ $( $instance:ident )? }
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: $eval:block
@@ -405,7 +387,6 @@ macro_rules! benchmarks_iter {
$crate::benchmarks_iter!(
{ $( $instance)? }
{ $( $where_clause )* }
{ $( $common )* }
( $( $names )* )
( $( $names_extra )* )
$name { $( $code )* }: $eval
@@ -423,7 +404,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
{ $( PRE { $( $pre_parsed:tt )* } )* }
{ $eval:block }
{
@@ -436,7 +416,6 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( $common )* }
{
$( PRE { $( $pre_parsed )* } )*
PRE { $pre_id , $pre_ty , $pre_ex }
@@ -450,7 +429,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
{ $( $parsed:tt )* }
{ $eval:block }
{
@@ -463,7 +441,6 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( $common )* }
{
$( $parsed )*
PARAM { $param , $param_from , $param_to , $param_instancer }
@@ -478,7 +455,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* }
{ $( $parsed:tt )* }
{ $eval:block }
{
@@ -491,16 +467,8 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( { $common , $common_from , $common_to , $common_instancer } )* }
{ $( $parsed )* }
{ $eval }
{
let $param
in ({ $( let $common = $common_from; )* $param })
.. ({ $( let $common = $common_to; )* $param })
=> ({ $( let $common = || -> Result<(), &'static str> { $common_instancer ; Ok(()) }; )* $param()? });
$( $rest )*
}
$postcode
}
};
@@ -509,7 +477,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* }
{ $( $parsed:tt )* }
{ $eval:block }
{
@@ -522,16 +489,8 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( { $common , $common_from , $common_to , $common_instancer } )* }
{ $( $parsed )* }
{ $eval }
{
let $param
in ({ $( let $common = $common_from; )* $param })
.. ({ $( let $common = $common_to; )* $param })
=> $param_instancer ;
$( $rest )*
}
$postcode
}
};
@@ -540,7 +499,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
{ $( $parsed:tt )* }
{ $eval:block }
{
@@ -553,7 +511,6 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( $common )* }
{ $( $parsed )* }
{ $eval }
{
@@ -568,7 +525,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
{ $( $parsed:tt )* }
{ $eval:block }
{
@@ -581,7 +537,6 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( $common )* }
{ $( $parsed )* }
{ $eval }
{
@@ -596,7 +551,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $common:tt )* }
{ $( $parsed:tt )* }
{ $eval:block }
{
@@ -609,7 +563,6 @@ macro_rules! benchmark_backend {
{ $( $instance)? }
$name
{ $( $where_clause )* }
{ $( $common )* }
{ $( $parsed )* }
{ $eval }
{
@@ -624,7 +577,6 @@ macro_rules! benchmark_backend {
{ $( $instance:ident )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( { $common:ident , $common_from:tt , $common_to:expr , $common_instancer:expr } )* }
{
$( PRE { $pre_id:tt , $pre_ty:ty , $pre_ex:expr } )*
$( PARAM { $param:ident , $param_from:expr , $param_to:expr , $param_instancer:expr } )*
@@ -653,9 +605,6 @@ macro_rules! benchmark_backend {
components: &[($crate::BenchmarkParameter, u32)],
verify: bool
) -> Result<Box<dyn FnOnce() -> Result<(), &'static str>>, &'static str> {
$(
let $common = $common_from;
)*
$(
// Prepare instance
let $param = components.iter()
+3 -8
View File
@@ -112,13 +112,8 @@ fn new_test_ext() -> sp_io::TestExternalities {
benchmarks!{
where_clause { where <T as OtherConfig>::OtherEvent: Into<<T as Config>::Event> }
_ {
// Define a common range for `b`.
let b in 1 .. 1000 => ();
}
set_value {
let b in ...;
let b in 1 .. 1000;
let caller = account::<T::AccountId>("caller", 0, 0);
}: _ (RawOrigin::Signed(caller), b.into())
verify {
@@ -126,7 +121,7 @@ benchmarks!{
}
other_name {
let b in ...;
let b in 1 .. 1000;
}: dummy (RawOrigin::None, b.into())
sort_vector {
@@ -142,7 +137,7 @@ benchmarks!{
}
bad_origin {
let b in ...;
let b in 1 .. 1000;
let caller = account::<T::AccountId>("caller", 0, 0);
}: dummy (RawOrigin::Signed(caller), b.into())