Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation info support in RuntimeMetadataIR #4851

Merged
merged 43 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4188611
WIP: storage macro errors out
pkhry Jun 18, 2024
f9312f9
update tests for methods and storage
pkhry Jun 19, 2024
64161bd
WIP: no events and errors
pkhry Jun 20, 2024
4d977a1
use +nightly fmt
pkhry Jun 26, 2024
6147dc1
update deprecation attribute parsing
pkhry Jun 26, 2024
b815256
add some more test-cases for deprecation
pkhry Jun 26, 2024
a7f577f
add prdoc and license
pkhry Jun 26, 2024
f69854c
prdoc typo
pkhry Jun 26, 2024
6dee2a6
fix clippy lints
pkhry Jun 26, 2024
7fc2026
cargo fmt
pkhry Jun 26, 2024
c8d2285
cargo fmt
pkhry Jun 27, 2024
6285ebb
fixup typo and test errors
pkhry Jun 27, 2024
c04eb6f
cargo fmt
pkhry Jun 27, 2024
5abb44e
fix clippy lints
pkhry Jun 27, 2024
21f032f
more clippy fixes
pkhry Jun 27, 2024
155f2e3
unwrap() -> compile_error!
pkhry Jul 15, 2024
8b2b802
better error message
pkhry Jul 18, 2024
9461e7a
Add deprecation for Calls,Events,Errors,Pallet (#4948)
pkhry Aug 1, 2024
13e0ae9
Merge remote-tracking branch 'origin/master' into pkhry/deprecation_a…
pkhry Aug 1, 2024
1a79953
fixup test
pkhry Aug 1, 2024
227b709
Fixup prdoc and tests
pkhry Aug 7, 2024
bb1e568
clippy
pkhry Aug 7, 2024
131766c
Merge remote-tracking branch 'origin/master' into pkhry/deprecation_a…
pkhry Aug 14, 2024
0dbe299
Merge remote-tracking branch 'origin/master' into pkhry/deprecation_a…
pkhry Sep 2, 2024
2c26d7c
update PrDoc
pkhry Sep 2, 2024
1a37a74
update PrDoc
pkhry Sep 2, 2024
daa64ac
Fixup docs
pkhry Sep 2, 2024
0c8f81a
Update from pkhry running command 'fmt'
actions-user Sep 2, 2024
37ad815
Update from pkhry running command 'update-ui'
actions-user Sep 2, 2024
dca578a
Merge branch 'master' into pkhry/deprecation_attr_frame_support
pkhry Sep 2, 2024
85b2530
fixup doc once more
pkhry Sep 3, 2024
8d90615
".git/.scripts/commands/fmt/fmt.sh"
Sep 4, 2024
72a5a92
add hackmd link to the prdoc
pkhry Sep 4, 2024
4932d41
Apply suggestions from code review
pkhry Sep 5, 2024
c04009d
Update substrate/frame/support/procedural/src/pallet/expand/storage.rs
pkhry Sep 5, 2024
037b4df
review comments
pkhry Sep 5, 2024
a61ac39
review comments
pkhry Sep 5, 2024
8d57f2f
rename Enum deprecation cases
pkhry Sep 5, 2024
8bb7c57
".git/.scripts/commands/fmt/fmt.sh"
Sep 5, 2024
82908b1
Merge branch 'master' into pkhry/deprecation_attr_frame_support
pkhry Sep 6, 2024
9a8bc35
update ui-test
pkhry Sep 9, 2024
c747296
Merge branch 'master' into pkhry/deprecation_attr_frame_support
bkchr Sep 11, 2024
9c618d8
update-ui test
pkhry Sep 11, 2024
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
40 changes: 40 additions & 0 deletions prdoc/pr_4851.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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: Add support for deprecation metadata in `RuntimeMetadataIr` entries.

doc:
- audience:
- Runtime dev
- Runtime user
description: |
Changes introduced are listed below.
Adds `DeprecationStatusIR` enum to sp_metadata_ir.
- Is a deprecation info for simple items.
Adds `DeprecationInfoIR` enum to sp_metadata_ir.
- It is a deprecation info for an enums/errors/calls. Contains `DeprecationStatusIR`.
Also denotes full/partial deprecation of the type or its variants/calls.
Adds `deprecation_info` field to
- `RuntimeApiMetadataIR`
- `RuntimeApiMethodMetadataIR`
- `StorageEntryMetadataIR`
- `PalletConstantMetadataIR`
- `PalletCallMetadataIR`
- `PalletMetadataIR`
- `PalletEventMetadataIR`
- `PalletErrorMetadataIR`
Examples of the deprecation info produced can be seen inside
- Tests for `frame-support`
- hackmd link https://hackmd.io/@Zett98/Bys0YgbcR

crates:
- name: frame-support-procedural
bump: patch
- name: frame-support
bump: major
- name: sp-api-proc-macro
bump: patch
- name: sp-api
bump: patch
- name: sp-metadata-ir
bump: major
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn derive_impl_works_with_no_aggregated_types() {
type Block = super::Block;
type AccountId = super::AccountId;
type PalletInfo = super::PalletInfo;
type ExampleConstant = ();
}

assert_type_eq_all!(<DummyRuntime as Config>::RuntimeOrigin, ());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// 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.
#![allow(deprecated, clippy::deprecated_semver)]

use super::{frame_system, Block};
use crate::derive_impl;
Expand Down Expand Up @@ -121,6 +122,7 @@ mod runtime {
// Ensure that the runtime does not export the calls from the pallet
#[runtime::pallet_index(4)]
#[runtime::disable_call]
#[deprecated = "example"]
pub type PalletWithDisabledCall = pallet_with_disabled_call::Pallet<Runtime>;

// Ensure that the runtime does not export the unsigned calls from the pallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn expand_runtime_metadata(
let index = &decl.index;
let storage = expand_pallet_metadata_storage(&filtered_names, runtime, decl);
let calls = expand_pallet_metadata_calls(&filtered_names, runtime, decl);
let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl);
let event = expand_pallet_metadata_events(&filtered_names, runtime, decl);
let constants = expand_pallet_metadata_constants(runtime, decl);
let errors = expand_pallet_metadata_errors(runtime, decl);
let docs = expand_pallet_metadata_docs(runtime, decl);
Expand All @@ -58,7 +58,7 @@ pub fn expand_runtime_metadata(
#attr
}
});

