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

Commit

Permalink
basic detection of benchmarking(cached) 💥
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0x17 committed Sep 6, 2022
1 parent e1e95e7 commit 63b2a1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ mod storage_alias;
mod transactional;
mod tt_macro;

use crate::storage_alias::Input;
use proc_macro::TokenStream;
use std::{cell::RefCell, str::FromStr};
pub(crate) use storage::INHERENT_INSTANCE_NAME;
Expand Down Expand Up @@ -595,8 +594,9 @@ pub fn benchmarking(attr: TokenStream, item: TokenStream) -> TokenStream {
}

fn benchmarking_cached(item: TokenStream) -> TokenStream {
let input = syn::parse2::<Input>(item.clone().into())
// re-use storage_alias's Input parser since it is accessible
// and valid for all storage item declarations
syn::parse2::<crate::storage_alias::Input>(item.clone().into())
.expect("benchmarking(cached) can only be attached to a valid storage type declaration");
println!("{}", input.storage_name);
item
}
13 changes: 11 additions & 2 deletions frame/support/procedural/src/pallet/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod type_value;
pub mod validate_unsigned;

use frame_support_procedural_tools::generate_crate_access_2018;
use quote::ToTokens;
use syn::spanned::Spanned;

/// Parsed definition of a pallet.
Expand Down Expand Up @@ -123,8 +124,16 @@ impl Def {
origin = Some(origin::OriginDef::try_from(index, item)?),
Some(PalletAttr::Inherent(_)) if inherent.is_none() =>
inherent = Some(inherent::InherentDef::try_from(index, item)?),
Some(PalletAttr::Storage(span)) =>
storages.push(storage::StorageDef::try_from(span, index, item)?),
Some(PalletAttr::Storage(span)) => {
let st = item.to_token_stream().to_string();
let storage_def = storage::StorageDef::try_from(span, index, item)?;
if st.contains("#[benchmarking(cached)]") {
println!("{} cached!", storage_def.ident.to_string());
} else {
println!("{} NOT cached!", storage_def.ident.to_string());
}
storages.push(storage_def)
},
Some(PalletAttr::ValidateUnsigned(_)) if validate_unsigned.is_none() => {
let v = validate_unsigned::ValidateUnsignedDef::try_from(index, item)?;
validate_unsigned = Some(v);
Expand Down
3 changes: 2 additions & 1 deletion frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ pub use hooks::{
pub mod schedule;
mod storage;
pub use storage::{
Instance, PartialStorageInfoTrait, StorageInfo, StorageInfoTrait, StorageInstance, WhitelistedStorageKeys
Instance, PartialStorageInfoTrait, StorageInfo, StorageInfoTrait, StorageInstance,
WhitelistedStorageKeys,
};

mod dispatch;
Expand Down

0 comments on commit 63b2a1d

Please sign in to comment.