diff --git a/prdoc/pr_7960.prdoc b/prdoc/pr_7960.prdoc new file mode 100644 index 0000000000000..bf19f8298e28a --- /dev/null +++ b/prdoc/pr_7960.prdoc @@ -0,0 +1,15 @@ +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. + +crates: +- name: pallet-example-view-functions + bump: none +- name: pallet-proxy + bump: none +- name: frame-support-procedural + bump: major +- name: frame-support + bump: minor 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 86606f2df4284..37cb261267deb 100644 --- a/substrate/frame/support/procedural/src/lib.rs +++ b/substrate/frame/support/procedural/src/lib.rs @@ -1096,9 +1096,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 8625d9ff164d7..e51f0e9b3bf97 100644 --- a/substrate/frame/support/src/lib.rs +++ b/substrate/frame/support/src/lib.rs @@ -1751,7 +1751,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 @@ -1769,7 +1769,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 { @@ -1795,7 +1795,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 b02a138b9a701..618859c1ec16b 100644 --- a/substrate/frame/support/test/tests/pallet.rs +++ b/substrate/frame/support/test/tests/pallet.rs @@ -466,7 +466,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 {