pkhry marked this conversation as resolved.
Show resolved Hide resolved
let deprecation_info = expand_pallet_metadata_deprecation(runtime, decl);
quote! {
#attr
#scrate::__private::metadata_ir::PalletMetadataIR {
Expand All @@ -70,6 +70,7 @@ pub fn expand_runtime_metadata(
constants: #constants,
error: #errors,
docs: #docs,
deprecation_info: #deprecation_info,
}
}
})
Expand Down Expand Up @@ -200,7 +201,6 @@ fn expand_pallet_metadata_calls(
fn expand_pallet_metadata_events(
filtered_names: &[&'static str],
runtime: &Ident,
scrate: &TokenStream,
decl: &Pallet,
) -> TokenStream {
if filtered_names.contains(&"Event") {
Expand All @@ -220,16 +220,21 @@ fn expand_pallet_metadata_events(

quote! {
Some(
#scrate::__private::metadata_ir::PalletEventMetadataIR {
ty: #scrate::__private::scale_info::meta_type::<#pallet_event>()
}
#pallet_event::event_metadata::<#pallet_event>()
)
}
} else {
quote!(None)
}
}

fn expand_pallet_metadata_deprecation(runtime: &Ident, decl: &Pallet) -> TokenStream {
let path = &decl.path;
let instance = decl.instance.as_ref().into_iter();

quote! { #path::Pallet::<#runtime #(, #path::#instance)*>::deprecation_info() }
}

fn expand_pallet_metadata_constants(runtime: &Ident, decl: &Pallet) -> TokenStream {
let path = &decl.path;
let instance = decl.instance.as_ref().into_iter();
Expand Down
35 changes: 19 additions & 16 deletions substrate/frame/support/procedural/src/construct_runtime/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ impl Parse for WhereSection {
definitions.push(definition);
if !input.peek(Token![,]) {
if !input.peek(token::Brace) {
return Err(input.error("Expected `,` or `{`"))
return Err(input.error("Expected `,` or `{`"));
}
break
break;
}
input.parse::<Token![,]>()?;
}
Expand All @@ -144,7 +144,7 @@ impl Parse for WhereSection {
"`{:?}` was declared above. Please use exactly one declaration for `{:?}`.",
kind, kind
);
return Err(Error::new(*kind_span, msg))
return Err(Error::new(*kind_span, msg));
}
Ok(Self { span: input.span() })
}
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Parse for WhereDefinition {
} else if lookahead.peek(keyword::UncheckedExtrinsic) {
(input.parse::<keyword::UncheckedExtrinsic>()?.span(), WhereKind::UncheckedExtrinsic)
} else {
return Err(lookahead.error())
return Err(lookahead.error());
};

let _: Token![=] = input.parse()?;
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Parse for PalletDeclaration {
{
return Err(input.error(
"Unexpected tokens, expected one of `::{`, `exclude_parts`, `use_parts`, `=`, `,`",
))
));
} else {
is_expanded.then_some(extra_parts)
};
Expand All @@ -283,7 +283,7 @@ impl Parse for PalletDeclaration {
let _: keyword::use_parts = input.parse()?;
SpecifiedParts::Use(parse_pallet_parts_no_generic(input)?)
} else if !input.peek(Token![=]) && !input.peek(Token![,]) && !input.is_empty() {
return Err(input.error("Unexpected tokens, expected one of `exclude_parts`, `=`, `,`"))
return Err(input.error("Unexpected tokens, expected one of `exclude_parts`, `=`, `,`"));
} else {
SpecifiedParts::All
};
Expand All @@ -295,7 +295,7 @@ impl Parse for PalletDeclaration {
let index = index.base10_parse::<u8>()?;
Some(index)
} else if !input.peek(Token![,]) && !input.is_empty() {
return Err(input.error("Unexpected tokens, expected one of `=`, `,`"))
return Err(input.error("Unexpected tokens, expected one of `=`, `,`"));
} else {
None
};
Expand Down Expand Up @@ -339,7 +339,7 @@ impl Parse for PalletPath {
let ident = input.call(Ident::parse_any)?;
res.inner.segments.push(ident.into());
} else {
return Err(lookahead.error())
return Err(lookahead.error());
}

while input.peek(Token![::]) && input.peek3(Ident) {
Expand Down Expand Up @@ -370,7 +370,7 @@ fn parse_pallet_parts(input: ParseStream) -> Result<Vec<PalletPart>> {
"`{}` was already declared before. Please remove the duplicate declaration",
part.name(),
);
return Err(Error::new(part.keyword.span(), msg))
return Err(Error::new(part.keyword.span(), msg));
}
}

