mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 12:37:57 +00:00
Updates Benchmark macro parsing to use Generic Argument (#13919)
* WIP Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Removes POC code * Adds assertion and UT * adds runtime error * removes const_assert * ".git/.scripts/commands/fmt/fmt.sh" --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: command-bot <>
This commit is contained in:
@@ -28,9 +28,9 @@ use syn::{
|
||||
punctuated::Punctuated,
|
||||
spanned::Spanned,
|
||||
token::{Comma, Gt, Lt, PathSep},
|
||||
Attribute, Error, Expr, ExprBlock, ExprCall, ExprPath, FnArg, Item, ItemFn, ItemMod, LitInt,
|
||||
Pat, Path, PathArguments, PathSegment, Result, ReturnType, Signature, Stmt, Token, Type,
|
||||
TypePath, Visibility, WhereClause,
|
||||
Attribute, Error, Expr, ExprBlock, ExprCall, ExprPath, FnArg, Item, ItemFn, ItemMod, Pat, Path,
|
||||
PathArguments, PathSegment, Result, ReturnType, Signature, Stmt, Token, Type, TypePath,
|
||||
Visibility, WhereClause,
|
||||
};
|
||||
|
||||
mod keywords {
|
||||
@@ -54,17 +54,17 @@ mod keywords {
|
||||
struct ParamDef {
|
||||
name: String,
|
||||
typ: Type,
|
||||
start: u32,
|
||||
end: u32,
|
||||
start: syn::GenericArgument,
|
||||
end: syn::GenericArgument,
|
||||
}
|
||||
|
||||
/// Allows easy parsing of the `<10, 20>` component of `x: Linear<10, 20>`.
|
||||
#[derive(Parse)]
|
||||
struct RangeArgs {
|
||||
_lt_token: Lt,
|
||||
start: LitInt,
|
||||
start: syn::GenericArgument,
|
||||
_comma: Comma,
|
||||
end: LitInt,
|
||||
end: syn::GenericArgument,
|
||||
_gt_token: Gt,
|
||||
}
|
||||
|
||||
@@ -228,17 +228,8 @@ fn parse_params(item_fn: &ItemFn) -> Result<Vec<ParamDef>> {
|
||||
let Some(segment) = tpath.path.segments.last() else { return invalid_param(typ.span()) };
|
||||
let args = segment.arguments.to_token_stream().into();
|
||||
let Ok(args) = syn::parse::<RangeArgs>(args) else { return invalid_param(typ.span()) };
|
||||
let Ok(start) = args.start.base10_parse::<u32>() else { return invalid_param(args.start.span()) };
|
||||
let Ok(end) = args.end.base10_parse::<u32>() else { return invalid_param(args.end.span()) };
|
||||
|
||||
if end < start {
|
||||
return Err(Error::new(
|
||||
args.start.span(),
|
||||
"The start of a `ParamRange` must be less than or equal to the end",
|
||||
))
|
||||
}
|
||||
|
||||
params.push(ParamDef { name, typ: typ.clone(), start, end });
|
||||
params.push(ParamDef { name, typ: typ.clone(), start: args.start, end: args.end });
|
||||
}
|
||||
Ok(params)
|
||||
}
|
||||
@@ -700,8 +691,8 @@ impl UnrolledParams {
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let name = Ident::new(&p.name, Span::call_site());
|
||||
let start = p.start;
|
||||
let end = p.end;
|
||||
let start = &p.start;
|
||||
let end = &p.end;
|
||||
quote!(#name, #start, #end)
|
||||
})
|
||||
.collect();
|
||||
@@ -987,6 +978,9 @@ fn expand_benchmark(
|
||||
// Test the lowest, highest (if its different from the lowest)
|
||||
// and up to num_values-2 more equidistant values in between.
|
||||
// For 0..10 and num_values=6 this would mean: [0, 2, 4, 6, 8, 10]
|
||||
if high < low {
|
||||
return Err("The start of a `ParamRange` must be less than or equal to the end".into());
|
||||
}
|
||||
|
||||
let mut values = #krate::vec![low];
|
||||
let diff = (high - low).min(num_values - 1);
|
||||
|
||||
Reference in New Issue
Block a user