[Deprecation] Remove the deprecated Store trait (#3532)

# Description

*Removes the deprecated `trait Store` feature from the code base*

Fixes #222

---------

Co-authored-by: Dónal Murray <donalm@seadanda.dev>
This commit is contained in:
philoniare
2024-03-12 04:39:21 +08:00
committed by GitHub
parent 05381afcb2
commit d3f81056ad
15 changed files with 20 additions and 276 deletions
+15
View File
@@ -0,0 +1,15 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
title: Remove deprecated `trait Store`
doc:
- audience: Runtime Dev
description: |
The deprecated `trait Store` feature has been removed from the codebase. Please remove usages of `generate_store`
macro from your pallets and access the storage through generics. For example,
`<Self as Store>::StoredRange::mutate` will need to be updated to `StoredRange::<T>::mutate`.
crates:
- name: frame-support
- name: frame
@@ -858,16 +858,6 @@ pub fn disable_frame_system_supertrait_check(_: TokenStream, _: TokenStream) ->
pallet_macro_stub()
}
///
/// ---
///
/// Rust-Analyzer Users: Documentation for this macro can be found at
/// `frame_support::pallet_macros::generate_store`.
#[proc_macro_attribute]
pub fn generate_store(_: TokenStream, _: TokenStream) -> TokenStream {
pallet_macro_stub()
}
///
/// ---
///
@@ -31,7 +31,6 @@ mod instances;
mod origin;
mod pallet_struct;
mod storage;
mod store_trait;
mod tasks;
mod tt_default_parts;
mod type_value;
@@ -68,7 +67,6 @@ pub fn expand(mut def: Def) -> proc_macro2::TokenStream {
let storages = storage::expand_storages(&mut def);
let inherents = inherent::expand_inherents(&mut def);
let instances = instances::expand_instances(&mut def);
let store_trait = store_trait::expand_store_trait(&mut def);
let hooks = hooks::expand_hooks(&mut def);
let genesis_build = genesis_build::expand_genesis_build(&mut def);
let genesis_config = genesis_config::expand_genesis_config(&mut def);
@@ -110,7 +108,6 @@ storage item. Otherwise, all storage items are listed among [*Type Definitions*]
#storages
#inherents
#instances
#store_trait
#hooks
#genesis_build
#genesis_config
@@ -1,67 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::pallet::Def;
use syn::spanned::Spanned;
/// If attribute `#[pallet::generate_store(..)]` is defined then:
/// * generate Store trait with all storages,
/// * implement Store trait for Pallet.
pub fn expand_store_trait(def: &mut Def) -> proc_macro2::TokenStream {
let (trait_vis, trait_store, attribute_span) =
if let Some(store) = &def.pallet_struct.store { store } else { return Default::default() };
let type_impl_gen = &def.type_impl_generics(trait_store.span());
let type_use_gen = &def.type_use_generics(trait_store.span());
let pallet_ident = &def.pallet_struct.pallet;
let mut where_clauses = vec![&def.config.where_clause];
where_clauses.extend(def.storages.iter().map(|storage| &storage.where_clause));
let completed_where_clause = super::merge_where_clauses(&where_clauses);
let storage_names = &def.storages.iter().map(|storage| &storage.ident).collect::<Vec<_>>();
let storage_cfg_attrs =
&def.storages.iter().map(|storage| &storage.cfg_attrs).collect::<Vec<_>>();
let warnig_struct_name = syn::Ident::new("Store", *attribute_span);
let warning: syn::ItemStruct = syn::parse_quote!(
#[deprecated(note = r"
Use of `#[pallet::generate_store(pub(super) trait Store)]` will be removed after July 2023.
Check https://github.com/paritytech/substrate/pull/13535 for more details.")]
struct #warnig_struct_name;
);
quote::quote_spanned!(trait_store.span() =>
const _:() = {
#warning
const _: Option<#warnig_struct_name> = None;
};
#trait_vis trait #trait_store {
#(
#(#storage_cfg_attrs)*
type #storage_names;
)*
}
impl<#type_impl_gen> #trait_store for #pallet_ident<#type_use_gen>
#completed_where_clause
{
#(
#(#storage_cfg_attrs)*
type #storage_names = #storage_names<#type_use_gen>;
)*
}
)
}
@@ -558,8 +558,6 @@ mod keyword {
syn::custom_keyword!(validate_unsigned);
syn::custom_keyword!(type_value);
syn::custom_keyword!(pallet);
syn::custom_keyword!(generate_store);
syn::custom_keyword!(Store);
syn::custom_keyword!(extra_constants);
syn::custom_keyword!(composite_enum);
}
@@ -23,10 +23,8 @@ use syn::spanned::Spanned;
mod keyword {
syn::custom_keyword!(pallet);
syn::custom_keyword!(Pallet);
syn::custom_keyword!(generate_store);
syn::custom_keyword!(without_storage_info);
syn::custom_keyword!(storage_version);
syn::custom_keyword!(Store);
}
/// Definition of the pallet pallet.
@@ -37,8 +35,6 @@ pub struct PalletStructDef {
pub instances: Vec<helper::InstanceUsage>,
/// The keyword Pallet used (contains span).
pub pallet: keyword::Pallet,
/// Whether the trait `Store` must be generated.
pub store: Option<(syn::Visibility, keyword::Store, proc_macro2::Span)>,
/// The span of the pallet::pallet attribute.
pub attr_span: proc_macro2::Span,
/// Whether to specify the storages max encoded len when implementing `StorageInfoTrait`.
@@ -49,11 +45,9 @@ pub struct PalletStructDef {
}
/// Parse for one variant of:
/// * `#[pallet::generate_store($vis trait Store)]`
/// * `#[pallet::without_storage_info]`
/// * `#[pallet::storage_version(STORAGE_VERSION)]`
pub enum PalletStructAttr {
GenerateStore { span: proc_macro2::Span, vis: syn::Visibility, keyword: keyword::Store },
WithoutStorageInfoTrait(proc_macro2::Span),
StorageVersion { storage_version: syn::Path, span: proc_macro2::Span },
}
@@ -61,9 +55,7 @@ pub enum PalletStructAttr {
impl PalletStructAttr {
fn span(&self) -> proc_macro2::Span {
match self {
Self::GenerateStore { span, .. } |
Self::WithoutStorageInfoTrait(span) |
Self::StorageVersion { span, .. } => *span,
Self::WithoutStorageInfoTrait(span) | Self::StorageVersion { span, .. } => *span,
}
}
}
@@ -77,16 +69,7 @@ impl syn::parse::Parse for PalletStructAttr {
content.parse::<syn::Token![::]>()?;
let lookahead = content.lookahead1();
if lookahead.peek(keyword::generate_store) {
content.parse::<keyword::generate_store>()?;
let generate_content;
syn::parenthesized!(generate_content in content);
let vis = generate_content.parse::<syn::Visibility>()?;
generate_content.parse::<syn::Token![trait]>()?;
let keyword = generate_content.parse::<keyword::Store>()?;
let span = content.span();
Ok(Self::GenerateStore { vis, keyword, span })
} else if lookahead.peek(keyword::without_storage_info) {
if lookahead.peek(keyword::without_storage_info) {
let span = content.parse::<keyword::without_storage_info>()?.span();
Ok(Self::WithoutStorageInfoTrait(span))
} else if lookahead.peek(keyword::storage_version) {
@@ -116,16 +99,12 @@ impl PalletStructDef {
return Err(syn::Error::new(item.span(), msg))
};
let mut store = None;
let mut without_storage_info = None;
let mut storage_version_found = None;
let struct_attrs: Vec<PalletStructAttr> = helper::take_item_pallet_attrs(&mut item.attrs)?;
for attr in struct_attrs {
match attr {
PalletStructAttr::GenerateStore { vis, keyword, span } if store.is_none() => {
store = Some((vis, keyword, span));
},
PalletStructAttr::WithoutStorageInfoTrait(span)
if without_storage_info.is_none() =>
{
@@ -162,7 +141,6 @@ impl PalletStructDef {
index,
instances,
pallet,
store,
attr_span,
without_storage_info,
storage_version: storage_version_found,
+2 -22
View File
@@ -702,7 +702,7 @@ pub use frame_support_procedural::crate_to_crate_version;
#[macro_export]
macro_rules! fail {
( $y:expr ) => {{
return Err($y.into())
return Err($y.into());
}};
}
@@ -949,7 +949,7 @@ pub mod pallet_prelude {
/// pub trait Config: frame_system::Config {}
/// }
/// ```
///
//
/// I.e. a regular struct definition named `Pallet`, with generic T and no where clause.
///
/// ## Macro expansion:
@@ -1341,26 +1341,6 @@ pub mod pallet_macros {
/// See [`pallet::storage`](`frame_support::pallet_macros::storage`) for more info.
pub use frame_support_procedural::getter;
/// Allows generating the `Store` trait for all storages.
///
/// DEPRECATED: Will be removed, do not use.
/// See <https://github.com/paritytech/substrate/pull/13535> for more details.
///
/// To generate a `Store` trait associating all storages, annotate your `Pallet` struct
/// with the attribute `#[pallet::generate_store($vis trait Store)]`, e.g.:
///
/// ```ignore
/// #[pallet::pallet]
/// #[pallet::generate_store(pub(super) trait Store)]
/// pub struct Pallet<T>(_);
/// ```
/// More precisely, the `Store` trait contains an associated type for each storage. It is
/// implemented for `Pallet` allowing access to the storage from pallet struct.
///
/// Thus when defining a storage named `Foo`, it can later be accessed from `Pallet` using
/// `<Pallet as Store>::Foo`.
pub use frame_support_procedural::generate_store;
/// Defines constants that are added to the constant field of
/// [`PalletMetadata`](frame_metadata::v15::PalletMetadata) struct for this pallet.
///
@@ -1,28 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[frame_support::pallet]
mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
}
fn main() {}
@@ -1,10 +0,0 @@
error: use of deprecated struct `pallet::_::Store`:
Use of `#[pallet::generate_store(pub(super) trait Store)]` will be removed after July 2023.
Check https://github.com/paritytech/substrate/pull/13535 for more details.
--> tests/pallet_ui/deprecated_store_attr.rs:24:3
|
24 | #[pallet::generate_store(trait Store)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D deprecated` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(deprecated)]`
@@ -1,42 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(trait Store)]
#[pallet::generate_store(trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
}
fn main() {}
@@ -1,5 +0,0 @@
error: Unexpected duplicated attribute
--> tests/pallet_ui/duplicate_store_attr.rs:29:3
|
29 | #[pallet::generate_store(trait Store)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1,4 +1,4 @@
error: expected one of: `generate_store`, `without_storage_info`, `storage_version`
error: expected `without_storage_info` or `storage_version`
--> tests/pallet_ui/pallet_struct_invalid_attr.rs:24:12
|
24 | #[pallet::generate_storage_info] // invalid
@@ -1,42 +0,0 @@
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#[frame_support::pallet]
mod pallet {
use frame_support::pallet_prelude::Hooks;
use frame_system::pallet_prelude::BlockNumberFor;
use frame_support::pallet_prelude::StorageValue;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
#[pallet::generate_store(pub trait Store)]
pub struct Pallet<T>(core::marker::PhantomData<T>);
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
#[pallet::call]
impl<T: Config> Pallet<T> {}
#[pallet::storage]
type Foo<T> = StorageValue<_, u8>;
}
fn main() {
}
@@ -1,19 +0,0 @@
error: use of deprecated struct `pallet::_::Store`:
Use of `#[pallet::generate_store(pub(super) trait Store)]` will be removed after July 2023.
Check https://github.com/paritytech/substrate/pull/13535 for more details.
--> tests/pallet_ui/store_trait_leak_private.rs:28:3
|
28 | #[pallet::generate_store(pub trait Store)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D deprecated` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(deprecated)]`
error[E0446]: private type `_GeneratedPrefixForStorageFoo<T>` in public interface
--> tests/pallet_ui/store_trait_leak_private.rs:28:37
|
28 | #[pallet::generate_store(pub trait Store)]
| ^^^^^ can't leak private type
...
37 | #[pallet::storage]
| ------- `_GeneratedPrefixForStorageFoo<T>` declared as private
@@ -41,7 +41,6 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
#[pallet::pallet]
#[pallet::generate_store(pub (super) trait Store)]
pub struct Pallet<T>(_);
#[pallet::config]