Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
01f3639
remove deprecation attribute before code expansion
pkhry Oct 31, 2024
524fffa
prdoc
pkhry Oct 31, 2024
f199b9f
fixup api
pkhry Oct 31, 2024
71e89d4
".git/.scripts/commands/update-ui/update-ui.sh"
Nov 1, 2024
eb8077c
review comments
pkhry Nov 4, 2024
74c7b9f
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Nov 4, 2024
6fe881a
rever change
pkhry Nov 5, 2024
c9eed15
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Nov 5, 2024
0978bff
update scale-info
pkhry Nov 27, 2024
acd6c55
move to allow(deprecated) propagation instead
pkhry Nov 27, 2024
f87b3e7
Merge branch 'pkhry/update-frame' into pkhry/silent-deprecation-attr
pkhry Nov 27, 2024
4e638d6
merge issue
pkhry Nov 27, 2024
5714f3c
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Dec 3, 2024
9ada2aa
review
pkhry Dec 3, 2024
39ee4cc
review
pkhry Dec 3, 2024
99c0436
remove expansion file
pkhry Dec 3, 2024
38affa5
review comments
pkhry Dec 4, 2024
b1c426a
fixup try_runtime! codegen contents
pkhry Dec 4, 2024
5f9a1df
fix clippy
pkhry Dec 4, 2024
377981c
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Dec 4, 2024
a23571b
fixup test
pkhry Dec 5, 2024
b9c70c2
".git/.scripts/commands/update-ui/update-ui.sh"
Dec 5, 2024
7e0712d
review comments
pkhry Dec 11, 2024
a1a14ab
more review comments
pkhry Dec 11, 2024
d6b3b9b
Apply suggestions from code review
pkhry Jan 6, 2025
4bfc2ba
fixup suggestions
pkhry Jan 6, 2025
34b8468
Update from pkhry running command 'fmt'
Jan 6, 2025
d3f7769
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Jan 6, 2025
4cfa648
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Jan 16, 2025
a5259eb
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Jan 20, 2025
73187e9
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Jan 21, 2025
45a83fc
review comments
pkhry Jan 24, 2025
d7f3522
remove one more useless allow(deprecated)
pkhry Jan 24, 2025
520545e
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Jan 24, 2025
e1546eb
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Mar 26, 2025
b81d2a8
prdoc
pkhry Mar 26, 2025
9ab6788
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Apr 7, 2025
d322252
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Apr 7, 2025
5ad3a0d
Apply suggestions from code review
pkhry Apr 7, 2025
d0546ef
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Apr 7, 2025
01f1fdc
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Apr 7, 2025
90a56fe
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Apr 8, 2025
c7124f6
Merge branch 'master' into pkhry/silent-deprecation-attr
pkhry Apr 9, 2025
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
18 changes: 18 additions & 0 deletions prdoc/pr_6312.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
title: DeprecationInfo propagate or automatically add allow(deprecated) attributes in the generated code.

doc:
- audience: [Runtime Dev, Runtime User]
description: |
Propagates or automatically adds allow(deprecated) attributes on `Constants`, `RuntimeApis`, `Runtime Calls` and enum variants
to reduce noise produced by warnings inside generated code.

