Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
frame-benchmarking: Macros should not force a particular env (#13161)
Browse files Browse the repository at this point in the history
The macros in frame-benchmarking relied on having all the macros imported, which isn't a behavior
for a proper macro :D This pr fixes this by making all internal macro usages absolute.
  • Loading branch information
bkchr authored and Ross Bulat committed Feb 3, 2023
1 parent 1caa837 commit f6136e1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
6 changes: 1 addition & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,13 +1823,9 @@ mod mmr {
pub type Hashing = <Runtime as pallet_mmr::Config>::Hashing;
}

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;

#[cfg(feature = "runtime-benchmarks")]
mod benches {
define_benchmarks!(
frame_benchmarking::define_benchmarks!(
[frame_benchmarking, BaselineBench::<Runtime>]
[pallet_alliance, Alliance]
[pallet_assets, Assets]
Expand Down
49 changes: 24 additions & 25 deletions frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,15 +1836,15 @@ macro_rules! add_benchmark {
/// Callback for `define_benchmarks` to call `add_benchmark`.
#[macro_export]
macro_rules! cb_add_benchmarks {
// anchor
// anchor
( $params:ident, $batches:ident, [ $name:path, $( $location:tt )* ] ) => {
add_benchmark!( $params, $batches, $name, $( $location )* );
$crate::add_benchmark!( $params, $batches, $name, $( $location )* );
};
// recursion tail
// recursion tail
( $params:ident, $batches:ident, [ $name:path, $( $location:tt )* ] $([ $names:path, $( $locations:tt )* ])+ ) => {
cb_add_benchmarks!( $params, $batches, [ $name, $( $location )* ] );
cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
}
$crate::cb_add_benchmarks!( $params, $batches, [ $name, $( $location )* ] );
$crate::cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
}
}

/// This macro allows users to easily generate a list of benchmarks for the pallets configured
Expand Down Expand Up @@ -1884,24 +1884,23 @@ macro_rules! list_benchmark {
/// Callback for `define_benchmarks` to call `list_benchmark`.
#[macro_export]
macro_rules! cb_list_benchmarks {
// anchor
// anchor
( $list:ident, $extra:ident, [ $name:path, $( $location:tt )* ] ) => {
list_benchmark!( $list, $extra, $name, $( $location )* );
$crate::list_benchmark!( $list, $extra, $name, $( $location )* );
};
// recursion tail
// recursion tail
( $list:ident, $extra:ident, [ $name:path, $( $location:tt )* ] $([ $names:path, $( $locations:tt )* ])+ ) => {
cb_list_benchmarks!( $list, $extra, [ $name, $( $location )* ] );
cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
}
$crate::cb_list_benchmarks!( $list, $extra, [ $name, $( $location )* ] );
$crate::cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
}
}

/// Defines pallet configs that `add_benchmarks` and `list_benchmarks` use.
/// Should be preferred instead of having a repetitive list of configs
/// in `add_benchmark` and `list_benchmark`.
#[macro_export]
macro_rules! define_benchmarks {
( $([ $names:path, $( $locations:tt )* ])* ) => {
( $([ $names:path, $( $locations:tt )* ])* ) => {
/// Calls `list_benchmark` with all configs from `define_benchmarks`
/// and passes the first two parameters on.
///
Expand All @@ -1910,11 +1909,11 @@ macro_rules! define_benchmarks {
/// list_benchmarks!(list, extra);
/// ```
#[macro_export]
macro_rules! list_benchmarks {
( $list:ident, $extra:ident ) => {
cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
}
}
macro_rules! list_benchmarks {
( $list:ident, $extra:ident ) => {
$crate::cb_list_benchmarks!( $list, $extra, $([ $names, $( $locations )* ])+ );
}
}

/// Calls `add_benchmark` with all configs from `define_benchmarks`
/// and passes the first two parameters on.
Expand All @@ -1924,10 +1923,10 @@ macro_rules! define_benchmarks {
/// add_benchmarks!(params, batches);
/// ```
#[macro_export]
macro_rules! add_benchmarks {
( $params:ident, $batches:ident ) => {
cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
}
}
}
macro_rules! add_benchmarks {
( $params:ident, $batches:ident ) => {
$crate::cb_add_benchmarks!( $params, $batches, $([ $names, $( $locations )* ])+ );
}
}
}
}

0 comments on commit f6136e1

Please sign in to comment.