-
Notifications
You must be signed in to change notification settings - Fork 660
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
Metadata V16 (unstable): Enrich metadata with associated types of config traits #5274
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
types Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: https://forum.polkadot.network/t/metadata-v16-updates/9557/1 |
@@ -320,12 +345,30 @@ pub fn replace_self_by_t(input: proc_macro2::TokenStream) -> proc_macro2::TokenS | |||
.collect() | |||
} | |||
|
|||
/// Check that the trait item requires the `TypeInfo` bound (or similar). | |||
fn contains_type_info_bound(ty: &TraitItemType) -> bool { | |||
const KNOWN_TYPE_INFO_BOUNDS: &[&str] = &[ |
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: Why not a Set?
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 we'd need some feature similar to rust-lang/rust#93140 to make the hashSet const here
impl ConfigDef { | ||
pub fn try_from( | ||
frame_system: &syn::Path, | ||
index: usize, | ||
item: &mut syn::Item, | ||
enable_default: bool, | ||
enable_associated_metadata: bool, |
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: maybe disable_associated_metadata
as by default it should be enabled(?)
…associated-types Signed-off-by: Alexandru Vasile <[email protected]>
substrate/frame/support/test/tests/pallet_ui/config_metadata_on_constants.rs
Outdated
Show resolved
Hide resolved
if config_set.len() != config_values.len() { | ||
return Err(syn::Error::new( | ||
span, | ||
"Invalid duplicated attribute for `#[pallet::config]`. Please remove duplicates.", |
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 nice to mention the actual duplicates plus maybe the spans.
|
||
impl syn::parse::Parse for ConfigValue { | ||
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { | ||
if input.peek(keyword::with_default) { |
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.
You want to use this: https://docs.rs/syn/latest/syn/parse/struct.ParseBuffer.html#method.lookahead1
)) | ||
} | ||
|
||
if already_constant { |
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.
So, if I put include_metadata
before constant
, this branch will not be taken.
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.
Thanks for catching this 🙏
Have moved the checks after we iterate over all pallet attributes
substrate/frame/support/src/lib.rs
Outdated
/// ``` | ||
/// | ||
/// For more information, see: | ||
/// * [`#[pallet::include_metadata]`](`include_metadata`) |
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.
Why are you linking include_metadata
when talking about without_metadata
?
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.
This other macro does not really provides more information. More like gives you the opportunity to include selected items.
…n_constants.rs Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
account Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
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.
Looks nice!
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
This feature is part of the upcoming metadata V16. The associated types of the
Config
trait that require theTypeInfo
orParameter
bounds are included in the metadata of the pallet. The metadata is not yet exposed to the end-user, however the metadata intermediate representation (IR) contains these types.Developers can opt out of metadata collection of the associated types by specifying
without_metadata
optional attribute to the#[pallet::config]
.Furthermore, the
without_metadata
argument can be used in combination with the newly added#[pallet::include_metadata]
attribute to selectively include only certain associated types in the metadata collection.API Design
Builds on top of the PoC: #4358
Closes: #4519
cc @paritytech/subxt-team