-
Notifications
You must be signed in to change notification settings - Fork 565
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
base: master
Are you sure you want to change the base?
Conversation
@@ -58,7 +58,6 @@ pub fn expand_runtime_metadata( | |||
#attr | |||
} | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Unrelated change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed it
@@ -97,26 +97,29 @@ impl Parse for RuntimeDeclaration { | |||
let pallets_token = pallets.token; | |||
|
|||
match convert_pallets(pallets.content.inner.into_iter().collect())? { | |||
PalletsConversion::Implicit(pallets) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes of this file look unrelated. I think you'll need to configure the rustfmt to comply with substrate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't notice that it was relying on nightly settings, corrected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weirdly enough even using the settings from rustfmt config it still changes some of the formatting, are some files formatted by hand?
// assert_eq!( | ||
// get_deprecation(&[simple_path]).unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dq: Should we uncomment thsese?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
let simple_path: Attribute = parse_quote!(#[deprecated = #FIRST]); | ||
let meta_list: Attribute = parse_quote!(#[deprecated(note = #FIRST)]); | ||
let meta_list_with_since: Attribute = | ||
parse_quote!(#[deprecated(note = #FIRST, since = #SECOND)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be interesting to see how this behaves with extra parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will just ignore them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can turn that into a compile error? And specify inside the message the forms we support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a compiler error already, that's one of the reason why i decided to use rust's deprecated. But the parsing now doesnt fail if attribute is malformed(not sure how useful it is tho)
@@ -441,6 +441,7 @@ fn expected_metadata() -> PalletStorageMetadataIR { | |||
ty: StorageEntryTypeIR::Plain(scale_info::meta_type::<u32>()), | |||
default: vec![0, 0, 0, 0], | |||
docs: vec![], | |||
deprecation_info: sp_metadata_ir::DeprecationStatus::NotDeprecated, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a few tests similar to these (with/without note=.. since=..):
- check deprecation info for storage entries
- check deprecation info for runtime APIs for individual methods and for the trait itself
- check deprecation info for constants
This way we'll also have a good example and see the API in action from the user's perspective
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more testcases for StorageEntryMetadataIr
and constants metadata
} | ||
|
||
Ok(().into()) | ||
} | ||
} | ||
|
||
#[pallet::storage] | ||
#[deprecated] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice test here! Bikeshedding on the attribute naming; how would pallet::depreacated
sound like? Would it bring more clarity to the user that this is related entirely to the metadata collection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, but that would introduce the need to use two separate deprecation attributes, one for metadata and one for rustc deprecation warnings. Or that's totally ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would make it a bit clear that the deprecation
tag is collected into the metadata. Then, the pallet::deprecated
could insert under the hood the deprecated
attribute to the type, and propagate DeprecationInfo
to the metadata. Up to you in the end, I have no strong pref here :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about sp-api-proc-macro
stuff? should it also be pallet::deprecated
there or for example api::deprecated
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can go with the default deprecation
tag for now, I would focus on the metadata collection first, we can come back and change it later if needed
Nice work here @pkhry! Certainly off to a good start! 👍 Left a few thoughts after the initial review, mainly:
From the CI step: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6513912:
After that we can have a look at exposing deprecation info for events / errors (maybe in a separate PR), your initial approach of using a |
f0008e0
to
c8d2285
Compare
The CI pipeline was cancelled due to failure one of the required jobs. |
Description:
Adds
DeprecationStatus
enum to sp_metadata_ir.Adds
deprecation_info
field to-
RuntimeApiMetadataIR
-
RuntimeApiMethodMetadataIR
-
StorageEntryMetadataIR
-
PalletConstantMetadataIR
There's also some test updates to make sure that deprecation attributes are getting propagated to the relevant structs.
see: #4098, Solution: A
TODO(to be done in separate MR):
Add a
Btree<T::Type, DeprecationStatus>
toPalletMetadataIR
to store deprecation info on Pallet events and errors and have the ability to query deprecation info byT::Type
.updated MetadataIr would like like this:
Note that it's not really possible to put deprecation metadata on Events and Errors themselves as they are required to have
From<MetaType>
impls.PS:
i used
cargo +nightly fmt --all
andcargo +nightly-2024-04-10 fmt --all
and still getting line changes due to formatting, what's the correct incantation?