Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 59 additions & 39 deletions frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,33 @@ macro_rules! benchmarks {
}

/// Same as [`benchmarks`] but for instantiable module.
///
/// NOTE: For pallet declared with [`frame_support::pallet`], use [`benchmarks_instance_pallet`].
#[macro_export]
macro_rules! benchmarks_instance {
(
$( $rest:tt )*
) => {
$crate::benchmarks_iter!(
{ I }
{ I: Instance }
{ }
( )
( )
$( $rest )*
);
}
}

/// Same as [`benchmarks`] but for instantiable pallet declared [`frame_support::pallet`].
///
/// NOTE: For pallet declared with `decl_module!`, use [`benchmarks_instnace`].
#[macro_export]
macro_rules! benchmarks_instance_pallet {
(
$( $rest:tt )*
) => {
$crate::benchmarks_iter!(
{ I: 'static }
{ }
( )
( )
Expand All @@ -195,15 +215,15 @@ macro_rules! benchmarks_instance {
macro_rules! benchmarks_iter {
// detect and extract where clause:
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
where_clause { where $( $where_bound:tt )* }
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $instance: $instance_bound)? }
{ $( $where_bound )* }
( $( $names )* )
( $( $names_extra )* )
Expand All @@ -212,7 +232,7 @@ macro_rules! benchmarks_iter {
};
// detect and extract extra tag:
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
Expand All @@ -221,7 +241,7 @@ macro_rules! benchmarks_iter {
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* $name )
Expand All @@ -231,7 +251,7 @@ macro_rules! benchmarks_iter {
};
// mutation arm:
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* ) // This contains $( $( { $instance } )? $name:ident )*
( $( $names_extra:tt )* )
Expand All @@ -240,7 +260,7 @@ macro_rules! benchmarks_iter {
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* )
Expand All @@ -251,7 +271,7 @@ macro_rules! benchmarks_iter {
};
// mutation arm:
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
Expand All @@ -260,7 +280,7 @@ macro_rules! benchmarks_iter {
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* )
Expand All @@ -277,7 +297,7 @@ macro_rules! benchmarks_iter {
};
// iteration arm:
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
Expand All @@ -286,7 +306,7 @@ macro_rules! benchmarks_iter {
$( $rest:tt )*
) => {
$crate::benchmark_backend! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
{ $( $where_clause )* }
{ }
Expand All @@ -298,12 +318,12 @@ macro_rules! benchmarks_iter {
#[cfg(test)]
$crate::impl_benchmark_test!(
{ $( $where_clause )* }
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
);

$crate::benchmarks_iter!(
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* { $( $instance )? } $name )
( $( $names_extra )* )
Expand All @@ -312,34 +332,34 @@ macro_rules! benchmarks_iter {
};
// iteration-exit arm
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
) => {
$crate::selected_benchmark!(
{ $( $where_clause)* }
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$( $names )*
);
$crate::impl_benchmark!(
{ $( $where_clause )* }
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
( $( $names )* )
( $( $names_extra ),* )
);
};
// add verify block to _() format
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: _ ( $origin:expr $( , $arg:expr )* )
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* )
Expand All @@ -350,15 +370,15 @@ macro_rules! benchmarks_iter {
};
// add verify block to name() format
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: $dispatch:ident ( $origin:expr $( , $arg:expr )* )
$( $rest:tt )*
) => {
$crate::benchmarks_iter! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* )
Expand All @@ -369,15 +389,15 @@ macro_rules! benchmarks_iter {
};
// add verify block to {} format
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
{ $( $where_clause:tt )* }
( $( $names:tt )* )
( $( $names_extra:tt )* )
$name:ident { $( $code:tt )* }: $eval:block
$( $rest:tt )*
) => {
$crate::benchmarks_iter!(
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
{ $( $where_clause )* }
( $( $names )* )
( $( $names_extra )* )
Expand All @@ -393,7 +413,7 @@ macro_rules! benchmarks_iter {
macro_rules! benchmark_backend {
// parsing arms
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( PRE { $( $pre_parsed:tt )* } )* }
Expand All @@ -405,7 +425,7 @@ macro_rules! benchmark_backend {
$postcode:block
) => {
$crate::benchmark_backend! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
{ $( $where_clause )* }
{
Expand All @@ -418,7 +438,7 @@ macro_rules! benchmark_backend {
}
};
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $parsed:tt )* }
Expand All @@ -430,7 +450,7 @@ macro_rules! benchmark_backend {
$postcode:block
) => {
$crate::benchmark_backend! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
{ $( $where_clause )* }
{
Expand All @@ -444,7 +464,7 @@ macro_rules! benchmark_backend {
};
// mutation arm to look after a single tt for param_from.
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $parsed:tt )* }
Expand All @@ -456,7 +476,7 @@ macro_rules! benchmark_backend {
$postcode:block
) => {
$crate::benchmark_backend! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
{ $( $where_clause )* }
{ $( $parsed )* }
Expand All @@ -470,7 +490,7 @@ macro_rules! benchmark_backend {
};
// mutation arm to look after the default tail of `=> ()`
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $parsed:tt )* }
Expand All @@ -482,7 +502,7 @@ macro_rules! benchmark_backend {
$postcode:block
) => {
$crate::benchmark_backend! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
{ $( $where_clause )* }
{ $( $parsed )* }
Expand All @@ -496,7 +516,7 @@ macro_rules! benchmark_backend {
};
// mutation arm to look after `let _ =`
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
{ $( $where_clause:tt )* }
{ $( $parsed:tt )* }
Expand All @@ -508,7 +528,7 @@ macro_rules! benchmark_backend {
$postcode:block
) => {
$crate::benchmark_backend! {
{ $( $instance)? }
{ $( $instance: $instance_bound )? }
$name
{ $( $where_clause )* }
{ $( $parsed )* }
Expand All @@ -522,7 +542,7 @@ macro_rules! benchmark_backend {
};
// actioning arm
(
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
{ $( $where_clause:tt )* }
{
Expand All @@ -536,7 +556,7 @@ macro_rules! benchmark_backend {
#[allow(non_camel_case_types)]
struct $name;
#[allow(unused_variables)]
impl<T: Config $( <$instance>, I: Instance)? >
impl<T: Config $( <$instance>, $instance: $instance_bound )? >
$crate::BenchmarkingSetup<T $(, $instance)? > for $name
where $( $where_clause )*
{
Expand Down Expand Up @@ -597,7 +617,7 @@ macro_rules! benchmark_backend {
macro_rules! selected_benchmark {
(
{ $( $where_clause:tt )* }
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$( { $( $bench_inst:ident )? } $bench:ident )*
) => {
// The list of available benchmarks for this pallet.
Expand All @@ -607,7 +627,7 @@ macro_rules! selected_benchmark {
}

// Allow us to select a benchmark from the list of available benchmarks.
impl<T: Config $( <$instance>, I: Instance )? >
impl<T: Config $( <$instance>, $instance: $instance_bound )? >
$crate::BenchmarkingSetup<T $(, $instance )? > for SelectedBenchmark
where $( $where_clause )*
{
Expand Down Expand Up @@ -643,11 +663,11 @@ macro_rules! selected_benchmark {
macro_rules! impl_benchmark {
(
{ $( $where_clause:tt )* }
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
( $( { $( $name_inst:ident )? } $name:ident )* )
( $( $name_extra:ident ),* )
) => {
impl<T: Config $(<$instance>, I: Instance)? >
impl<T: Config $(<$instance>, $instance: $instance_bound )? >
$crate::Benchmarking<$crate::BenchmarkResults> for Module<T $(, $instance)? >
where T: frame_system::Config, $( $where_clause )*
{
Expand Down Expand Up @@ -866,7 +886,7 @@ macro_rules! impl_benchmark {
macro_rules! impl_benchmark_test {
(
{ $( $where_clause:tt )* }
{ $( $instance:ident )? }
{ $( $instance:ident: $instance_bound:tt )? }
$name:ident
) => {
$crate::paste::item! {
Expand Down
4 changes: 2 additions & 2 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::*;
use frame_system::RawOrigin as SystemOrigin;
use frame_system::EventRecord;
use frame_benchmarking::{
benchmarks_instance,
benchmarks_instance_pallet,
account,
whitelisted_caller,
impl_benchmark_test_suite,
Expand All @@ -46,7 +46,7 @@ fn assert_last_event<T: Config<I>, I: Instance>(generic_event: <T as Config<I>>:
assert_eq!(event, &system_event);
}

benchmarks_instance! {
benchmarks_instance_pallet! {
set_members {
let m in 1 .. T::MaxMembers::get();
let n in 1 .. T::MaxMembers::get();
Expand Down
Loading