From 5d0760879ec7181da9602e4553fa97afaa685e26 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Mon, 11 Jul 2022 12:22:40 +0100 Subject: [PATCH 01/13] flratten AllPallets types --- .../procedural/src/construct_runtime/mod.rs | 54 ++++++------------- .../src/pallet/expand/pallet_struct.rs | 6 +-- frame/support/src/dispatch.rs | 4 +- frame/support/src/migrations.rs | 2 +- frame/support/src/traits/filter.rs | 2 +- frame/support/src/traits/hooks.rs | 10 ++-- frame/support/src/traits/metadata.rs | 42 +++++---------- frame/support/src/traits/misc.rs | 2 +- frame/support/src/traits/storage.rs | 2 +- frame/support/test/tests/pallet.rs | 10 ++-- 10 files changed, 46 insertions(+), 88 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 7b4156a94db58..4f90543309f50 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -308,47 +308,26 @@ fn decl_all_pallets<'a>( names.push(&pallet_declaration.name); } - // Make nested tuple structure like: - // `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))` - // But ignore the system pallet. - let all_pallets_without_system = names - .iter() - .filter(|n| **n != SYSTEM_PALLET_NAME) - .rev() - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); - - // Make nested tuple structure like: - // `((FirstPallet, (SecondPallet, ( ... , LastPallet) ... ))))` - let all_pallets_with_system = names - .iter() - .rev() - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); - - // Make nested tuple structure like: - // `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))` - // But ignore the system pallet. - let all_pallets_without_system_reversed = names - .iter() - .filter(|n| **n != SYSTEM_PALLET_NAME) - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); - - // Make nested tuple structure like: - // `((LastPallet, (SecondLastPallet, ( ... , FirstPallet) ... ))))` - let all_pallets_with_system_reversed = names - .iter() - .fold(TokenStream2::default(), |combined, name| quote!((#name, #combined))); - let system_pallet = match names.iter().find(|n| **n == SYSTEM_PALLET_NAME) { Some(name) => name, None => return syn::Error::new( proc_macro2::Span::call_site(), "`System` pallet declaration is missing. \ - Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},`", + Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event},`", ) .into_compile_error(), }; + let names_without_system = + names.iter().filter(|n| **n != SYSTEM_PALLET_NAME).collect::>(); + let names_reversed = names.clone().into_iter().rev().collect::>(); + let names_without_system_reverse = + names_without_system.clone().into_iter().rev().collect::>(); + let names_reversed_with_system_first = std::iter::once(system_pallet) + .chain(names_without_system_reverse.clone().into_iter()) + .collect::>(); + quote!( #types @@ -364,25 +343,22 @@ fn decl_all_pallets<'a>( pub type AllPallets = AllPalletsWithSystem; /// All pallets included in the runtime as a nested tuple of types. - pub type AllPalletsWithSystem = ( #all_pallets_with_system ); + pub type AllPalletsWithSystem = ( #(#names),* ); /// All pallets included in the runtime as a nested tuple of types. /// Excludes the System pallet. - pub type AllPalletsWithoutSystem = ( #all_pallets_without_system ); + pub type AllPalletsWithoutSystem = ( #(#names_without_system),* ); /// All pallets included in the runtime as a nested tuple of types in reversed order. /// Excludes the System pallet. - pub type AllPalletsWithoutSystemReversed = ( #all_pallets_without_system_reversed ); + pub type AllPalletsWithoutSystemReversed =( #(#names_without_system_reverse),* ); /// All pallets included in the runtime as a nested tuple of types in reversed order. - pub type AllPalletsWithSystemReversed = ( #all_pallets_with_system_reversed ); + pub type AllPalletsWithSystemReversed = ( #(#names_reversed),* ); /// All pallets included in the runtime as a nested tuple of types in reversed order. /// With the system pallet first. - pub type AllPalletsReversedWithSystemFirst = ( - #system_pallet, - AllPalletsWithoutSystemReversed - ); + pub type AllPalletsReversedWithSystemFirst = ( #(#names_reversed_with_system_first),* ); ) } diff --git a/frame/support/procedural/src/pallet/expand/pallet_struct.rs b/frame/support/procedural/src/pallet/expand/pallet_struct.rs index 52586a70a521a..cd0691e06afc2 100644 --- a/frame/support/procedural/src/pallet/expand/pallet_struct.rs +++ b/frame/support/procedural/src/pallet/expand/pallet_struct.rs @@ -240,9 +240,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream { #config_where_clause { fn count() -> usize { 1 } - fn accumulate( - acc: &mut #frame_support::sp_std::vec::Vec<#frame_support::traits::PalletInfoData> - ) { + fn infos() -> #frame_support::sp_std::vec::Vec<#frame_support::traits::PalletInfoData> { use #frame_support::traits::PalletInfoAccess; let item = #frame_support::traits::PalletInfoData { index: Self::index(), @@ -250,7 +248,7 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream { module_name: Self::module_name(), crate_version: Self::crate_version(), }; - acc.push(item); + #frame_support::sp_std::vec![item] } } diff --git a/frame/support/src/dispatch.rs b/frame/support/src/dispatch.rs index c175998956ff2..cdf5f1d73d51a 100644 --- a/frame/support/src/dispatch.rs +++ b/frame/support/src/dispatch.rs @@ -2204,7 +2204,7 @@ macro_rules! decl_module { for $mod_type<$trait_instance $(, $instance)?> where $( $other_where_bounds )* { fn count() -> usize { 1 } - fn accumulate(acc: &mut $crate::sp_std::vec::Vec<$crate::traits::PalletInfoData>) { + fn infos() -> $crate::sp_std::vec::Vec<$crate::traits::PalletInfoData> { use $crate::traits::PalletInfoAccess; let item = $crate::traits::PalletInfoData { index: Self::index(), @@ -2212,7 +2212,7 @@ macro_rules! decl_module { module_name: Self::module_name(), crate_version: Self::crate_version(), }; - acc.push(item); + vec![item] } } diff --git a/frame/support/src/migrations.rs b/frame/support/src/migrations.rs index 05833e0515c07..373dc836aefe4 100644 --- a/frame/support/src/migrations.rs +++ b/frame/support/src/migrations.rs @@ -42,7 +42,7 @@ impl PalletVersionToStorageVersionHelpe } } -#[impl_trait_for_tuples::impl_for_tuples(30)] +#[impl_trait_for_tuples::impl_for_tuples(100)] impl PalletVersionToStorageVersionHelper for T { fn migrate(db_weight: &RuntimeDbWeight) -> Weight { let mut weight: Weight = 0; diff --git a/frame/support/src/traits/filter.rs b/frame/support/src/traits/filter.rs index 95e5954184b4b..7a22086f16c86 100644 --- a/frame/support/src/traits/filter.rs +++ b/frame/support/src/traits/filter.rs @@ -183,7 +183,7 @@ macro_rules! impl_filter_stack { /// Type that provide some integrity tests. /// /// This implemented for modules by `decl_module`. -#[impl_trait_for_tuples::impl_for_tuples(30)] +#[impl_trait_for_tuples::impl_for_tuples(100)] pub trait IntegrityTest { /// Run integrity test. /// diff --git a/frame/support/src/traits/hooks.rs b/frame/support/src/traits/hooks.rs index 385db4e4d1ad9..3ec479f55b75d 100644 --- a/frame/support/src/traits/hooks.rs +++ b/frame/support/src/traits/hooks.rs @@ -38,7 +38,7 @@ pub trait OnInitialize { } } -#[impl_for_tuples(30)] +#[impl_for_tuples(100)] impl OnInitialize for Tuple { fn on_initialize(n: BlockNumber) -> crate::weights::Weight { let mut weight = 0; @@ -50,7 +50,7 @@ impl OnInitialize for Tuple { /// The block finalization trait. /// /// Implementing this lets you express what should happen for your pallet when the block is ending. -#[impl_for_tuples(30)] +#[impl_for_tuples(100)] pub trait OnFinalize { /// The block is being finalized. Implement to have something happen. /// @@ -79,7 +79,7 @@ pub trait OnIdle { } } -#[impl_for_tuples(30)] +#[impl_for_tuples(100)] impl OnIdle for Tuple { fn on_idle(n: BlockNumber, remaining_weight: crate::weights::Weight) -> crate::weights::Weight { let on_idle_functions: &[fn( @@ -105,7 +105,7 @@ impl OnIdle for Tuple { /// Implementing this trait for a pallet let's you express operations that should /// happen at genesis. It will be called in an externalities provided environment and /// will see the genesis state after all pallets have written their genesis state. -#[impl_for_tuples(30)] +#[impl_for_tuples(100)] pub trait OnGenesis { /// Something that should happen at genesis. fn on_genesis() {} @@ -187,7 +187,7 @@ pub trait OnRuntimeUpgrade { } } -#[impl_for_tuples(30)] +#[impl_for_tuples(100)] impl OnRuntimeUpgrade for Tuple { fn on_runtime_upgrade() -> crate::weights::Weight { let mut weight = 0; diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index d3dc57e1ee52d..17eef15317871 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -70,40 +70,24 @@ pub trait PalletsInfoAccess { /// /// You probably don't want this function but `infos()` instead. fn count() -> usize { - 0 + // for backwards compatibility with XCM-3, Mark is deprecated. + Self::infos().len() } - /// Extend the given vector by all of the pallets' information that this type represents. - /// - /// You probably don't want this function but `infos()` instead. - fn accumulate(_accumulator: &mut Vec) {} - /// All of the pallets' information that this type represents. - fn infos() -> Vec { - let mut result = Vec::with_capacity(Self::count()); - Self::accumulate(&mut result); - result - } + fn infos() -> Vec; } -impl PalletsInfoAccess for () {} -impl PalletsInfoAccess for (T,) { - fn count() -> usize { - T::count() - } - fn accumulate(acc: &mut Vec) { - T::accumulate(acc) - } -} - -impl PalletsInfoAccess for (T1, T2) { - fn count() -> usize { - T1::count() + T2::count() - } - fn accumulate(acc: &mut Vec) { - // The AllPallets type tuplises the pallets in reverse order, so we unreverse them here. - T2::accumulate(acc); - T1::accumulate(acc); +// TODO: this and needing to implement `PalletsInfoAccess` for any individual pallet is kinda wrong. +// all we need is: +// Impl PalletsInfoAccess for (T) {} +// Impl PalletsInfoAccess for (T, T1) {} +#[impl_trait_for_tuples::impl_for_tuples(100)] +impl PalletsInfoAccess for Tuple { + fn infos() -> Vec { + let mut res = vec![]; + for_tuples!( #( res.extend_from_slice(&Tuple::infos()); )* ); + res } } diff --git a/frame/support/src/traits/misc.rs b/frame/support/src/traits/misc.rs index ccbb47909d5f4..8df2a4a13274c 100644 --- a/frame/support/src/traits/misc.rs +++ b/frame/support/src/traits/misc.rs @@ -632,7 +632,7 @@ impl PrivilegeCmp for EqualPrivilegeOnly { /// but cannot preform any alterations. More specifically alterations are /// not forbidden, but they are not persisted in any way after the worker /// has finished. -#[impl_trait_for_tuples::impl_for_tuples(30)] +#[impl_trait_for_tuples::impl_for_tuples(100)] pub trait OffchainWorker { /// This function is being called after every block import (when fully synced). /// diff --git a/frame/support/src/traits/storage.rs b/frame/support/src/traits/storage.rs index e484140cc2fd9..765350a04dab1 100644 --- a/frame/support/src/traits/storage.rs +++ b/frame/support/src/traits/storage.rs @@ -71,7 +71,7 @@ pub trait StorageInfoTrait { fn storage_info() -> Vec; } -#[impl_trait_for_tuples::impl_for_tuples(30)] +#[impl_trait_for_tuples::impl_for_tuples(100)] impl StorageInfoTrait for Tuple { fn storage_info() -> Vec { let mut res = vec![]; diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 6b72327eb4989..1b6036e584e33 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1598,7 +1598,7 @@ fn test_storage_info() { fn assert_type_all_pallets_reversed_with_system_first_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsReversedWithSystemFirst) {} - fn _b(t: (System, (Example4, (Example2, (Example,))))) { + fn _b(t: (System, Example4, Example2, Example,)) { _a(t) } } @@ -1607,7 +1607,7 @@ fn assert_type_all_pallets_reversed_with_system_first_is_correct() { fn assert_type_all_pallets_with_system_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithSystem) {} - fn _b(t: (System, (Example, (Example2, (Example4,))))) { + fn _b(t: (System, Example, Example2, Example4,)) { _a(t) } } @@ -1616,7 +1616,7 @@ fn assert_type_all_pallets_with_system_is_correct() { fn assert_type_all_pallets_without_system_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithoutSystem) {} - fn _b(t: (Example, (Example2, (Example4,)))) { + fn _b(t: (Example, Example2, Example4,)) { _a(t) } } @@ -1625,7 +1625,7 @@ fn assert_type_all_pallets_without_system_is_correct() { fn assert_type_all_pallets_with_system_reversed_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithSystemReversed) {} - fn _b(t: (Example4, (Example2, (Example, (System,))))) { + fn _b(t: (Example4, Example2, Example, System,)) { _a(t) } } @@ -1634,7 +1634,7 @@ fn assert_type_all_pallets_with_system_reversed_is_correct() { fn assert_type_all_pallets_without_system_reversed_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithoutSystemReversed) {} - fn _b(t: (Example4, (Example2, (Example,)))) { + fn _b(t: (Example4, Example2, Example,)) { _a(t) } } From f46e6485c8ab31a03ac6804ff3078c24b851237c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sat, 30 Jul 2022 14:25:47 +0100 Subject: [PATCH 02/13] feature flag it --- frame/support/Cargo.toml | 4 +++ frame/support/src/traits.rs | 5 ++-- frame/support/src/traits/filter.rs | 11 --------- frame/support/src/traits/hooks.rs | 37 +++++++++++++++++++++++----- frame/support/src/traits/members.rs | 9 +++++-- frame/support/src/traits/metadata.rs | 5 +++- frame/support/src/traits/misc.rs | 13 +++++++--- frame/support/src/traits/storage.rs | 5 +++- frame/support/test/tests/pallet.rs | 10 ++++---- 9 files changed, 68 insertions(+), 31 deletions(-) diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index ca26d3a5e32f2..3544761cc7ece 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -71,3 +71,7 @@ no-metadata-docs = ["frame-support-procedural/no-metadata-docs"] # By default some types have documentation, `full-metadata-docs` allows to add documentation to # more types in the metadata. full-metadata-docs = ["scale-info/docs"] +# Generate impl-trait for tuples with the given number of tuples. Will be needed as the number of +# pallets in a runtime grows. Does increase the compile time! +tuples-96 = [] +tuples-128 = [] diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index db8c8da4f869b..ee6c033796df5 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -50,7 +50,7 @@ mod error; pub use error::PalletError; mod filter; -pub use filter::{ClearFilterGuard, FilterStack, FilterStackGuard, InstanceFilter, IntegrityTest}; +pub use filter::{ClearFilterGuard, FilterStack, FilterStackGuard, InstanceFilter}; mod misc; pub use misc::{ @@ -81,7 +81,8 @@ mod hooks; #[cfg(feature = "std")] pub use hooks::GenesisBuild; pub use hooks::{ - Hooks, OnFinalize, OnGenesis, OnIdle, OnInitialize, OnRuntimeUpgrade, OnTimestampSet, + Hooks, IntegrityTest, OnFinalize, OnGenesis, OnIdle, OnInitialize, OnRuntimeUpgrade, + OnTimestampSet, }; #[cfg(feature = "try-runtime")] pub use hooks::{OnRuntimeUpgradeHelpersExt, ON_RUNTIME_UPGRADE_PREFIX}; diff --git a/frame/support/src/traits/filter.rs b/frame/support/src/traits/filter.rs index 7a22086f16c86..cdd82a3124e63 100644 --- a/frame/support/src/traits/filter.rs +++ b/frame/support/src/traits/filter.rs @@ -180,17 +180,6 @@ macro_rules! impl_filter_stack { } } -/// Type that provide some integrity tests. -/// -/// This implemented for modules by `decl_module`. -#[impl_trait_for_tuples::impl_for_tuples(100)] -pub trait IntegrityTest { - /// Run integrity test. - /// - /// The test is not executed in a externalities provided environment. - fn integrity_test() {} -} - #[cfg(test)] pub mod test_impl_filter_stack { use super::*; diff --git a/frame/support/src/traits/hooks.rs b/frame/support/src/traits/hooks.rs index 3ec479f55b75d..8191285239268 100644 --- a/frame/support/src/traits/hooks.rs +++ b/frame/support/src/traits/hooks.rs @@ -38,7 +38,9 @@ pub trait OnInitialize { } } -#[impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnInitialize for Tuple { fn on_initialize(n: BlockNumber) -> crate::weights::Weight { let mut weight = 0; @@ -50,7 +52,9 @@ impl OnInitialize for Tuple { /// The block finalization trait. /// /// Implementing this lets you express what should happen for your pallet when the block is ending. -#[impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnFinalize { /// The block is being finalized. Implement to have something happen. /// @@ -79,7 +83,9 @@ pub trait OnIdle { } } -#[impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnIdle for Tuple { fn on_idle(n: BlockNumber, remaining_weight: crate::weights::Weight) -> crate::weights::Weight { let on_idle_functions: &[fn( @@ -105,7 +111,9 @@ impl OnIdle for Tuple { /// Implementing this trait for a pallet let's you express operations that should /// happen at genesis. It will be called in an externalities provided environment and /// will see the genesis state after all pallets have written their genesis state. -#[impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnGenesis { /// Something that should happen at genesis. fn on_genesis() {} @@ -187,7 +195,9 @@ pub trait OnRuntimeUpgrade { } } -#[impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnRuntimeUpgrade for Tuple { fn on_runtime_upgrade() -> crate::weights::Weight { let mut weight = 0; @@ -210,6 +220,19 @@ impl OnRuntimeUpgrade for Tuple { } } +/// Type that provide some integrity tests. +/// +/// This implemented for modules by `decl_module`. +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] +pub trait IntegrityTest { + /// Run integrity test. + /// + /// The test is not executed in a externalities provided environment. + fn integrity_test() {} +} + /// The pallet hooks trait. Implementing this lets you express some logic to execute. pub trait Hooks { /// The block is being finalized. Implement to have something happen. @@ -321,7 +344,9 @@ pub trait GenesisBuild: Default + sp_runtime::traits::MaybeSerializeD } /// A trait which is called when the timestamp is set in the runtime. -#[impl_for_tuples(30)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnTimestampSet { /// Called when the timestamp is set. fn on_timestamp_set(moment: Moment); diff --git a/frame/support/src/traits/members.rs b/frame/support/src/traits/members.rs index 8c69a2aaccb33..cb9e9285cab25 100644 --- a/frame/support/src/traits/members.rs +++ b/frame/support/src/traits/members.rs @@ -18,6 +18,7 @@ //! Traits for dealing with the idea of membership. use sp_std::{marker::PhantomData, prelude::*}; +use impl_trait_for_tuples::impl_for_tuples; /// A trait for querying whether a type can be said to "contain" a value. pub trait Contains { @@ -25,7 +26,9 @@ pub trait Contains { fn contains(t: &T) -> bool; } -#[impl_trait_for_tuples::impl_for_tuples(1, 30)] +#[impl_for_tuples(1, 64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(1, 96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(1, 128))] impl Contains for Tuple { fn contains(t: &T) -> bool { for_tuples!( #( @@ -41,7 +44,9 @@ pub trait ContainsPair { fn contains(a: &A, b: &B) -> bool; } -#[impl_trait_for_tuples::impl_for_tuples(0, 30)] +#[impl_for_tuples(0, 64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(0, 96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(0, 128))] impl ContainsPair for Tuple { fn contains(a: &A, b: &B) -> bool { for_tuples!( #( diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index 17eef15317871..a5f94de3b9db3 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -19,6 +19,7 @@ use codec::{Decode, Encode}; use sp_runtime::RuntimeDebug; +use impl_trait_for_tuples::impl_for_tuples; use sp_std::prelude::*; /// Provides information about the pallet itself and its setup in the runtime. @@ -82,7 +83,9 @@ pub trait PalletsInfoAccess { // all we need is: // Impl PalletsInfoAccess for (T) {} // Impl PalletsInfoAccess for (T, T1) {} -#[impl_trait_for_tuples::impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl PalletsInfoAccess for Tuple { fn infos() -> Vec { let mut res = vec![]; diff --git a/frame/support/src/traits/misc.rs b/frame/support/src/traits/misc.rs index 8df2a4a13274c..2afe20fe45ce9 100644 --- a/frame/support/src/traits/misc.rs +++ b/frame/support/src/traits/misc.rs @@ -21,6 +21,7 @@ use crate::dispatch::Parameter; use codec::{CompactLen, Decode, DecodeAll, Encode, EncodeLike, Input, MaxEncodedLen}; use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter}; use sp_arithmetic::traits::{CheckedAdd, CheckedMul, CheckedSub, Saturating}; +use impl_trait_for_tuples::impl_for_tuples; #[doc(hidden)] pub use sp_runtime::traits::{ ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128, ConstU16, ConstU32, @@ -467,14 +468,18 @@ impl SameOrOther { } /// Handler for when a new account has been created. -#[impl_trait_for_tuples::impl_for_tuples(30)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnNewAccount { /// A new account `who` has been registered. fn on_new_account(who: &AccountId); } /// The account with the given id was reaped. -#[impl_trait_for_tuples::impl_for_tuples(30)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnKilledAccount { /// The account with the given id was reaped. fn on_killed_account(who: &AccountId); @@ -632,7 +637,9 @@ impl PrivilegeCmp for EqualPrivilegeOnly { /// but cannot preform any alterations. More specifically alterations are /// not forbidden, but they are not persisted in any way after the worker /// has finished. -#[impl_trait_for_tuples::impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OffchainWorker { /// This function is being called after every block import (when fully synced). /// diff --git a/frame/support/src/traits/storage.rs b/frame/support/src/traits/storage.rs index 765350a04dab1..fc710f14db7c3 100644 --- a/frame/support/src/traits/storage.rs +++ b/frame/support/src/traits/storage.rs @@ -18,6 +18,7 @@ //! Traits for encoding data related to pallet's storage items. use sp_std::prelude::*; +use impl_trait_for_tuples::impl_for_tuples; /// An instance of a pallet in the storage. /// @@ -71,7 +72,9 @@ pub trait StorageInfoTrait { fn storage_info() -> Vec; } -#[impl_trait_for_tuples::impl_for_tuples(100)] +#[impl_for_tuples(64)] +#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl StorageInfoTrait for Tuple { fn storage_info() -> Vec { let mut res = vec![]; diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 1b6036e584e33..02edde3b349f4 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1598,7 +1598,7 @@ fn test_storage_info() { fn assert_type_all_pallets_reversed_with_system_first_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsReversedWithSystemFirst) {} - fn _b(t: (System, Example4, Example2, Example,)) { + fn _b(t: (System, Example4, Example2, Example)) { _a(t) } } @@ -1607,7 +1607,7 @@ fn assert_type_all_pallets_reversed_with_system_first_is_correct() { fn assert_type_all_pallets_with_system_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithSystem) {} - fn _b(t: (System, Example, Example2, Example4,)) { + fn _b(t: (System, Example, Example2, Example4)) { _a(t) } } @@ -1616,7 +1616,7 @@ fn assert_type_all_pallets_with_system_is_correct() { fn assert_type_all_pallets_without_system_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithoutSystem) {} - fn _b(t: (Example, Example2, Example4,)) { + fn _b(t: (Example, Example2, Example4)) { _a(t) } } @@ -1625,7 +1625,7 @@ fn assert_type_all_pallets_without_system_is_correct() { fn assert_type_all_pallets_with_system_reversed_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithSystemReversed) {} - fn _b(t: (Example4, Example2, Example, System,)) { + fn _b(t: (Example4, Example2, Example, System)) { _a(t) } } @@ -1634,7 +1634,7 @@ fn assert_type_all_pallets_with_system_reversed_is_correct() { fn assert_type_all_pallets_without_system_reversed_is_correct() { // Just ensure the 2 types are same. fn _a(_t: AllPalletsWithoutSystemReversed) {} - fn _b(t: (Example4, Example2, Example,)) { + fn _b(t: (Example4, Example2, Example)) { _a(t) } } From 1bb98a213f64b4f8984c43ad2b41276af9c1df6c Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 2 Aug 2022 20:00:31 +0100 Subject: [PATCH 03/13] fix --- frame/support/src/traits/hooks.rs | 14 +++++++------- frame/support/src/traits/members.rs | 4 ++-- frame/support/src/traits/metadata.rs | 4 ++-- frame/support/src/traits/misc.rs | 6 +++--- frame/support/src/traits/storage.rs | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/frame/support/src/traits/hooks.rs b/frame/support/src/traits/hooks.rs index 8191285239268..63fa6749a7626 100644 --- a/frame/support/src/traits/hooks.rs +++ b/frame/support/src/traits/hooks.rs @@ -38,7 +38,7 @@ pub trait OnInitialize { } } -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnInitialize for Tuple { @@ -52,7 +52,7 @@ impl OnInitialize for Tuple { /// The block finalization trait. /// /// Implementing this lets you express what should happen for your pallet when the block is ending. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnFinalize { @@ -83,7 +83,7 @@ pub trait OnIdle { } } -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnIdle for Tuple { @@ -111,7 +111,7 @@ impl OnIdle for Tuple { /// Implementing this trait for a pallet let's you express operations that should /// happen at genesis. It will be called in an externalities provided environment and /// will see the genesis state after all pallets have written their genesis state. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnGenesis { @@ -195,7 +195,7 @@ pub trait OnRuntimeUpgrade { } } -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnRuntimeUpgrade for Tuple { @@ -223,7 +223,7 @@ impl OnRuntimeUpgrade for Tuple { /// Type that provide some integrity tests. /// /// This implemented for modules by `decl_module`. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait IntegrityTest { @@ -344,7 +344,7 @@ pub trait GenesisBuild: Default + sp_runtime::traits::MaybeSerializeD } /// A trait which is called when the timestamp is set in the runtime. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnTimestampSet { diff --git a/frame/support/src/traits/members.rs b/frame/support/src/traits/members.rs index cb9e9285cab25..aa1b9f94cb5f5 100644 --- a/frame/support/src/traits/members.rs +++ b/frame/support/src/traits/members.rs @@ -26,7 +26,7 @@ pub trait Contains { fn contains(t: &T) -> bool; } -#[impl_for_tuples(1, 64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(1, 64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(1, 96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(1, 128))] impl Contains for Tuple { @@ -44,7 +44,7 @@ pub trait ContainsPair { fn contains(a: &A, b: &B) -> bool; } -#[impl_for_tuples(0, 64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(0, 96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(0, 128))] impl ContainsPair for Tuple { diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index a5f94de3b9db3..e1dc9ff26702c 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -81,9 +81,9 @@ pub trait PalletsInfoAccess { // TODO: this and needing to implement `PalletsInfoAccess` for any individual pallet is kinda wrong. // all we need is: -// Impl PalletsInfoAccess for (T) {} +// Impl PalletsInfoAccess for (T,) {} // Impl PalletsInfoAccess for (T, T1) {} -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl PalletsInfoAccess for Tuple { diff --git a/frame/support/src/traits/misc.rs b/frame/support/src/traits/misc.rs index 2afe20fe45ce9..738218180c219 100644 --- a/frame/support/src/traits/misc.rs +++ b/frame/support/src/traits/misc.rs @@ -468,7 +468,7 @@ impl SameOrOther { } /// Handler for when a new account has been created. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnNewAccount { @@ -477,7 +477,7 @@ pub trait OnNewAccount { } /// The account with the given id was reaped. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnKilledAccount { @@ -637,7 +637,7 @@ impl PrivilegeCmp for EqualPrivilegeOnly { /// but cannot preform any alterations. More specifically alterations are /// not forbidden, but they are not persisted in any way after the worker /// has finished. -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OffchainWorker { diff --git a/frame/support/src/traits/storage.rs b/frame/support/src/traits/storage.rs index fc710f14db7c3..433006044ed12 100644 --- a/frame/support/src/traits/storage.rs +++ b/frame/support/src/traits/storage.rs @@ -72,7 +72,7 @@ pub trait StorageInfoTrait { fn storage_info() -> Vec; } -#[impl_for_tuples(64)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] #[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl StorageInfoTrait for Tuple { From 9bc95fd78db2089b427e64166c2e90ae4371b7a1 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 2 Aug 2022 20:07:45 +0100 Subject: [PATCH 04/13] fix --- frame/support/src/traits/hooks.rs | 26 +++++++++++++------------- frame/support/src/traits/members.rs | 12 ++++++------ frame/support/src/traits/metadata.rs | 4 ++-- frame/support/src/traits/misc.rs | 12 ++++++------ frame/support/src/traits/storage.rs | 4 ++-- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/frame/support/src/traits/hooks.rs b/frame/support/src/traits/hooks.rs index 63fa6749a7626..2b7234006e0ff 100644 --- a/frame/support/src/traits/hooks.rs +++ b/frame/support/src/traits/hooks.rs @@ -39,7 +39,7 @@ pub trait OnInitialize { } #[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnInitialize for Tuple { fn on_initialize(n: BlockNumber) -> crate::weights::Weight { @@ -52,8 +52,8 @@ impl OnInitialize for Tuple { /// The block finalization trait. /// /// Implementing this lets you express what should happen for your pallet when the block is ending. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnFinalize { /// The block is being finalized. Implement to have something happen. @@ -83,8 +83,8 @@ pub trait OnIdle { } } -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnIdle for Tuple { fn on_idle(n: BlockNumber, remaining_weight: crate::weights::Weight) -> crate::weights::Weight { @@ -111,8 +111,8 @@ impl OnIdle for Tuple { /// Implementing this trait for a pallet let's you express operations that should /// happen at genesis. It will be called in an externalities provided environment and /// will see the genesis state after all pallets have written their genesis state. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnGenesis { /// Something that should happen at genesis. @@ -195,8 +195,8 @@ pub trait OnRuntimeUpgrade { } } -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl OnRuntimeUpgrade for Tuple { fn on_runtime_upgrade() -> crate::weights::Weight { @@ -223,8 +223,8 @@ impl OnRuntimeUpgrade for Tuple { /// Type that provide some integrity tests. /// /// This implemented for modules by `decl_module`. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait IntegrityTest { /// Run integrity test. @@ -344,8 +344,8 @@ pub trait GenesisBuild: Default + sp_runtime::traits::MaybeSerializeD } /// A trait which is called when the timestamp is set in the runtime. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnTimestampSet { /// Called when the timestamp is set. diff --git a/frame/support/src/traits/members.rs b/frame/support/src/traits/members.rs index aa1b9f94cb5f5..796e4c580b468 100644 --- a/frame/support/src/traits/members.rs +++ b/frame/support/src/traits/members.rs @@ -26,9 +26,9 @@ pub trait Contains { fn contains(t: &T) -> bool; } -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(1, 64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(1, 96))] -#[cfg_attr(feature = "tuples-128", impl_for_tuples(1, 128))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl Contains for Tuple { fn contains(t: &T) -> bool { for_tuples!( #( @@ -44,9 +44,9 @@ pub trait ContainsPair { fn contains(a: &A, b: &B) -> bool; } -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(0, 96))] -#[cfg_attr(feature = "tuples-128", impl_for_tuples(0, 128))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl ContainsPair for Tuple { fn contains(a: &A, b: &B) -> bool { for_tuples!( #( diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index e1dc9ff26702c..2927ac180b7ff 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -83,8 +83,8 @@ pub trait PalletsInfoAccess { // all we need is: // Impl PalletsInfoAccess for (T,) {} // Impl PalletsInfoAccess for (T, T1) {} -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl PalletsInfoAccess for Tuple { fn infos() -> Vec { diff --git a/frame/support/src/traits/misc.rs b/frame/support/src/traits/misc.rs index 738218180c219..8f3f533b0a1c6 100644 --- a/frame/support/src/traits/misc.rs +++ b/frame/support/src/traits/misc.rs @@ -468,8 +468,8 @@ impl SameOrOther { } /// Handler for when a new account has been created. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnNewAccount { /// A new account `who` has been registered. @@ -477,8 +477,8 @@ pub trait OnNewAccount { } /// The account with the given id was reaped. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OnKilledAccount { /// The account with the given id was reaped. @@ -637,8 +637,8 @@ impl PrivilegeCmp for EqualPrivilegeOnly { /// but cannot preform any alterations. More specifically alterations are /// not forbidden, but they are not persisted in any way after the worker /// has finished. -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] pub trait OffchainWorker { /// This function is being called after every block import (when fully synced). diff --git a/frame/support/src/traits/storage.rs b/frame/support/src/traits/storage.rs index 433006044ed12..0270b35082ccb 100644 --- a/frame/support/src/traits/storage.rs +++ b/frame/support/src/traits/storage.rs @@ -72,8 +72,8 @@ pub trait StorageInfoTrait { fn storage_info() -> Vec; } -#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64) )] -#[cfg_attr(feature = "tuples-96", impl_for_tuples(96))] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl StorageInfoTrait for Tuple { fn storage_info() -> Vec { From dc211b98f1765d43ed2d0930d07bb4286ab799e2 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Tue, 2 Aug 2022 20:07:56 +0100 Subject: [PATCH 05/13] fmt --- frame/support/src/traits/members.rs | 2 +- frame/support/src/traits/metadata.rs | 2 +- frame/support/src/traits/misc.rs | 2 +- frame/support/src/traits/storage.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/support/src/traits/members.rs b/frame/support/src/traits/members.rs index 796e4c580b468..daf2d3aa6517d 100644 --- a/frame/support/src/traits/members.rs +++ b/frame/support/src/traits/members.rs @@ -17,8 +17,8 @@ //! Traits for dealing with the idea of membership. -use sp_std::{marker::PhantomData, prelude::*}; use impl_trait_for_tuples::impl_for_tuples; +use sp_std::{marker::PhantomData, prelude::*}; /// A trait for querying whether a type can be said to "contain" a value. pub trait Contains { diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index 2927ac180b7ff..0f900e409f9db 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -18,8 +18,8 @@ //! Traits for managing information attached to pallets and their constituents. use codec::{Decode, Encode}; -use sp_runtime::RuntimeDebug; use impl_trait_for_tuples::impl_for_tuples; +use sp_runtime::RuntimeDebug; use sp_std::prelude::*; /// Provides information about the pallet itself and its setup in the runtime. diff --git a/frame/support/src/traits/misc.rs b/frame/support/src/traits/misc.rs index 8f3f533b0a1c6..c9dcf9faaace0 100644 --- a/frame/support/src/traits/misc.rs +++ b/frame/support/src/traits/misc.rs @@ -19,9 +19,9 @@ use crate::dispatch::Parameter; use codec::{CompactLen, Decode, DecodeAll, Encode, EncodeLike, Input, MaxEncodedLen}; +use impl_trait_for_tuples::impl_for_tuples; use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter}; use sp_arithmetic::traits::{CheckedAdd, CheckedMul, CheckedSub, Saturating}; -use impl_trait_for_tuples::impl_for_tuples; #[doc(hidden)] pub use sp_runtime::traits::{ ConstBool, ConstI128, ConstI16, ConstI32, ConstI64, ConstI8, ConstU128, ConstU16, ConstU32, diff --git a/frame/support/src/traits/storage.rs b/frame/support/src/traits/storage.rs index 0270b35082ccb..d40d82c28e87e 100644 --- a/frame/support/src/traits/storage.rs +++ b/frame/support/src/traits/storage.rs @@ -17,8 +17,8 @@ //! Traits for encoding data related to pallet's storage items. -use sp_std::prelude::*; use impl_trait_for_tuples::impl_for_tuples; +use sp_std::prelude::*; /// An instance of a pallet in the storage. /// From 81cbf48793ab2809b193725a13c603adf0c79d11 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Thu, 11 Aug 2022 11:15:37 +0430 Subject: [PATCH 06/13] remove todo --- frame/support/src/traits/metadata.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index 0f900e409f9db..6acc55baf2266 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -79,10 +79,6 @@ pub trait PalletsInfoAccess { fn infos() -> Vec; } -// TODO: this and needing to implement `PalletsInfoAccess` for any individual pallet is kinda wrong. -// all we need is: -// Impl PalletsInfoAccess for (T,) {} -// Impl PalletsInfoAccess for (T, T1) {} #[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] #[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] #[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] From d4a81395fcc1e493fda59bda2da27025f734255b Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Fri, 12 Aug 2022 07:29:58 +0100 Subject: [PATCH 07/13] Update frame/support/src/traits/metadata.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- frame/support/src/traits/metadata.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index 6acc55baf2266..b0dd5bd5160b4 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -85,7 +85,7 @@ pub trait PalletsInfoAccess { impl PalletsInfoAccess for Tuple { fn infos() -> Vec { let mut res = vec![]; - for_tuples!( #( res.extend_from_slice(&Tuple::infos()); )* ); + for_tuples!( #( res.extend(Tuple::infos()); )* ); res } } From cf4790a638a6bbe13f289a55462c25aa0713ac3b Mon Sep 17 00:00:00 2001 From: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Date: Fri, 12 Aug 2022 07:30:18 +0100 Subject: [PATCH 08/13] Update frame/support/src/migrations.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- frame/support/src/migrations.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame/support/src/migrations.rs b/frame/support/src/migrations.rs index 373dc836aefe4..6824e11c35a6a 100644 --- a/frame/support/src/migrations.rs +++ b/frame/support/src/migrations.rs @@ -42,7 +42,9 @@ impl PalletVersionToStorageVersionHelpe } } -#[impl_trait_for_tuples::impl_for_tuples(100)] +#[cfg_attr(all(not(feature = "tuples-96"), not(feature = "tuples-128")), impl_for_tuples(64))] +#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))] +#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))] impl PalletVersionToStorageVersionHelper for T { fn migrate(db_weight: &RuntimeDbWeight) -> Weight { let mut weight: Weight = 0; From ed03bfc3d3b9210be8eb106b94f5253202b89aaa Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 12 Aug 2022 11:09:29 +0430 Subject: [PATCH 09/13] fix --- frame/support/src/migrations.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/support/src/migrations.rs b/frame/support/src/migrations.rs index 6824e11c35a6a..f594b98ede4ff 100644 --- a/frame/support/src/migrations.rs +++ b/frame/support/src/migrations.rs @@ -19,6 +19,7 @@ use crate::{ traits::{GetStorageVersion, PalletInfoAccess}, weights::{RuntimeDbWeight, Weight}, }; +use impl_trait_for_tuples::impl_for_tuples; /// Trait used by [`migrate_from_pallet_version_to_storage_version`] to do the actual migration. pub trait PalletVersionToStorageVersionHelper { From fdd602e7c5d91e1ac11fbc74787bcb0197d7b1ab Mon Sep 17 00:00:00 2001 From: kianenigma Date: Fri, 12 Aug 2022 11:19:56 +0430 Subject: [PATCH 10/13] mark as deprecated --- frame/support/procedural/src/construct_runtime/mod.rs | 6 ++++++ frame/support/test/tests/pallet.rs | 3 +++ 2 files changed, 9 insertions(+) diff --git a/frame/support/procedural/src/construct_runtime/mod.rs b/frame/support/procedural/src/construct_runtime/mod.rs index 4f90543309f50..042af31be6bf4 100644 --- a/frame/support/procedural/src/construct_runtime/mod.rs +++ b/frame/support/procedural/src/construct_runtime/mod.rs @@ -351,13 +351,19 @@ fn decl_all_pallets<'a>( /// All pallets included in the runtime as a nested tuple of types in reversed order. /// Excludes the System pallet. + #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ + `AllPalletWithSystem or AllPalletsWithoutSystem`")] pub type AllPalletsWithoutSystemReversed =( #(#names_without_system_reverse),* ); /// All pallets included in the runtime as a nested tuple of types in reversed order. + #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ + `AllPalletWithSystem or AllPalletsWithoutSystem`")] pub type AllPalletsWithSystemReversed = ( #(#names_reversed),* ); /// All pallets included in the runtime as a nested tuple of types in reversed order. /// With the system pallet first. + #[deprecated(note = "Using reverse pallet orders is deprecated. use only \ + `AllPalletWithSystem or AllPalletsWithoutSystem`")] pub type AllPalletsReversedWithSystemFirst = ( #(#names_reversed_with_system_first),* ); ) } diff --git a/frame/support/test/tests/pallet.rs b/frame/support/test/tests/pallet.rs index 02edde3b349f4..c4bbc59c70373 100644 --- a/frame/support/test/tests/pallet.rs +++ b/frame/support/test/tests/pallet.rs @@ -1597,6 +1597,7 @@ fn test_storage_info() { #[test] fn assert_type_all_pallets_reversed_with_system_first_is_correct() { // Just ensure the 2 types are same. + #[allow(deprecated)] fn _a(_t: AllPalletsReversedWithSystemFirst) {} fn _b(t: (System, Example4, Example2, Example)) { _a(t) @@ -1624,6 +1625,7 @@ fn assert_type_all_pallets_without_system_is_correct() { #[test] fn assert_type_all_pallets_with_system_reversed_is_correct() { // Just ensure the 2 types are same. + #[allow(deprecated)] fn _a(_t: AllPalletsWithSystemReversed) {} fn _b(t: (Example4, Example2, Example, System)) { _a(t) @@ -1633,6 +1635,7 @@ fn assert_type_all_pallets_with_system_reversed_is_correct() { #[test] fn assert_type_all_pallets_without_system_reversed_is_correct() { // Just ensure the 2 types are same. + #[allow(deprecated)] fn _a(_t: AllPalletsWithoutSystemReversed) {} fn _b(t: (Example4, Example2, Example)) { _a(t) From 5898880424ec52abae7b3d2405a27e826e9472df Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 14 Aug 2022 21:29:35 +0430 Subject: [PATCH 11/13] add docs --- frame/support/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 8e43df82a284c..affac53a3e887 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -16,6 +16,15 @@ // limitations under the License. //! Support code for the runtime. +//! +//! ## Note on Tuple Traits +//! +//! Many of the traits defined in [`traits`] have auto-implementations on tuples as well. Usually, +//! the tuple is a function of number of pallets in the runtime. By default, the traits are +//! implemented for tuples of up to 64 items. +// +// If you have more pallets in your runtime, or for any other reason need more, enabled `tuples-96` +// or the `tuples-128` complication flag. Note that these features *will increase* the compilation of this crate. #![cfg_attr(not(feature = "std"), no_std)] From f9b788b8bf38e078677714e42a3b7b850e3c8b3a Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 14 Aug 2022 21:31:11 +0430 Subject: [PATCH 12/13] fix ui test? --- .../support/test/tests/pallet_ui/hooks_invalid_item.stderr | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/support/test/tests/pallet_ui/hooks_invalid_item.stderr b/frame/support/test/tests/pallet_ui/hooks_invalid_item.stderr index d1a89fbb850e9..ff52a094d6f8d 100644 --- a/frame/support/test/tests/pallet_ui/hooks_invalid_item.stderr +++ b/frame/support/test/tests/pallet_ui/hooks_invalid_item.stderr @@ -1,13 +1,13 @@ error[E0107]: missing generics for trait `Hooks` - --> $DIR/hooks_invalid_item.rs:12:18 + --> tests/pallet_ui/hooks_invalid_item.rs:12:18 | 12 | impl Hooks for Pallet {} | ^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `BlockNumber` - --> $DIR/hooks.rs:214:11 + --> $WORKSPACE/frame/support/src/traits/hooks.rs | -214 | pub trait Hooks { + | pub trait Hooks { | ^^^^^ ----------- help: add missing generic argument | From a2ab6ec229a2cd15e196458741f65cef13b654a8 Mon Sep 17 00:00:00 2001 From: kianenigma Date: Sun, 14 Aug 2022 21:48:09 +0430 Subject: [PATCH 13/13] fmt --- frame/support/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index affac53a3e887..7e4c944330fe3 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -24,7 +24,8 @@ //! implemented for tuples of up to 64 items. // // If you have more pallets in your runtime, or for any other reason need more, enabled `tuples-96` -// or the `tuples-128` complication flag. Note that these features *will increase* the compilation of this crate. +// or the `tuples-128` complication flag. Note that these features *will increase* the compilation +// of this crate. #![cfg_attr(not(feature = "std"), no_std)]