Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Update to latest changes in scale-info #5

Merged
merged 7 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ members = [
exclude = [
"examples/",
]

[patch.crates-io]
scale-info = { git = "https://github.com/paritytech/scale-info", branch = "aj-substrate" }
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Andrew Jones <[email protected]>"]
edition = "2018"

[dependencies]
frame-metadata = { package = "frame-metadata", git = "https://github.com/paritytech/frame-metadata", branch = "aj-substrate", default-features = false, features = ["v13"] }
frame-metadata = { package = "frame-metadata", git = "https://github.com/paritytech/frame-metadata", branch = "aj-substrate", default-features = false, features = ["v14"] }
heck = "0.3.1"
proc-macro2 = "1.0"
quote = "1"
Expand Down
Binary file modified core/node-runtime.scale
Binary file not shown.
6 changes: 3 additions & 3 deletions core/src/generate_runtime.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::{TokenStream2, TypeGenerator};
use frame_metadata::{v13::RuntimeMetadataV13, RuntimeMetadata, RuntimeMetadataPrefixed};
use frame_metadata::{v14::RuntimeMetadataV14, RuntimeMetadata, RuntimeMetadataPrefixed};
use heck::SnakeCase as _;
use quote::{format_ident, quote};
use scale_info::prelude::string::ToString;

pub struct RuntimeGenerator {
metadata: RuntimeMetadataV13,
metadata: RuntimeMetadataV14,
}

impl RuntimeGenerator {
pub fn new(metadata: RuntimeMetadataPrefixed) -> Self {
match metadata.1 {
RuntimeMetadata::V13(v13) => Self { metadata: v13 },
RuntimeMetadata::V14(v14) => Self { metadata: v14 },
_ => panic!("Unsupported metadata version {:?}", metadata.1),
}
}
Expand Down
41 changes: 25 additions & 16 deletions core/src/generate_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use proc_macro2::{Ident, Span, TokenStream as TokenStream2, TokenStream};
use quote::{format_ident, quote, ToTokens};
use scale_info::{
form::PortableForm, prelude::num::NonZeroU32, Field, PortableRegistry, Type, TypeDef,
form::PortableForm, Field, PortableRegistry, Type, TypeDef,
TypeDefPrimitive,
};
use std::collections::{BTreeMap, HashSet};
Expand Down Expand Up @@ -60,7 +60,7 @@ impl<'a> TypeGenerator<'a> {
fn insert_type(
&'a self,
ty: Type<PortableForm>,
id: NonZeroU32,
id: u32,
path: Vec<String>,
root_mod_ident: &Ident,
module: &mut Module<'a>,
Expand All @@ -87,7 +87,7 @@ impl<'a> TypeGenerator<'a> {
/// If no type with the given id found in the type registry.
pub fn resolve_type_path(
&self,
id: NonZeroU32,
id: u32,
parent_type_params: &[TypeParameter],
) -> TypePath {
if let Some(parent_type_param) = parent_type_params
Expand All @@ -114,7 +114,7 @@ impl<'a> TypeGenerator<'a> {
TypeDef::Sequence(seq) => vec![seq.type_param().id()],
TypeDef::Tuple(tuple) => tuple.fields().iter().map(|f| f.id()).collect(),
TypeDef::Compact(compact) => vec![compact.type_param().id()],
TypeDef::Phantom(phantom) => vec![phantom.type_param().id()],
TypeDef::Phantom(_phantom) => vec![/* TODO [now]: this is not yet in the `aj-substrate` branch phantom.type_param().id() */],
Copy link
Owner

Choose a reason for hiding this comment

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

Actually I have remove that here: paritytech/scale-info#96, and aj-substrate includes that PR. We need to figure out whether we still have enough information to generate the correct types. We probably should, but it needs testing out on this side.

_ => ty.type_params().iter().map(|f| f.id()).collect(),
};

Expand Down Expand Up @@ -328,11 +328,14 @@ impl<'a> ModuleType<'a> {
let mut fields_tokens = fields
.iter()
.map(|(name, ty, ty_name)| {
let ty = ty_toks(ty_name, ty);
if is_struct {
quote! { pub #name: #ty }
} else {
quote! { #name: #ty }
match ty_name {
Some(ty_name) if is_struct => {
let ty = ty_toks(ty_name, ty);
quote! { pub #name: #ty }
}
_ => {
quote! { #name: #ty }
}
}
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -364,11 +367,14 @@ impl<'a> ModuleType<'a> {
let mut fields_tokens = type_paths
.iter()
.map(|(ty, ty_name)| {
let ty = ty_toks(ty_name, ty);
if is_struct {
quote! { pub #ty }
} else {
quote! { #ty }
match ty_name {
Some(ty_name) if is_struct => {
let ty = ty_toks(ty_name, ty);
quote! { pub #ty }
}
_ => {
quote! { #ty }
}
}
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -506,11 +512,14 @@ impl TypePathType {
syn::Type::Path(path)
}
TypeDef::Phantom(_) => {
/* TODO: [now]: As soon as branch `aj-substrate` is updated to contain new code for
* TypeDefPhantom this goes back, use `()` for the time being.
let type_param = params
.iter()
.next()
.expect("a phantom type should have a single type parameter");
let type_path = syn::parse_quote! { core::marker::PhantomData<#type_param> };
*/
Copy link
Owner

Choose a reason for hiding this comment

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

Yes, aj-substrate is in flux atm - should stabilize in the next day or two once I get polkadot compiling.

let type_path = syn::parse_quote! { core::marker::PhantomData<()> };
syn::Type::Path(type_path)
}
TypeDef::Compact(_) => {
Expand Down Expand Up @@ -540,7 +549,7 @@ impl TypePathType {

#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct TypeParameter {
concrete_type_id: NonZeroU32,
concrete_type_id: u32,
name: proc_macro2::Ident,
}

Expand Down