From ac523fef90cee44bc78cf1363a2147bde8df75d4 Mon Sep 17 00:00:00 2001 From: giuseppere Date: Tue, 18 Mar 2025 18:06:27 +0100 Subject: [PATCH 1/3] Change `view_functions_experimental` into `view_functions` --- substrate/frame/examples/view-functions/src/lib.rs | 6 +++--- substrate/frame/proxy/src/lib.rs | 2 +- substrate/frame/support/procedural/src/lib.rs | 4 ++-- .../frame/support/procedural/src/pallet/parse/mod.rs | 8 +++----- .../procedural/src/pallet/parse/view_functions.rs | 10 +++++----- substrate/frame/support/src/lib.rs | 6 +++--- substrate/frame/support/test/tests/pallet.rs | 2 +- .../test/tests/pallet_ui/pass/view_function_valid.rs | 2 +- .../test/tests/pallet_ui/view_function_invalid_item.rs | 2 +- .../tests/pallet_ui/view_function_invalid_item.stderr | 2 +- .../test/tests/pallet_ui/view_function_no_return.rs | 2 +- .../test/tests/pallet_ui/view_function_not_public.rs | 2 +- .../tests/pallet_ui/view_function_not_public.stderr | 2 +- 13 files changed, 24 insertions(+), 26 deletions(-) diff --git a/substrate/frame/examples/view-functions/src/lib.rs b/substrate/frame/examples/view-functions/src/lib.rs index 9cad8ab1bcdb0..dc0111cf98287 100644 --- a/substrate/frame/examples/view-functions/src/lib.rs +++ b/substrate/frame/examples/view-functions/src/lib.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! This pallet demonstrates the use of the `pallet::view_functions_experimental` api for service +//! This pallet demonstrates the use of the `pallet::view_functions` api for service //! work. #![cfg_attr(not(feature = "std"), no_std)] @@ -58,7 +58,7 @@ pub mod pallet { #[pallet::storage] pub type SomeMap = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet where T::AccountId: From + SomeAssociation1, @@ -96,7 +96,7 @@ pub mod pallet2 { pub type SomeMap, I: 'static = ()> = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl, I: 'static> Pallet where T::AccountId: From + SomeAssociation1, diff --git a/substrate/frame/proxy/src/lib.rs b/substrate/frame/proxy/src/lib.rs index e583980760231..045fe47494d45 100644 --- a/substrate/frame/proxy/src/lib.rs +++ b/substrate/frame/proxy/src/lib.rs @@ -738,7 +738,7 @@ pub mod pallet { ValueQuery, >; - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet { /// Check if a `RuntimeCall` is allowed for a given `ProxyType`. pub fn check_permissions( diff --git a/substrate/frame/support/procedural/src/lib.rs b/substrate/frame/support/procedural/src/lib.rs index 3a106aa05d51c..5a6746368b83e 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -1095,9 +1095,9 @@ pub fn validate_unsigned(_: TokenStream, _: TokenStream) -> TokenStream { /// --- /// /// Documentation for this macro can be found at -/// `frame_support::pallet_macros::view_functions_experimental`. +/// `frame_support::pallet_macros::view_functions`. #[proc_macro_attribute] -pub fn view_functions_experimental(_: TokenStream, _: TokenStream) -> TokenStream { +pub fn view_functions(_: TokenStream, _: TokenStream) -> TokenStream { pallet_macro_stub() } diff --git a/substrate/frame/support/procedural/src/pallet/parse/mod.rs b/substrate/frame/support/procedural/src/pallet/parse/mod.rs index 89875974b8b5d..1eaeb92ff5265 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/mod.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/mod.rs @@ -570,7 +570,7 @@ mod keyword { syn::custom_keyword!(pallet); syn::custom_keyword!(extra_constants); syn::custom_keyword!(composite_enum); - syn::custom_keyword!(view_functions_experimental); + syn::custom_keyword!(view_functions); } /// The possible values for the `#[pallet::config]` attribute. @@ -788,10 +788,8 @@ impl syn::parse::Parse for PalletAttr { Ok(PalletAttr::ExtraConstants(content.parse::()?.span())) } else if lookahead.peek(keyword::composite_enum) { Ok(PalletAttr::Composite(content.parse::()?.span())) - } else if lookahead.peek(keyword::view_functions_experimental) { - Ok(PalletAttr::ViewFunctions( - content.parse::()?.span(), - )) + } else if lookahead.peek(keyword::view_functions) { + Ok(PalletAttr::ViewFunctions(content.parse::()?.span())) } else { Err(lookahead.error()) } diff --git a/substrate/frame/support/procedural/src/pallet/parse/view_functions.rs b/substrate/frame/support/procedural/src/pallet/parse/view_functions.rs index 469ee0fe5b795..bc6563a7c5128 100644 --- a/substrate/frame/support/procedural/src/pallet/parse/view_functions.rs +++ b/substrate/frame/support/procedural/src/pallet/parse/view_functions.rs @@ -19,11 +19,11 @@ use frame_support_procedural_tools::get_doc_literals; use inflector::Inflector; use syn::spanned::Spanned; -/// Parsed representation of an impl block annotated with `pallet::view_functions_experimental`. +/// Parsed representation of an impl block annotated with `pallet::view_functions`. pub struct ViewFunctionsImplDef { /// The where_clause used. pub where_clause: Option, - /// The span of the pallet::view_functions_experimental attribute. + /// The span of the pallet::view_functions attribute. pub attr_span: proc_macro2::Span, /// The view function definitions. pub view_functions: Vec, @@ -34,14 +34,14 @@ impl ViewFunctionsImplDef { let syn::Item::Impl(item_impl) = item else { return Err(syn::Error::new( item.span(), - "Invalid pallet::view_functions_experimental, expected item impl", + "Invalid pallet::view_functions, expected item impl", )) }; let mut view_functions = Vec::new(); for item in &mut item_impl.items { if let syn::ImplItem::Fn(method) = item { if !matches!(method.vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::view_functions_experimental, view function must be public: \ + let msg = "Invalid pallet::view_functions, view function must be public: \ `pub fn`"; let span = match method.vis { @@ -57,7 +57,7 @@ impl ViewFunctionsImplDef { } else { return Err(syn::Error::new( item.span(), - "Invalid pallet::view_functions_experimental, expected a function", + "Invalid pallet::view_functions, expected a function", )) } } diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs index 86c7330d275de..c5bd7b95e1bf9 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -1746,7 +1746,7 @@ pub mod pallet_macros { /// /// ## Syntax /// View functions methods must be read-only and always return some output. A - /// `view_functions_experimental` impl block only allows methods to be defined inside of + /// `view_functions` impl block only allows methods to be defined inside of /// it. /// /// ## Example @@ -1764,7 +1764,7 @@ pub mod pallet_macros { /// #[pallet::storage] /// pub type SomeMap = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>; /// - /// #[pallet::view_functions_experimental] + /// #[pallet::view_functions] /// impl Pallet { /// /// Retrieve a map storage value by key. /// pub fn get_value_with_arg(key: u32) -> Option { @@ -1790,7 +1790,7 @@ pub mod pallet_macros { /// functions should expose a _stable_ interface and changes to the method signature are /// strongly discouraged. For more details on the dispatching mechanism, see the /// [`DispatchViewFunction`](frame_support::view_functions::DispatchViewFunction) trait. - pub use frame_support_procedural::view_functions_experimental; + pub use frame_support_procedural::view_functions; /// Allows defining a struct implementing the [`Get`](frame_support::traits::Get) trait to /// ease the use of storage types. diff --git a/substrate/frame/support/test/tests/pallet.rs b/substrate/frame/support/test/tests/pallet.rs index dc09f1d35f989..d1f7251ed9640 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -461,7 +461,7 @@ pub mod pallet { _myfield: u32, } - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet where T::AccountId: From + SomeAssociation1, diff --git a/substrate/frame/support/test/tests/pallet_ui/pass/view_function_valid.rs b/substrate/frame/support/test/tests/pallet_ui/pass/view_function_valid.rs index 18392d4c316a5..46d694f03019c 100644 --- a/substrate/frame/support/test/tests/pallet_ui/pass/view_function_valid.rs +++ b/substrate/frame/support/test/tests/pallet_ui/pass/view_function_valid.rs @@ -28,7 +28,7 @@ pub mod pallet { #[pallet::storage] pub type MyStorage = StorageValue<_, u32>; - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet { pub fn get_value() -> Option { MyStorage::::get() diff --git a/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.rs b/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.rs index 81a794d9b0d6b..7851bfdd24d28 100644 --- a/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.rs +++ b/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.rs @@ -25,7 +25,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(_); - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet { pub const SECONDS_PER_MINUTE: u32 = 60; } diff --git a/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.stderr b/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.stderr index 6afdf707fce60..f0a4604d274cc 100644 --- a/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/view_function_invalid_item.stderr @@ -1,4 +1,4 @@ -error: Invalid pallet::view_functions_experimental, expected a function +error: Invalid pallet::view_functions, expected a function --> tests/pallet_ui/view_function_invalid_item.rs:30:3 | 30 | pub const SECONDS_PER_MINUTE: u32 = 60; diff --git a/substrate/frame/support/test/tests/pallet_ui/view_function_no_return.rs b/substrate/frame/support/test/tests/pallet_ui/view_function_no_return.rs index 3356e354ca72c..f7d274eed44ec 100644 --- a/substrate/frame/support/test/tests/pallet_ui/view_function_no_return.rs +++ b/substrate/frame/support/test/tests/pallet_ui/view_function_no_return.rs @@ -28,7 +28,7 @@ mod pallet { #[pallet::storage] pub type MyStorage = StorageValue<_, u32>; - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet { pub fn get_value() { MyStorage::::set(0); diff --git a/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.rs b/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.rs index e6611013335c6..f131060074a04 100644 --- a/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.rs +++ b/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.rs @@ -28,7 +28,7 @@ mod pallet { #[pallet::storage] pub type MyStorage = StorageValue<_, u32>; - #[pallet::view_functions_experimental] + #[pallet::view_functions] impl Pallet { fn get_value() -> Option { MyStorage::::get() diff --git a/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.stderr b/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.stderr index 7b0688af07974..3a638038157fd 100644 --- a/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.stderr +++ b/substrate/frame/support/test/tests/pallet_ui/view_function_not_public.stderr @@ -1,4 +1,4 @@ -error: Invalid pallet::view_functions_experimental, view function must be public: `pub fn` +error: Invalid pallet::view_functions, view function must be public: `pub fn` --> tests/pallet_ui/view_function_not_public.rs:33:3 | 33 | fn get_value() -> Option { From 09a2edf2ed10338aa98feffa41039df9af4c5199 Mon Sep 17 00:00:00 2001 From: "cmd[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 20 Mar 2025 15:58:26 +0000 Subject: [PATCH 2/3] Update from github-actions[bot] running command 'prdoc --audience runtime_dev --bump patch' --- prdoc/pr_7960.prdoc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 prdoc/pr_7960.prdoc diff --git a/prdoc/pr_7960.prdoc b/prdoc/pr_7960.prdoc new file mode 100644 index 0000000000000..8b8e7c16311c5 --- /dev/null +++ b/prdoc/pr_7960.prdoc @@ -0,0 +1,22 @@ +title: Stabilize pallet view functions +doc: +- audience: Runtime Dev + description: |- + Pallet view functions are no longer marked as experimental, and their use is suggested starting from this PR. + + Your feedback is more than welcome. + + See [docs](https://paritytech.github.io/polkadot-sdk/master/frame_support/pallet_macros/attr.view_functions_experimental.html) for a quick introduction. For more context, you can look at: + + - #4722 + - #7412 + - #7830 : discussion on possible changes to pallet view functions +crates: +- name: pallet-example-view-functions + bump: patch +- name: pallet-proxy + bump: patch +- name: frame-support-procedural + bump: patch +- name: frame-support + bump: patch From f81232f5d072edebeb0e8e7ea9a012a02e9f1c7c Mon Sep 17 00:00:00 2001 From: giuseppere Date: Thu, 20 Mar 2025 17:04:51 +0100 Subject: [PATCH 3/3] fix prdoc --- prdoc/pr_7960.prdoc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/prdoc/pr_7960.prdoc b/prdoc/pr_7960.prdoc index 8b8e7c16311c5..bf19f8298e28a 100644 --- a/prdoc/pr_7960.prdoc +++ b/prdoc/pr_7960.prdoc @@ -4,19 +4,12 @@ doc: description: |- Pallet view functions are no longer marked as experimental, and their use is suggested starting from this PR. - Your feedback is more than welcome. - - See [docs](https://paritytech.github.io/polkadot-sdk/master/frame_support/pallet_macros/attr.view_functions_experimental.html) for a quick introduction. For more context, you can look at: - - - #4722 - - #7412 - - #7830 : discussion on possible changes to pallet view functions crates: - name: pallet-example-view-functions - bump: patch + bump: none - name: pallet-proxy - bump: patch + bump: none - name: frame-support-procedural - bump: patch + bump: major - name: frame-support - bump: patch + bump: minor