Expand Down Expand Up @@ -505,7 +505,7 @@ impl Parse for PalletPart {
keyword.name(),
valid_generics,
);
return Err(syn::Error::new(keyword.span(), msg))
return Err(syn::Error::new(keyword.span(), msg));
}

Ok(Self { keyword, generics })
Expand Down Expand Up @@ -566,7 +566,7 @@ fn parse_pallet_parts_no_generic(input: ParseStream) -> Result<Vec<PalletPartNoG
"`{}` was already declared before. Please remove the duplicate declaration",
part.keyword.name(),
);
return Err(Error::new(part.keyword.span(), msg))
return Err(Error::new(part.keyword.span(), msg));
}
}

Expand All @@ -592,6 +592,8 @@ pub struct Pallet {
pub cfg_pattern: Vec<cfg_expr::Expression>,
/// The doc literals
pub docs: Vec<syn::Expr>,
/// attributes
pub attrs: Vec<syn::Attribute>,
}

impl Pallet {
Expand Down Expand Up @@ -650,7 +652,7 @@ enum PalletsConversion {
/// incrementally from last explicit or 0.
fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConversion> {
if pallets.iter().any(|pallet| pallet.pallet_parts.is_none()) {
return Ok(PalletsConversion::Implicit(pallets))
return Ok(PalletsConversion::Implicit(pallets));
}

let mut indices = HashMap::new();
Expand Down Expand Up @@ -678,15 +680,15 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
);
let mut err = syn::Error::new(used_pallet.span(), &msg);
err.combine(syn::Error::new(pallet.name.span(), msg));
return Err(err)
return Err(err);
}

if let Some(used_pallet) = names.insert(pallet.name.clone(), pallet.name.span()) {
let msg = "Two pallets with the same name!";

let mut err = syn::Error::new(used_pallet, &msg);
err.combine(syn::Error::new(pallet.name.span(), &msg));
return Err(err)
return Err(err);
}

let mut pallet_parts = pallet.pallet_parts.expect("Checked above");
Expand All @@ -712,7 +714,7 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
}
})
);
return Err(syn::Error::new(part.keyword.span(), msg))
return Err(syn::Error::new(part.keyword.span(), msg));
}
},
SpecifiedParts::All => (),
Expand All @@ -738,7 +740,7 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
if attr.path().segments.first().map_or(false, |s| s.ident != "cfg") {
let msg = "Unsupported attribute, only #[cfg] is supported on pallet \
declarations in `construct_runtime`";
return Err(syn::Error::new(attr.span(), msg))
return Err(syn::Error::new(attr.span(), msg));
}

attr.parse_args_with(|input: syn::parse::ParseStream| {
Expand All @@ -762,6 +764,7 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
cfg_pattern,
pallet_parts,
docs: vec![],
attrs: pallet.attrs.clone(),
})
})
.collect::<Result<Vec<_>>>()?;
Expand Down
Loading
Loading