crates:
- name: frame-support-procedural
bump: none
- name: frame-support
bump: none
- name: sp-api-proc-macro
bump: none
- name: sp-api
bump: none

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub fn expand_runtime_metadata(

quote! {
impl #runtime {
#[allow(deprecated)]
fn metadata_ir() -> #scrate::__private::metadata_ir::MetadataIR {
// Each runtime must expose the `runtime_metadata()` to fetch the runtime API metadata.
// The function is implemented by calling `impl_runtime_apis!`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ fn expand_enum_conversion(

quote! {
#attr
#[allow(deprecated)]
impl From<#pallet_enum> for #enum_name_ident {
fn from(x: #pallet_enum) -> Self {
#enum_name_ident
::#variant_name(x)
}
}
#attr
#[allow(deprecated)]
impl TryInto<#pallet_enum> for #enum_name_ident {
type Error = ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ pub(crate) fn decl_static_assertions(
);

quote! {
#[allow(deprecated)]
#scrate::__private::tt_call! {
macro = [{ #path::tt_error_token }]
your_tt_return = [{ #scrate::__private::tt_return }]
Expand Down
18 changes: 18 additions & 0 deletions substrate/frame/support/procedural/src/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,21 @@ pub fn variant_index_for_deprecation(index: u8, item: &Variant) -> u8 {
})
.unwrap_or(index)
}

/// Filters all of the `allow` and `deprecated` attributes.
///
/// `allow` attributes are returned as is while `deprecated` attributes are replaced by
/// `#[allow(deprecated)]`.
pub fn extract_or_return_allow_attrs(
items: &[syn::Attribute],
) -> impl Iterator<Item = syn::Attribute> + '_ {
items.iter().filter_map(|attr| {
attr.path().is_ident("allow").then(|| attr.clone()).or_else(|| {
attr.path().is_ident("deprecated").then(|| {
syn::parse_quote! {
#[allow(deprecated)]
}
})
})
})
}
1 change: 1 addition & 0 deletions substrate/frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ pub fn derive_eq_no_bound(input: TokenStream) -> TokenStream {
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();

quote::quote_spanned!(name.span() =>
#[allow(deprecated)]
const _: () = {
impl #impl_generics ::core::cmp::Eq for #name #ty_generics #where_clause {}
};
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/procedural/src/no_bound/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke
quote::quote!(
const _: () = {
#[automatically_derived]
#[allow(deprecated)]
impl #impl_generics ::core::clone::Clone for #name #ty_generics #where_clause {
fn clone(&self) -> Self {
#impl_
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/procedural/src/no_bound/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub fn derive_debug_no_bound(input: proc_macro::TokenStream) -> proc_macro::Toke
quote::quote!(
const _: () = {
#[automatically_derived]
#[allow(deprecated)]
impl #impl_generics ::core::fmt::Debug for #input_ident #ty_generics #where_clause {
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
#impl_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To
quote!(
const _: () = {
#[automatically_derived]
#[allow(deprecated)]
impl #impl_generics ::core::default::Default for #name #ty_generics #where_clause {
fn default() -> Self {
#impl_
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/support/procedural/src/no_bound/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn derive_ord_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenS

quote::quote!(
const _: () = {
#[allow(deprecated)]
impl #impl_generics core::cmp::Ord for #name #ty_generics #where_clause {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
#impl_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub fn derive_partial_eq_no_bound(input: proc_macro::TokenStream) -> proc_macro:
quote::quote!(
const _: () = {
#[automatically_derived]
#[allow(deprecated)]
impl #impl_generics ::core::cmp::PartialEq for #name #ty_generics #where_clause {
fn eq(&self, other: &Self) -> bool {
#impl_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn derive_partial_ord_no_bound(input: proc_macro::TokenStream) -> proc_macro

quote::quote!(
const _: () = {
#[allow(deprecated)]
impl #impl_generics core::cmp::PartialOrd for #name #ty_generics #where_clause {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
#impl_
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/support/procedural/src/pallet/expand/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

use crate::{
deprecation::extract_or_return_allow_attrs,
pallet::{
expand::warnings::{weight_constant_warning, weight_witness_warning},
parse::{call::CallWeightDef, helper::CallReturnType},
Expand Down Expand Up @@ -236,11 +237,10 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
let maybe_allow_attrs = methods
.iter()
.map(|method| {
method
.attrs
.iter()
.find(|attr| attr.path().is_ident("allow"))
.map_or(proc_macro2::TokenStream::new(), |attr| attr.to_token_stream())
let attrs = extract_or_return_allow_attrs(&method.attrs);
quote::quote! {
#(#attrs)*
}
})
.collect::<Vec<_>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Consequently, a runtime that wants to include this pallet must implement this tr
]
),
);
config_item.attrs.retain(|attr| !attr.path().is_ident("deprecated"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind this. Thinking back I think it was overkill to allow deprecating the config in the first place.

I wouldn't mind also just letting the flag there, and have deprecated warning everywhere.


// we only emit `DefaultConfig` if there are trait items, so an empty `DefaultConfig` is
// impossible consequently.
Expand Down
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.

use crate::pallet::Def;
use crate::{deprecation::extract_or_return_allow_attrs, pallet::Def};

struct ConstDef {
/// Name of the associated type.
Expand Down Expand Up @@ -55,11 +55,16 @@ pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream {
Ok(deprecation) => deprecation,
Err(e) => return e.into_compile_error(),
};

// Extracts #[allow] attributes, necessary so that we don't run into compiler warnings
let maybe_allow_attrs = extract_or_return_allow_attrs(&const_.attrs);

config_consts.push(ConstDef {
ident: const_.ident.clone(),
type_: const_.type_.clone(),
doc: const_.doc.clone(),
default_byte_impl: quote::quote!(
#(#maybe_allow_attrs)*
let value = <<T as Config #trait_use_gen>::#ident as
#frame_support::traits::Get<#const_type>>::get();
#frame_support::__private::codec::Encode::encode(&value)
Expand All @@ -79,12 +84,15 @@ pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream {
Ok(deprecation) => deprecation,
Err(e) => return e.into_compile_error(),
};
// Extracts #[allow] attributes, necessary so that we don't run into compiler warnings
let maybe_allow_attrs = extract_or_return_allow_attrs(&const_.attrs);

extra_consts.push(ConstDef {
ident: const_.ident.clone(),
type_: const_.type_.clone(),
doc: const_.doc.clone(),
default_byte_impl: quote::quote!(
#(#maybe_allow_attrs)*
let value = <Pallet<#type_use_gen>>::#ident();
#frame_support::__private::codec::Encode::encode(&value)
),
Expand Down
22 changes: 16 additions & 6 deletions substrate/frame/support/procedural/src/pallet/expand/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

use crate::{
deprecation::extract_or_return_allow_attrs,
pallet::{
parse::error::{VariantDef, VariantField},
Def,
Expand Down Expand Up @@ -75,18 +76,18 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
error
.variants
.iter()
.map(|VariantDef { ident: variant, field: field_ty, cfg_attrs }| {
.map(|VariantDef { ident: variant, field: field_ty, cfg_attrs, maybe_allow_attrs }| {
let variant_str = variant.to_string();
let cfg_attrs = cfg_attrs.iter().map(|attr| attr.to_token_stream());
match field_ty {
Some(VariantField { is_named: true }) => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant { .. } => #variant_str,)
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* #(#maybe_allow_attrs)* Self::#variant { .. } => #variant_str,)
},
Some(VariantField { is_named: false }) => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant(..) => #variant_str,)
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* #(#maybe_allow_attrs)* Self::#variant(..) => #variant_str,)
},
None => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant => #variant_str,)
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* #(#maybe_allow_attrs)* Self::#variant => #variant_str,)
},
}
});
Expand All @@ -99,7 +100,6 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
unreachable!("Checked by error parser")
}
};

error_item.variants.insert(0, phantom_variant);

let capture_docs = if cfg!(feature = "no-metadata-docs") { "never" } else { "always" };
Expand Down Expand Up @@ -137,7 +137,12 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
));
}

// Extracts #[allow] attributes, necessary so that we don't run into compiler warnings
let maybe_allow_attrs: Vec<syn::Attribute> =
extract_or_return_allow_attrs(&error_item.attrs).collect();

quote::quote_spanned!(error.attr_span =>
#(#maybe_allow_attrs)*
impl<#type_impl_gen> core::fmt::Debug for #error_ident<#type_use_gen>
#config_where_clause
{
Expand All @@ -148,16 +153,18 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
}
}

#(#maybe_allow_attrs)*
impl<#type_impl_gen> #error_ident<#type_use_gen> #config_where_clause {
#[doc(hidden)]
pub fn as_str(&self) -> &'static str {
match &self {
Self::__Ignore(_, _) => unreachable!("`__Ignore` can never be constructed"),
#(#maybe_allow_attrs)* Self::__Ignore(_, _) => unreachable!("`__Ignore` can never be constructed"),
#( #as_str_matches )*
}
}
}

#(#maybe_allow_attrs)*
impl<#type_impl_gen> From<#error_ident<#type_use_gen>> for &'static str
#config_where_clause
{
Expand All @@ -166,6 +173,7 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
}
}

#(#maybe_allow_attrs)*
impl<#type_impl_gen> From<#error_ident<#type_use_gen>>
for #frame_support::sp_runtime::DispatchError
#config_where_clause
Expand Down Expand Up @@ -204,10 +212,12 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {

pub use #error_token_unique_id as tt_error_token;

#(#maybe_allow_attrs)*
impl<#type_impl_gen> #error_ident<#type_use_gen> #config_where_clause {
#[allow(dead_code)]
#[doc(hidden)]
pub fn error_metadata() -> #frame_support::__private::metadata_ir::PalletErrorMetadataIR {
#(#maybe_allow_attrs)*
#frame_support::__private::metadata_ir::PalletErrorMetadataIR {
ty: #frame_support::__private::scale_info::meta_type::<#error_ident<#type_use_gen>>(),
deprecation_info: #deprecation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

use crate::{
deprecation::extract_or_return_allow_attrs,
pallet::{parse::event::PalletEventDepositAttr, Def},
COUNTER,
};
Expand Down Expand Up @@ -135,6 +136,10 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {
#[scale_info(skip_type_params(#event_use_gen), capture_docs = #capture_docs)]
));

// Extracts #[allow] attributes, necessary so that we don't run into compiler warnings
let maybe_allow_attrs: Vec<syn::Attribute> =
extract_or_return_allow_attrs(&event_item.attrs).collect();

let deposit_event = if let Some(deposit_event) = &event.deposit_event {
let event_use_gen = &event.gen_kind.type_use_gen(event.attr_span);
let trait_use_gen = &def.trait_use_generics(event.attr_span);
Expand All @@ -146,6 +151,7 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {

quote::quote_spanned!(*fn_span =>
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause {
#(#maybe_allow_attrs)*
#fn_vis fn deposit_event(event: Event<#event_use_gen>) {
let event = <
<T as Config #trait_use_gen>::RuntimeEvent as
Expand Down Expand Up @@ -180,10 +186,12 @@ pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream {

#deposit_event

#(#maybe_allow_attrs)*
impl<#event_impl_gen> From<#event_ident<#event_use_gen>> for () #event_where_clause {
fn from(_: #event_ident<#event_use_gen>) {}
}

#(#maybe_allow_attrs)*
impl<#event_impl_gen> #event_ident<#event_use_gen> #event_where_clause {
#[allow(dead_code)]
#[doc(hidden)]
Expand Down
8 changes: 2 additions & 6 deletions substrate/frame/support/procedural/src/pallet/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,8 @@ storage item. Otherwise, all storage items are listed among [*Type Definitions*]
#composites
);

def.item
.content
.as_mut()
.expect("This is checked by parsing")
.1
.push(syn::Item::Verbatim(new_items));
let item = &mut def.item.content.as_mut().expect("This is checked by parsing").1;
item.push(syn::Item::Verbatim(new_items));

def.item.into_token_stream()
}
Loading
Loading