diff --git a/prdoc/pr_9354.prdoc b/prdoc/pr_9354.prdoc new file mode 100644 index 0000000000000..d699bbef14551 --- /dev/null +++ b/prdoc/pr_9354.prdoc @@ -0,0 +1,8 @@ +title: Remove whitespaces added by macros due to token re-parsing +doc: +- audience: Runtime Dev + description: |- + Normalize result of `stringify` in scenarios when used inside nested macros to stringify token streams for benchmarking framework +crates: +- name: frame-benchmarking + bump: patch diff --git a/substrate/frame/benchmarking/src/v1.rs b/substrate/frame/benchmarking/src/v1.rs index a6b155f4a1908..a6c1a67e34ff2 100644 --- a/substrate/frame/benchmarking/src/v1.rs +++ b/substrate/frame/benchmarking/src/v1.rs @@ -1817,8 +1817,8 @@ pub fn show_benchmark_debug_info( #[macro_export] macro_rules! add_benchmark { ( $params:ident, $batches:ident, $name:path, $location:ty ) => { - let name_string = stringify!($name).as_bytes(); - let instance_string = stringify!($location).as_bytes(); + let pallet_string = stringify!($name).replace(" ", "").into_bytes(); + let instance_string = stringify!($location).replace(" ", "").into_bytes(); let (config, whitelist) = $params; let $crate::BenchmarkConfig { pallet, @@ -1827,7 +1827,7 @@ macro_rules! add_benchmark { verify, internal_repeats, } = config; - if &pallet[..] == &name_string[..] { + if &pallet[..] == &pallet_string[..] { let benchmark_result = <$location>::run_benchmark( &benchmark[..], &selected_components[..], @@ -1850,7 +1850,7 @@ macro_rules! add_benchmark { }, Err($crate::BenchmarkError::Stop(e)) => { $crate::show_benchmark_debug_info( - instance_string, + &instance_string, benchmark, selected_components, verify, @@ -1881,8 +1881,8 @@ macro_rules! add_benchmark { if let Some(final_results) = final_results { $batches.push($crate::BenchmarkBatch { - pallet: name_string.to_vec(), - instance: instance_string.to_vec(), + pallet: pallet_string, + instance: instance_string, benchmark: benchmark.clone(), results: final_results, }); @@ -1913,12 +1913,12 @@ macro_rules! add_benchmark { #[macro_export] macro_rules! list_benchmark { ( $list:ident, $extra:ident, $name:path, $location:ty ) => { - let pallet_string = stringify!($name).as_bytes(); - let instance_string = stringify!($location).as_bytes(); + let pallet_string = stringify!($name).replace(" ", "").into_bytes(); + let instance_string = stringify!($location).replace(" ", "").into_bytes(); let benchmarks = <$location>::benchmarks($extra); let pallet_benchmarks = BenchmarkList { - pallet: pallet_string.to_vec(), - instance: instance_string.to_vec(), + pallet: pallet_string, + instance: instance_string, benchmarks: benchmarks.to_vec(), }; $list.push(pallet_benchmarks)