Unverified Commit 68318131 authored by Andrew Jones's avatar Andrew Jones Committed by GitHub
Browse files

Update to new scale-info and codec releases (#663)

* Update to scale-info 0.5

* Update TypeInfo manual impls

* Update parity-scale-code to 2.0

* Add Encode ?Sized bounds

* Change type display name for Key custom TypeInfo impl

* Add missing ?Sized constraint

* Fmt

* Missing ?Sized bound in example
parent 2d10a700
Pipeline #122650 failed with stages
in 10 minutes and 21 seconds
......@@ -20,7 +20,7 @@ ink_allocator = { version = "3.0.0-rc2", path = "../allocator/", default-feature
ink_primitives = { version = "3.0.0-rc2", path = "../primitives/", default-features = false }
ink_prelude = { version = "3.0.0-rc2", path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
num-traits = { version = "0.2", default-features = false, features = ["i128"] }
cfg-if = "1.0"
......@@ -38,7 +38,7 @@ blake2 = { version = "0.9", optional = true }
# Sadly couldn't be marked as dev-dependency.
# Never use this crate outside of the off-chain environment!
rand = { version = "0.8", default-features = false, features = ["alloc"], optional = true }
scale-info = { version = "0.4", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "0.5", default-features = false, features = ["derive"], optional = true }
[features]
default = ["std"]
......
......@@ -152,7 +152,7 @@ where
}
#[inline]
fn encode_to<O: scale::Output>(&self, output: &mut O) {
fn encode_to<O: scale::Output + ?Sized>(&self, output: &mut O) {
<T as scale::Encode>::encode_to(&self.arg, output)
}
}
......@@ -164,7 +164,7 @@ impl scale::Encode for EmptyArgumentList {
}
#[inline]
fn encode_to<O: scale::Output>(&self, _output: &mut O) {}
fn encode_to<O: scale::Output + ?Sized>(&self, _output: &mut O) {}
}
impl<'a, Head, Rest> scale::Encode for ArgumentList<Argument<Head>, Rest>
......@@ -178,7 +178,7 @@ where
}
#[inline]
fn encode_to<O: scale::Output>(&self, output: &mut O) {
fn encode_to<O: scale::Output + ?Sized>(&self, output: &mut O) {
// We reverse the order of encoding because we build up the list of
// arguments in reverse order, too. This way we encode the arguments
// in the same order in which they have been pushed to the argument list
......@@ -198,7 +198,7 @@ where
}
#[inline]
fn encode_to<O: scale::Output>(&self, output: &mut O) {
fn encode_to<O: scale::Output + ?Sized>(&self, output: &mut O) {
scale::Encode::encode_to(&self.selector, output);
scale::Encode::encode_to(&self.args, output);
}
......
......@@ -74,7 +74,7 @@ impl scale::Encode for CallData {
self.bytes.len()
}
fn encode_to<T: scale::Output>(&self, dest: &mut T) {
fn encode_to<T: scale::Output + ?Sized>(&self, dest: &mut T) {
dest.write(self.bytes.as_slice());
}
}
......
......@@ -229,7 +229,7 @@ where
}
#[inline]
fn encode_to<T: scale::Output>(&self, dest: &mut T) {
fn encode_to<T: scale::Output + ?Sized>(&self, dest: &mut T) {
self.prefix.encode_to(dest);
self.value.encode_to(dest);
}
......
......@@ -22,7 +22,7 @@ ink_metadata = { version = "3.0.0-rc2", path = "../metadata", default-features =
ink_prelude = { version = "3.0.0-rc2", path = "../prelude/", default-features = false }
ink_lang_macro = { version = "3.0.0-rc2", path = "macro", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from"] }
static_assertions = "1.1"
......
......@@ -19,7 +19,7 @@ ink_lang_ir = { version = "3.0.0-rc2", path = "../ir", default-features = false
ink_lang_codegen = { version = "3.0.0-rc2", path = "../codegen", default-features = false }
ink_primitives = { version = "3.0.0-rc2", path = "../../primitives/", default-features = false }
scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
syn = "1"
proc-macro2 = "1"
......@@ -30,7 +30,7 @@ ink_storage = { version = "3.0.0-rc2", path = "../../storage/" }
ink_lang = { version = "3.0.0-rc2", path = ".." }
trybuild = "1.0.24"
scale-info = { version = "0.4", default-features = false, features = ["derive"] }
scale-info = { version = "0.5", default-features = false, features = ["derive"] }
[lib]
name = "ink_lang_macro"
......
......@@ -21,7 +21,7 @@ ink_primitives = { version = "3.0.0-rc2", path = "../primitives/", default-featu
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
impl-serde = "0.3.1"
derive_more = { version = "0.99", default-features = false, features = ["from"] }
scale-info = { version = "0.4", default-features = false, features = ["derive"] }
scale-info = { version = "0.5", default-features = false, features = ["derive", "serde"] }
[dev-dependencies]
pretty_assertions = "0.6.1"
......
......@@ -27,12 +27,12 @@ use ink_prelude::collections::btree_map::BTreeMap;
use ink_primitives::Key;
use scale_info::{
form::{
CompactForm,
Form,
MetaForm,
PortableForm,
},
meta_type,
IntoCompact,
IntoPortable,
Registry,
TypeInfo,
};
......@@ -146,10 +146,10 @@ impl CellLayout {
}
}
impl IntoCompact for CellLayout {
type Output = CellLayout<CompactForm>;
impl IntoPortable for CellLayout {
type Output = CellLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
CellLayout {
key: self.key,
ty: registry.register_type(&self.ty),
......@@ -157,22 +157,26 @@ impl IntoCompact for CellLayout {
}
}
impl IntoCompact for Layout {
type Output = Layout<CompactForm>;
impl IntoPortable for Layout {
type Output = Layout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
match self {
Layout::Cell(encoded_cell) => {
Layout::Cell(encoded_cell.into_compact(registry))
Layout::Cell(encoded_cell.into_portable(registry))
}
Layout::Hash(hash_layout) => {
Layout::Hash(hash_layout.into_portable(registry))
}
Layout::Hash(hash_layout) => Layout::Hash(hash_layout.into_compact(registry)),
Layout::Array(array_layout) => {
Layout::Array(array_layout.into_compact(registry))
Layout::Array(array_layout.into_portable(registry))
}
Layout::Struct(struct_layout) => {
Layout::Struct(struct_layout.into_compact(registry))
Layout::Struct(struct_layout.into_portable(registry))
}
Layout::Enum(enum_layout) => {
Layout::Enum(enum_layout.into_portable(registry))
}
Layout::Enum(enum_layout) => Layout::Enum(enum_layout.into_compact(registry)),
}
}
}
......@@ -209,14 +213,14 @@ pub struct HashLayout<F: Form = MetaForm> {
layout: Box<Layout<F>>,
}
impl IntoCompact for HashLayout {
type Output = HashLayout<CompactForm>;
impl IntoPortable for HashLayout {
type Output = HashLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
HashLayout {
offset: self.offset,
strategy: self.strategy,
layout: Box::new(self.layout.into_compact(registry)),
layout: Box::new(self.layout.into_portable(registry)),
}
}
}
......@@ -380,15 +384,15 @@ where
}
}
impl IntoCompact for ArrayLayout {
type Output = ArrayLayout<CompactForm>;
impl IntoPortable for ArrayLayout {
type Output = ArrayLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ArrayLayout {
offset: self.offset,
len: self.len,
cells_per_elem: self.cells_per_elem,
layout: Box::new(self.layout.into_compact(registry)),
layout: Box::new(self.layout.into_portable(registry)),
}
}
}
......@@ -426,15 +430,15 @@ where
}
}
impl IntoCompact for StructLayout {
type Output = StructLayout<CompactForm>;
impl IntoPortable for StructLayout {
type Output = StructLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
StructLayout {
fields: self
.fields
.into_iter()
.map(|field| field.into_compact(registry))
.map(|field| field.into_portable(registry))
.collect::<Vec<_>>(),
}
}
......@@ -492,13 +496,13 @@ where
}
}
impl IntoCompact for FieldLayout {
type Output = FieldLayout<CompactForm>;
impl IntoPortable for FieldLayout {
type Output = FieldLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
FieldLayout {
name: self.name.map(|name| name.into_compact(registry)),
layout: self.layout.into_compact(registry),
name: self.name.map(|name| name.into_portable(registry)),
layout: self.layout.into_portable(registry),
}
}
}
......@@ -563,17 +567,17 @@ where
}
}
impl IntoCompact for EnumLayout {
type Output = EnumLayout<CompactForm>;
impl IntoPortable for EnumLayout {
type Output = EnumLayout<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
EnumLayout {
dispatch_key: self.dispatch_key,
variants: self
.variants
.into_iter()
.map(|(discriminant, layout)| {
(discriminant, layout.into_compact(registry))
(discriminant, layout.into_portable(registry))
})
.collect(),
}
......
......@@ -44,7 +44,7 @@ fn named_fields_struct_layout(key_ptr: &mut KeyPtr) -> Layout {
fn named_fields_work() {
let layout = named_fields_struct_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry);
let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! {
{
......@@ -101,7 +101,7 @@ fn tuple_struct_layout(key_ptr: &mut KeyPtr) -> Layout {
fn tuple_struct_work() {
let layout = tuple_struct_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry);
let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! {
{
......@@ -156,7 +156,7 @@ fn clike_enum_layout(key_ptr: &mut KeyPtr) -> Layout {
fn clike_enum_work() {
let layout = clike_enum_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry);
let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! {
{
......@@ -237,7 +237,7 @@ fn mixed_enum_layout(key_ptr: &mut KeyPtr) -> Layout {
fn mixed_enum_work() {
let layout = mixed_enum_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry);
let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! {
{
......@@ -336,7 +336,7 @@ fn unbounded_hashing_layout(key_ptr: &mut KeyPtr) -> Layout {
fn unbounded_layout_works() {
let layout = unbounded_hashing_layout(&mut KeyPtr::from(Key::from([0x00; 32])));
let mut registry = Registry::new();
let compacted = layout.into_compact(&mut registry);
let compacted = layout.into_portable(&mut registry);
let json = serde_json::to_value(&compacted).unwrap();
let expected = serde_json::json! {
{
......
......@@ -47,25 +47,30 @@ use impl_serde::serialize as serde_hex;
#[cfg(feature = "derive")]
use scale_info::{
form::CompactForm,
IntoCompact as _,
form::{
FormString,
PortableForm,
},
IntoPortable as _,
PortableRegistry,
Registry,
RegistryReadOnly,
};
use serde::{
de::DeserializeOwned,
Deserialize,
Serialize,
};
/// An entire ink! project for metadata file generation purposes.
#[derive(Debug, Serialize, Deserialize)]
pub struct InkProject {
#[serde(bound(deserialize = "S: DeserializeOwned"))]
pub struct InkProject<S: FormString = &'static str> {
#[serde(flatten)]
registry: RegistryReadOnly,
registry: PortableRegistry<S>,
#[serde(rename = "storage")]
/// The layout of the storage data structure
layout: layout::Layout<CompactForm>,
spec: ContractSpec<CompactForm>,
layout: layout::Layout<PortableForm<S>>,
spec: ContractSpec<PortableForm<S>>,
}
impl InkProject {
......@@ -77,26 +82,29 @@ impl InkProject {
let mut registry = Registry::new();
Self {
layout: layout.into().into_compact(&mut registry),
spec: spec.into().into_compact(&mut registry),
layout: layout.into().into_portable(&mut registry),
spec: spec.into().into_portable(&mut registry),
registry: registry.into(),
}
}
}
impl InkProject {
impl<S> InkProject<S>
where
S: FormString,
{
/// Returns a read-only registry of types in the contract.
pub fn registry(&self) -> &RegistryReadOnly {
pub fn registry(&self) -> &PortableRegistry<S> {
&self.registry
}
/// Returns the storage layout of the contract.
pub fn layout(&self) -> &layout::Layout<CompactForm> {
pub fn layout(&self) -> &layout::Layout<PortableForm<S>> {
&self.layout
}
/// Returns the specification of the contract.
pub fn spec(&self) -> &ContractSpec<CompactForm> {
pub fn spec(&self) -> &ContractSpec<PortableForm<S>> {
&self.spec
}
}
......@@ -24,12 +24,12 @@ use alloc::{
use core::marker::PhantomData;
use scale_info::{
form::{
CompactForm,
Form,
MetaForm,
PortableForm,
},
meta_type,
IntoCompact,
IntoPortable,
Registry,
TypeInfo,
};
......@@ -56,27 +56,27 @@ pub struct ContractSpec<F: Form = MetaForm> {
docs: Vec<F::String>,
}
impl IntoCompact for ContractSpec {
type Output = ContractSpec<CompactForm>;
impl IntoPortable for ContractSpec {
type Output = ContractSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ContractSpec {
constructors: self
.constructors
.into_iter()
.map(|constructor| constructor.into_compact(registry))
.map(|constructor| constructor.into_portable(registry))
.collect::<Vec<_>>(),
messages: self
.messages
.into_iter()
.map(|msg| msg.into_compact(registry))
.map(|msg| msg.into_portable(registry))
.collect::<Vec<_>>(),
events: self
.events
.into_iter()
.map(|event| event.into_compact(registry))
.map(|event| event.into_portable(registry))
.collect::<Vec<_>>(),
docs: registry.map_into_compact(self.docs),
docs: registry.map_into_portable(self.docs),
}
}
}
......@@ -232,19 +232,19 @@ pub struct ConstructorSpec<F: Form = MetaForm> {
pub docs: Vec<F::String>,
}
impl IntoCompact for ConstructorSpec {
type Output = ConstructorSpec<CompactForm>;
impl IntoPortable for ConstructorSpec {
type Output = ConstructorSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ConstructorSpec {
name: registry.map_into_compact(self.name),
name: registry.map_into_portable(self.name),
selector: self.selector,
args: self
.args
.into_iter()
.map(|arg| arg.into_compact(registry))
.map(|arg| arg.into_portable(registry))
.collect::<Vec<_>>(),
docs: registry.map_into_compact(self.docs),
docs: registry.map_into_portable(self.docs),
}
}
}
......@@ -609,22 +609,22 @@ impl
}
}
impl IntoCompact for MessageSpec {
type Output = MessageSpec<CompactForm>;
impl IntoPortable for MessageSpec {
type Output = MessageSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
MessageSpec {
name: registry.map_into_compact(self.name),
name: registry.map_into_portable(self.name),
selector: self.selector,
mutates: self.mutates,
payable: self.payable,
args: self
.args
.into_iter()
.map(|arg| arg.into_compact(registry))
.map(|arg| arg.into_portable(registry))
.collect::<Vec<_>>(),
return_type: self.return_type.into_compact(registry),
docs: registry.map_into_compact(self.docs),
return_type: self.return_type.into_portable(registry),
docs: registry.map_into_portable(self.docs),
}
}
}
......@@ -678,18 +678,18 @@ impl EventSpecBuilder {
}
}
impl IntoCompact for EventSpec {
type Output = EventSpec<CompactForm>;
impl IntoPortable for EventSpec {
type Output = EventSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
EventSpec {
name: self.name.into_compact(registry),
name: self.name.into_portable(registry),
args: self
.args
.into_iter()
.map(|arg| arg.into_compact(registry))
.map(|arg| arg.into_portable(registry))
.collect::<Vec<_>>(),
docs: registry.map_into_compact(self.docs),
docs: registry.map_into_portable(self.docs),
}
}
}
......@@ -808,13 +808,13 @@ pub struct TypeSpec<F: Form = MetaForm> {
display_name: DisplayName<F>,
}
impl IntoCompact for TypeSpec {
type Output = TypeSpec<CompactForm>;
impl IntoPortable for TypeSpec {
type Output = TypeSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
TypeSpec {
ty: registry.register_type(&self.ty),
display_name: self.display_name.into_compact(registry),
display_name: self.display_name.into_portable(registry),
}
}
}
......@@ -907,15 +907,15 @@ pub struct EventParamSpec<F: Form = MetaForm> {
docs: Vec<F::String>,
}
impl IntoCompact for EventParamSpec {
type Output = EventParamSpec<CompactForm>;
impl IntoPortable for EventParamSpec {
type Output = EventParamSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
EventParamSpec {
name: self.name.into_compact(registry),
name: self.name.into_portable(registry),
indexed: self.indexed,
ty: self.ty.into_compact(registry),
docs: registry.map_into_compact(self.docs),
ty: self.ty.into_portable(registry),
docs: registry.map_into_portable(self.docs),
}
}
}
......@@ -1015,14 +1015,14 @@ pub struct ReturnTypeSpec<F: Form = MetaForm> {
opt_type: Option<TypeSpec<F>>,
}
impl IntoCompact for ReturnTypeSpec {
type Output = ReturnTypeSpec<CompactForm>;
impl IntoPortable for ReturnTypeSpec {
type Output = ReturnTypeSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
ReturnTypeSpec {
opt_type: self
.opt_type
.map(|opt_type| opt_type.into_compact(registry)),
.map(|opt_type| opt_type.into_portable(registry)),
}
}
}
......@@ -1071,13 +1071,13 @@ pub struct MessageParamSpec<F: Form = MetaForm> {
ty: TypeSpec<F>,
}
impl IntoCompact for MessageParamSpec {
type Output = MessageParamSpec<CompactForm>;
impl IntoPortable for MessageParamSpec {
type Output = MessageParamSpec<PortableForm>;
fn into_compact(self, registry: &mut Registry) -> Self::Output {
fn into_portable(self, registry: &mut Registry) -> Self::Output {
MessageParamSpec {
name: self.name.into_compact(registry),
ty: self.ty.into_compact(registry),
name: self.name.into_portable(registry),
ty: self.ty.into_portable(registry),