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

generation of real benchmark functions for benchmarking v2 #13224

Merged
merged 42 commits into from
Feb 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5214c62
function generation with _name working, need to modify signature
sam0x17 Jan 24, 2023
7b84838
WIP
sam0x17 Feb 4, 2023
c7110fb
support custom BenchmarkResult<T> type
sam0x17 Feb 9, 2023
ebd6206
full support for BenchmarkResult<T> on benchmark function defs
sam0x17 Feb 9, 2023
80fef06
support () return type for benchmark function defs that don't use ?
sam0x17 Feb 9, 2023
b812762
uncomment
sam0x17 Feb 9, 2023
e33b00a
fix where clause handling
sam0x17 Feb 9, 2023
da30b03
fix benchmark function call bodies
sam0x17 Feb 9, 2023
3e37c0d
proper parsing of return type
sam0x17 Feb 11, 2023
5de194d
add UI tests for bad return type
sam0x17 Feb 11, 2023
a0d93dc
fix detection of missing last_stmt with defined return type
sam0x17 Feb 11, 2023
4b20793
UI tests covering missing last_stmt
sam0x17 Feb 11, 2023
fc3ccfb
properly detect and complain about empty benchmark function defs
sam0x17 Feb 13, 2023
d409eda
fix missing Comma in Result<T, BenchmarkError> parsing + test
sam0x17 Feb 13, 2023
37f986b
add additional UI test
sam0x17 Feb 13, 2023
fe4f234
allow complex path for BenchmarkResult and BenchmarkError in fn defs
sam0x17 Feb 13, 2023
a773e7f
add UI tests covering complex path for BenchmarkResult, BenchmarkError
sam0x17 Feb 14, 2023
1261327
retain doc comments and attributes
sam0x17 Feb 14, 2023
a2c2274
also add attributes to struct
sam0x17 Feb 14, 2023
550f97a
add docs for benchmark function definition support
sam0x17 Feb 14, 2023
4c41f4e
fix imports on benchmark example
sam0x17 Feb 14, 2023
4e6bcb9
fix issue with unused variables in extrinsic call fn def
sam0x17 Feb 14, 2023
9c10c4c
fix up docs
sam0x17 Feb 15, 2023
2ff8eda
remove support for v2::BenchmarkResult because it was confusing
sam0x17 Feb 15, 2023
460ed3c
fix typo
sam0x17 Feb 15, 2023
16f2e4c
remove ability to use custom T for Result<T, BenchmarkError> in v2
sam0x17 Feb 17, 2023
14de958
use missing call error instead of empty_fn()
sam0x17 Feb 17, 2023
db8a68a
remove unneeded match statement
sam0x17 Feb 18, 2023
edd3dd7
Add a proper QED
sam0x17 Feb 20, 2023
da10ba1
fix other QED
sam0x17 Feb 20, 2023
d8b2e8c
cargo fmt
sam0x17 Feb 21, 2023
1e74d11
add an explicit error for non TypePath as return type
sam0x17 Feb 21, 2023
b3bdbd6
tweak error warning and add a UI test for non TypePath return
sam0x17 Feb 21, 2023
20bf0fc
remove comment
sam0x17 Feb 21, 2023
ef739b2
add docs about T and I generic params
sam0x17 Feb 21, 2023
0ce80e1
improve docs referring to section "below"
sam0x17 Feb 21, 2023
46e6883
pull out return type checking logic into its own function
sam0x17 Feb 21, 2023
27df864
pull out params parsing into its own function
sam0x17 Feb 21, 2023
fb05d87
pull out call_def parsing into its own function
sam0x17 Feb 21, 2023
abe495b
add doc comment for missing_call()
sam0x17 Feb 21, 2023
de6cc9d
replace spaces with tabs
sam0x17 Feb 21, 2023
60e9841
add a result-based example to the benchmarking examples
sam0x17 Feb 21, 2023
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
Prev Previous commit
Next Next commit
fix benchmark function call bodies
  • Loading branch information
sam0x17 committed Feb 14, 2023
commit da30b0347303a5732338e337fb40d0bf54003ee2
23 changes: 13 additions & 10 deletions frame/support/procedural/src/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,8 @@ fn expand_benchmark(
true => quote!(T: Config<I>, I: 'static),
};

let (pre_call, post_call) = match benchmark_def.call_def {
// used in the benchmarking impls
let (pre_call, post_call, fn_call_body) = match &benchmark_def.call_def {
BenchmarkCallDef::ExtrinsicCall { origin, expr_call, attr_span: _ } => {
let mut expr_call = expr_call.clone();

Expand Down Expand Up @@ -742,13 +743,13 @@ fn expand_benchmark(
qself: None,
path: Path { leading_colon: None, segments: punct },
});

let pre_call = quote! {
let __call = Call::<#type_use_generics>::#expr_call;
let __benchmarked_call_encoded = #codec::Encode::encode(&__call);
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
};
(
// (pre_call, post_call):
quote! {
let __call = Call::<#type_use_generics>::#expr_call;
let __benchmarked_call_encoded = #codec::Encode::encode(&__call);
},
// (pre_call, post_call, fn_call_body):
pre_call.clone(),
quote! {
let __call_decoded = <Call<#type_use_generics> as #codec::Decode>
::decode(&mut &__benchmarked_call_encoded[..])
Expand All @@ -759,18 +760,20 @@ fn expand_benchmark(
__origin,
)?;
},
pre_call,
)
},
BenchmarkCallDef::Block { block, attr_span: _ } => (quote!(), quote!(#block)),
BenchmarkCallDef::Block { block, attr_span: _ } =>
(quote!(), quote!(#block), quote!(#block)),
};

let vis = benchmark_def.fn_vis;
let mut sig = benchmark_def.fn_sig;

// modify signature generics, ident, and inputs, e.g:
// before: `fn bench(u: Linear<1, 100>) -> BenchmarkResult<()>`
// after: `fn _bench <T: Config<I>, I: 'static>(u: u32, verify: bool) ->
// BenchmarkResult<()>`
let mut sig = benchmark_def.fn_sig;
sig.generics = parse_quote!(<#type_impl_generics>);
if !where_clause.is_empty() {
sig.generics.where_clause = parse_quote!(where #where_clause);
Expand All @@ -795,7 +798,7 @@ fn expand_benchmark(
#(
#setup_stmts
)*
#pre_call
#fn_call_body
if verify {
#(
#verify_stmts
Expand Down