Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions prdoc/pr_7960.prdoc
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions substrate/frame/examples/view-functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down Expand Up @@ -58,7 +58,7 @@ pub mod pallet {
#[pallet::storage]
pub type SomeMap<T: Config> = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>;

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T>
where
T::AccountId: From<SomeType1> + SomeAssociation1,
Expand Down Expand Up @@ -96,7 +96,7 @@ pub mod pallet2 {
pub type SomeMap<T: Config<I>, I: 'static = ()> =
StorageMap<_, Twox64Concat, u32, u32, OptionQuery>;

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config<I>, I: 'static> Pallet<T, I>
where
T::AccountId: From<SomeType1> + SomeAssociation1,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ pub mod pallet {
ValueQuery,
>;

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T> {
/// Check if a `RuntimeCall` is allowed for a given `ProxyType`.
pub fn check_permissions(
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
8 changes: 3 additions & 5 deletions substrate/frame/support/procedural/src/pallet/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -788,10 +788,8 @@ impl syn::parse::Parse for PalletAttr {
Ok(PalletAttr::ExtraConstants(content.parse::<keyword::extra_constants>()?.span()))
} else if lookahead.peek(keyword::composite_enum) {
Ok(PalletAttr::Composite(content.parse::<keyword::composite_enum>()?.span()))
} else if lookahead.peek(keyword::view_functions_experimental) {
Ok(PalletAttr::ViewFunctions(
content.parse::<keyword::view_functions_experimental>()?.span(),
))
} else if lookahead.peek(keyword::view_functions) {
Ok(PalletAttr::ViewFunctions(content.parse::<keyword::view_functions>()?.span()))
} else {
Err(lookahead.error())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<syn::WhereClause>,
/// 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<ViewFunctionDef>,
Expand All @@ -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 {
Expand All @@ -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",
))
}
}
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1769,7 +1769,7 @@ pub mod pallet_macros {
/// #[pallet::storage]
/// pub type SomeMap<T: Config> = StorageMap<_, Twox64Concat, u32, u32, OptionQuery>;
///
/// #[pallet::view_functions_experimental]
/// #[pallet::view_functions]
/// impl<T: Config> Pallet<T> {
/// /// Retrieve a map storage value by key.
/// pub fn get_value_with_arg(key: u32) -> Option<u32> {
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/test/tests/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ pub mod pallet {
_myfield: u32,
}

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T>
where
T::AccountId: From<SomeType1> + SomeAssociation1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod pallet {
#[pallet::storage]
pub type MyStorage<T> = StorageValue<_, u32>;

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T> {
pub fn get_value() -> Option<u32> {
MyStorage::<T>::get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod pallet {
#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T> {
pub const SECONDS_PER_MINUTE: u32 = 60;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod pallet {
#[pallet::storage]
pub type MyStorage<T> = StorageValue<_, u32>;

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T> {
pub fn get_value() {
MyStorage::<T>::set(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mod pallet {
#[pallet::storage]
pub type MyStorage<T> = StorageValue<_, u32>;

#[pallet::view_functions_experimental]
#[pallet::view_functions]
impl<T: Config> Pallet<T> {
fn get_value() -> Option<u32> {
MyStorage::<T>::get()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<u32> {
Expand Down
Loading