From 8fd88431d49c036318d398d265c5e975fb1dede6 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 13:28:35 +0100 Subject: [PATCH 01/13] Move storage derives to ink_macro crate --- .gitlab-ci.yml | 2 +- Cargo.toml | 1 - crates/ink/ir/Cargo.toml | 1 - crates/ink/ir/src/ir/storage_item/mod.rs | 34 +++- crates/ink/ir/src/ir/utils.rs | 21 +++ crates/ink/macro/Cargo.toml | 2 + crates/ink/macro/src/lib.rs | 114 ++++++++++++++ crates/ink/macro/src/storage/mod.rs | 33 ++++ .../src => ink/macro/src/storage}/storable.rs | 0 .../macro/src/storage}/storable_hint.rs | 4 +- .../macro/src/storage}/storage_key.rs | 4 +- .../macro/src/storage}/storage_layout.rs | 0 .../macro/src/storage}/tests/mod.rs | 0 .../macro/src/storage}/tests/storable.rs | 0 .../macro/src/storage}/tests/storable_hint.rs | 0 .../macro/src/storage}/tests/storage_key.rs | 0 .../src/storage}/tests/storage_layout.rs | 0 crates/storage/traits/Cargo.toml | 1 - crates/storage/traits/codegen/Cargo.toml | 19 --- crates/storage/traits/codegen/LICENSE | 1 - crates/storage/traits/codegen/README.md | 1 - crates/storage/traits/codegen/src/lib.rs | 82 ---------- crates/storage/traits/derive/Cargo.toml | 31 ---- crates/storage/traits/derive/LICENSE | 1 - crates/storage/traits/derive/README.md | 1 - crates/storage/traits/derive/src/lib.rs | 147 ------------------ crates/storage/traits/src/lib.rs | 6 - 27 files changed, 206 insertions(+), 300 deletions(-) create mode 100644 crates/ink/macro/src/storage/mod.rs rename crates/{storage/traits/derive/src => ink/macro/src/storage}/storable.rs (100%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/storable_hint.rs (96%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/storage_key.rs (91%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/storage_layout.rs (100%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/tests/mod.rs (100%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/tests/storable.rs (100%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/tests/storable_hint.rs (100%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/tests/storage_key.rs (100%) rename crates/{storage/traits/derive/src => ink/macro/src/storage}/tests/storage_layout.rs (100%) delete mode 100644 crates/storage/traits/codegen/Cargo.toml delete mode 120000 crates/storage/traits/codegen/LICENSE delete mode 120000 crates/storage/traits/codegen/README.md delete mode 100644 crates/storage/traits/codegen/src/lib.rs delete mode 100644 crates/storage/traits/derive/Cargo.toml delete mode 120000 crates/storage/traits/derive/LICENSE delete mode 120000 crates/storage/traits/derive/README.md delete mode 100644 crates/storage/traits/derive/src/lib.rs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7250ced468..b39c651152 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ variables: # read more https://github.com/paritytech/scripts/pull/244 CI_IMAGE: "paritytech/ink-ci-linux:production" PURELY_STD_CRATES: "ink/codegen storage/traits/codegen metadata engine" - ALSO_WASM_CRATES: "env storage storage/traits storage/traits/derive allocator prelude primitives ink ink/macro ink/ir" + ALSO_WASM_CRATES: "env storage storage/traits allocator prelude primitives ink ink/macro ink/ir" ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}" DELEGATOR_SUBCONTRACTS: "accumulator adder subber" UPGRADEABLE_CONTRACTS: "forward-calls set-code-hash" diff --git a/Cargo.toml b/Cargo.toml index 06d044546d..c15cc56cd6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ members = [ "crates/env", "crates/storage", "crates/storage/traits", - "crates/storage/traits/derive", ] exclude = [ "examples/", diff --git a/crates/ink/ir/Cargo.toml b/crates/ink/ir/Cargo.toml index 5169746408..4dc691cb99 100644 --- a/crates/ink/ir/Cargo.toml +++ b/crates/ink/ir/Cargo.toml @@ -18,7 +18,6 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] name = "ink_ir" [dependencies] -ink_storage_codegen = { version = "4.0.0-alpha.1", path = "../../storage/traits/codegen" } quote = "1" syn = { version = "1.0", features = ["parsing", "full", "visit", "extra-traits"] } proc-macro2 = "1.0" diff --git a/crates/ink/ir/src/ir/storage_item/mod.rs b/crates/ink/ir/src/ir/storage_item/mod.rs index d651b06a7d..1ad4b43358 100644 --- a/crates/ink/ir/src/ir/storage_item/mod.rs +++ b/crates/ink/ir/src/ir/storage_item/mod.rs @@ -14,13 +14,14 @@ mod config; +use crate::utils::find_storage_key_salt; use config::StorageItemConfig; -use ink_storage_codegen::DeriveUtils; use proc_macro2::TokenStream as TokenStream2; use quote::{ quote, ToTokens, }; +use std::collections::HashSet; /// A checked ink! storage item with its configuration. pub struct StorageItem { @@ -59,7 +60,34 @@ impl StorageItem { /// Returns all types that were used in the storage declaration. pub fn all_used_types(&self) -> Vec { - self.ast.all_types() + let res: Vec<_> = match self.data().clone() { + syn::Data::Struct(st) => st.fields.iter().map(|field| field.ty.clone()).collect(), + syn::Data::Enum(en) => { + en.variants + .iter() + .flat_map(|variant| variant.fields.iter()) + .map(|field| field.ty.clone()) + .collect() + } + syn::Data::Union(un) => { + un.fields + .named + .iter() + .map(|field| field.ty.clone()) + .collect() + } + }; + let mut set = HashSet::new(); + res.into_iter() + .filter(|ty| { + if !set.contains(ty) { + set.insert(ty.clone()); + true + } else { + false + } + }) + .collect() } /// Returns the config of the storage. @@ -94,7 +122,7 @@ impl StorageItem { /// Returns salt for storage key. pub fn salt(&self) -> TokenStream2 { - if let Some(param) = self.ast.find_salt() { + if let Some(param) = find_storage_key_salt(&self.ast) { param.ident.to_token_stream() } else { quote! { () } diff --git a/crates/ink/ir/src/ir/utils.rs b/crates/ink/ir/src/ir/utils.rs index 8acdb9f4b4..e0ea698e24 100644 --- a/crates/ink/ir/src/ir/utils.rs +++ b/crates/ink/ir/src/ir/utils.rs @@ -144,3 +144,24 @@ where name )) } + +/// Finds the salt of a struct, enum or union. +/// The salt is any generic that has bound `StorageKey`. +/// In most cases it is parent storage key or auto-generated storage key. +pub fn find_storage_key_salt(input: &syn::DeriveInput) -> Option { + input.generics.params.iter().find_map(|param| { + if let syn::GenericParam::Type(type_param) = param { + if let Some(syn::TypeParamBound::Trait(trait_bound)) = + type_param.bounds.first() + { + let segments = &trait_bound.path.segments; + if let Some(last) = segments.last() { + if last.ident == "StorageKey" { + return Some(type_param.clone()) + } + } + } + } + None + }) +} diff --git a/crates/ink/macro/Cargo.toml b/crates/ink/macro/Cargo.toml index 760e99b05b..45c693ae11 100644 --- a/crates/ink/macro/Cargo.toml +++ b/crates/ink/macro/Cargo.toml @@ -21,7 +21,9 @@ ink_primitives = { version = "4.0.0-alpha.1", path = "../../primitives/", defaul scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } syn = "1" +synstructure = "0.12.6" proc-macro2 = "1" +quote = "1" [dev-dependencies] ink_env = { path = "../../env" } diff --git a/crates/ink/macro/src/lib.rs b/crates/ink/macro/src/lib.rs index 16c4e21e2b..1551724831 100644 --- a/crates/ink/macro/src/lib.rs +++ b/crates/ink/macro/src/lib.rs @@ -19,6 +19,7 @@ mod chain_extension; mod contract; mod ink_test; mod selector; +mod storage; mod storage_item; mod trait_def; @@ -1261,5 +1262,118 @@ pub fn chain_extension(attr: TokenStream, item: TokenStream) -> TokenStream { chain_extension::generate(attr.into(), item.into()).into() } +synstructure::decl_derive!( + [Storable] => + /// Derives `ink_storage`'s `Storable` trait for the given `struct`, `enum` or `union`. + /// + /// # Examples + /// + /// ``` + /// use ink_storage::traits::Storable; + /// + /// #[derive(Storable)] + /// struct NamedFields { + /// a: u32, + /// b: [u32; 1], + /// } + /// + /// let value = ::decode(&mut &[123, 123][..]); + /// ``` + storage::storable_derive +); +synstructure::decl_derive!( + [StorableHint] => + /// Derives `ink_storage`'s `StorableHint` trait for the given `struct` or `enum`. + /// + /// If the type declaration contains generic `StorageKey`, + /// it will use it as salt to generate a combined storage key. + /// + /// # Examples + /// + /// ``` + /// use ink_storage::traits::{ + /// StorableHint, + /// StorageKey, + /// AutoStorableHint, + /// AutoKey, + /// ManualKey, + /// }; + /// use ink_storage::traits::Storable; + /// + /// #[derive(Default, StorableHint, Storable)] + /// struct NamedFields { + /// a: u32, + /// b: [u32; 32], + /// } + /// + /// let _: NamedFields = >::Type::default(); + /// let _: NamedFields = >>::Type::default(); + /// ``` + storage::storable_hint_derive +); +synstructure::decl_derive!( + [StorageKey] => + /// Derives `ink_storage`'s `StorageKey` trait for the given `struct` or `enum`. + /// + /// # Examples + /// + /// ``` + /// use ink_storage::traits::{ + /// AutoStorableHint, + /// StorageKey, + /// ManualKey, + /// AutoKey, + /// }; + /// + /// #[derive(StorageKey)] + /// struct NamedFields { + /// a: u32, + /// b: [u32; 32], + /// } + /// + /// assert_eq!(::KEY, 0); + /// + /// #[derive(StorageKey)] + /// struct NamedFieldsManualKey { + /// a: >>::Type, + /// b: <[u32; 32] as AutoStorableHint>>::Type, + /// } + /// + /// assert_eq!( as StorageKey>::KEY, 0); + /// assert_eq!( as StorageKey>::KEY, 0); + /// assert_eq!(> as StorageKey>::KEY, 123); + /// ``` + storage::storage_key_derive +); +synstructure::decl_derive!( + [StorageLayout] => + /// Derives `ink_storage`'s `StorageLayout` trait for the given `struct` or `enum`. + /// + /// # Examples + /// + /// ``` + /// use ink_metadata::layout::Layout::Struct; + /// use ink_storage::traits::StorageLayout; + /// + /// #[derive(StorageLayout)] + /// struct NamedFields { + /// a: u32, + /// b: [u32; 32], + /// } + /// + /// let key = 0x123; + /// let mut value = NamedFields { + /// a: 123, + /// b: [22; 32], + /// }; + /// + /// if let Struct(layout) = ::layout(&key) { + /// assert_eq!(*layout.fields()[0].name(), "a"); + /// assert_eq!(*layout.fields()[1].name(), "b"); + /// } + /// ``` + storage::storage_layout_derive +); + #[cfg(test)] pub use contract::generate_or_err; diff --git a/crates/ink/macro/src/storage/mod.rs b/crates/ink/macro/src/storage/mod.rs new file mode 100644 index 0000000000..c46e882640 --- /dev/null +++ b/crates/ink/macro/src/storage/mod.rs @@ -0,0 +1,33 @@ +// Copyright 2018-2022 Parity Technologies (UK) Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// 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. + +//! Custom derive for `ink_storage` traits. +//! +//! This crate provides helpers to define your very own custom storage data +//! structures that work along the `ink_storage` data structures. + +mod storable; +mod storable_hint; +mod storage_key; +mod storage_layout; + +pub use self::{ + storable::storable_derive, + storable_hint::storable_hint_derive, + storage_key::storage_key_derive, + storage_layout::storage_layout_derive, +}; + +#[cfg(test)] +mod tests; diff --git a/crates/storage/traits/derive/src/storable.rs b/crates/ink/macro/src/storage/storable.rs similarity index 100% rename from crates/storage/traits/derive/src/storable.rs rename to crates/ink/macro/src/storage/storable.rs diff --git a/crates/storage/traits/derive/src/storable_hint.rs b/crates/ink/macro/src/storage/storable_hint.rs similarity index 96% rename from crates/storage/traits/derive/src/storable_hint.rs rename to crates/ink/macro/src/storage/storable_hint.rs index 084360fcf6..32515e735e 100644 --- a/crates/storage/traits/derive/src/storable_hint.rs +++ b/crates/ink/macro/src/storage/storable_hint.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use ink_storage_codegen::DeriveUtils; +use ink_ir::utils::find_storage_key_salt; use proc_macro2::TokenStream as TokenStream2; use quote::{ format_ident, @@ -36,7 +36,7 @@ fn storable_hint_inner(s: synstructure::Structure) -> TokenStream2 { let (impl_generics, _, where_clause) = generics.split_for_impl(); let (_, ty_generics_original, _) = s.ast().generics.split_for_impl(); - if let Some(inner_salt_ident) = s.ast().find_salt() { + if let Some(inner_salt_ident) = find_storage_key_salt(s.ast()) { let inner_salt_ident = inner_salt_ident.ident.to_token_stream(); let ty_generics: Vec<_> = s .ast() diff --git a/crates/storage/traits/derive/src/storage_key.rs b/crates/ink/macro/src/storage/storage_key.rs similarity index 91% rename from crates/storage/traits/derive/src/storage_key.rs rename to crates/ink/macro/src/storage/storage_key.rs index 25991ba562..a2dbfa7dce 100644 --- a/crates/storage/traits/derive/src/storage_key.rs +++ b/crates/ink/macro/src/storage/storage_key.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use ink_storage_codegen::DeriveUtils; +use ink_ir::utils::find_storage_key_salt; use proc_macro2::TokenStream as TokenStream2; use quote::{ quote, @@ -23,7 +23,7 @@ pub fn storage_key_derive(mut s: synstructure::Structure) -> TokenStream2 { s.add_bounds(synstructure::AddBounds::None) .underscore_const(true); - let salt = if let Some(param) = s.ast().find_salt() { + let salt = if let Some(param) = find_storage_key_salt(s.ast()) { param.ident.to_token_stream() } else { quote! { () } diff --git a/crates/storage/traits/derive/src/storage_layout.rs b/crates/ink/macro/src/storage/storage_layout.rs similarity index 100% rename from crates/storage/traits/derive/src/storage_layout.rs rename to crates/ink/macro/src/storage/storage_layout.rs diff --git a/crates/storage/traits/derive/src/tests/mod.rs b/crates/ink/macro/src/storage/tests/mod.rs similarity index 100% rename from crates/storage/traits/derive/src/tests/mod.rs rename to crates/ink/macro/src/storage/tests/mod.rs diff --git a/crates/storage/traits/derive/src/tests/storable.rs b/crates/ink/macro/src/storage/tests/storable.rs similarity index 100% rename from crates/storage/traits/derive/src/tests/storable.rs rename to crates/ink/macro/src/storage/tests/storable.rs diff --git a/crates/storage/traits/derive/src/tests/storable_hint.rs b/crates/ink/macro/src/storage/tests/storable_hint.rs similarity index 100% rename from crates/storage/traits/derive/src/tests/storable_hint.rs rename to crates/ink/macro/src/storage/tests/storable_hint.rs diff --git a/crates/storage/traits/derive/src/tests/storage_key.rs b/crates/ink/macro/src/storage/tests/storage_key.rs similarity index 100% rename from crates/storage/traits/derive/src/tests/storage_key.rs rename to crates/ink/macro/src/storage/tests/storage_key.rs diff --git a/crates/storage/traits/derive/src/tests/storage_layout.rs b/crates/ink/macro/src/storage/tests/storage_layout.rs similarity index 100% rename from crates/storage/traits/derive/src/tests/storage_layout.rs rename to crates/ink/macro/src/storage/tests/storage_layout.rs diff --git a/crates/storage/traits/Cargo.toml b/crates/storage/traits/Cargo.toml index 742ad73897..ba75e39def 100644 --- a/crates/storage/traits/Cargo.toml +++ b/crates/storage/traits/Cargo.toml @@ -18,7 +18,6 @@ include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] ink_metadata = { version = "4.0.0-alpha.1", path = "../../metadata", default-features = false, features = ["derive"], optional = true } ink_primitives = { version = "4.0.0-alpha.1", path = "../../primitives", default-features = false } ink_prelude = { version = "4.0.0-alpha.1", path = "../../prelude", default-features = false } -ink_storage_derive = { version = "4.0.0-alpha.1", path = "derive", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] } scale-info = { version = "2", default-features = false, features = ["derive"], optional = true } syn = { version = "1", features = ["full"] } diff --git a/crates/storage/traits/codegen/Cargo.toml b/crates/storage/traits/codegen/Cargo.toml deleted file mode 100644 index 51cdb919a4..0000000000 --- a/crates/storage/traits/codegen/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "ink_storage_codegen" -version = "4.0.0-alpha.1" -authors = ["Parity Technologies "] -edition = "2021" - -license = "Apache-2.0" -readme = "../README.md" -repository = "https://github.com/paritytech/ink" -documentation = "https://docs.rs/ink_storage_derive" -homepage = "https://www.parity.io/" -description = "[ink!] Utils codegen crate related to ink_storage." -keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"] -categories = ["no-std", "embedded"] -include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] - -[dependencies] -ink_primitives = { version = "4.0.0-alpha.1", path = "../../../primitives", default-features = false } -syn = { version = "1", features = ["full", "extra-traits"] } \ No newline at end of file diff --git a/crates/storage/traits/codegen/LICENSE b/crates/storage/traits/codegen/LICENSE deleted file mode 120000 index 1477615432..0000000000 --- a/crates/storage/traits/codegen/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../../../../LICENSE \ No newline at end of file diff --git a/crates/storage/traits/codegen/README.md b/crates/storage/traits/codegen/README.md deleted file mode 120000 index ff5c79602c..0000000000 --- a/crates/storage/traits/codegen/README.md +++ /dev/null @@ -1 +0,0 @@ -../../../../README.md \ No newline at end of file diff --git a/crates/storage/traits/codegen/src/lib.rs b/crates/storage/traits/codegen/src/lib.rs deleted file mode 100644 index 65de0226a0..0000000000 --- a/crates/storage/traits/codegen/src/lib.rs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2018-2022 Parity Technologies (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// 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. - -use std::collections::HashSet; -use syn::Data; - -/// Provides common methods for `DeriveInput`. -/// -/// # Developer Note -/// -/// This is only for internal usage in the `codegen` module. -pub trait DeriveUtils { - /// Finds the salt of the structure, enum or union. - /// The salt is any generic that has bound `StorageKey`. - /// In most cases it is parent storage key or auto-generated storage key. - fn find_salt(&self) -> Option; - - /// Return all types of the input. - fn all_types(&self) -> Vec; -} - -impl DeriveUtils for syn::DeriveInput { - fn find_salt(&self) -> Option { - self.generics.params.iter().find_map(|param| { - if let syn::GenericParam::Type(type_param) = param { - if let Some(syn::TypeParamBound::Trait(trait_bound)) = - type_param.bounds.first() - { - let segments = &trait_bound.path.segments; - if let Some(last) = segments.last() { - if last.ident == "StorageKey" { - return Some(type_param.clone()) - } - } - } - } - None - }) - } - - fn all_types(&self) -> Vec { - let res: Vec<_> = match self.data.clone() { - Data::Struct(st) => st.fields.iter().map(|field| field.ty.clone()).collect(), - Data::Enum(en) => { - en.variants - .iter() - .flat_map(|variant| variant.fields.iter()) - .map(|field| field.ty.clone()) - .collect() - } - Data::Union(un) => { - un.fields - .named - .iter() - .map(|field| field.ty.clone()) - .collect() - } - }; - let mut set = HashSet::new(); - res.into_iter() - .filter(|ty| { - if !set.contains(ty) { - set.insert(ty.clone()); - true - } else { - false - } - }) - .collect() - } -} diff --git a/crates/storage/traits/derive/Cargo.toml b/crates/storage/traits/derive/Cargo.toml deleted file mode 100644 index 0a9e039795..0000000000 --- a/crates/storage/traits/derive/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -name = "ink_storage_derive" -version = "4.0.0-alpha.1" -authors = ["Parity Technologies ", "Robin Freyler "] -edition = "2021" - -license = "Apache-2.0" -readme = "../README.md" -repository = "https://github.com/paritytech/ink" -documentation = "https://docs.rs/ink_storage_derive" -homepage = "https://www.parity.io/" -description = "[ink!] Derive macros for common ink_storage defined traits." -keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"] -categories = ["no-std", "embedded"] -include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] - -[lib] -proc-macro = true - -[dependencies] -quote = "1" -syn = { version = "1", features = ["full"] } -proc-macro2 = "1" -synstructure = "0.12.4" -ink_storage_codegen = { version = "4.0.0-alpha.1", path = "../codegen" } - -[dev-dependencies] -ink = { path = "../../../ink" } -ink_metadata = { path = "../../../metadata" } -ink_storage = { path = "../.." } -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] } diff --git a/crates/storage/traits/derive/LICENSE b/crates/storage/traits/derive/LICENSE deleted file mode 120000 index 1477615432..0000000000 --- a/crates/storage/traits/derive/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../../../../LICENSE \ No newline at end of file diff --git a/crates/storage/traits/derive/README.md b/crates/storage/traits/derive/README.md deleted file mode 120000 index ff5c79602c..0000000000 --- a/crates/storage/traits/derive/README.md +++ /dev/null @@ -1 +0,0 @@ -../../../../README.md \ No newline at end of file diff --git a/crates/storage/traits/derive/src/lib.rs b/crates/storage/traits/derive/src/lib.rs deleted file mode 100644 index e4fea22c29..0000000000 --- a/crates/storage/traits/derive/src/lib.rs +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2018-2022 Parity Technologies (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// 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. - -//! Custom derive for `ink_storage` traits. -//! -//! This crate provides helpers to define your very own custom storage data -//! structures that work along the `ink_storage` data structures. - -extern crate proc_macro; - -mod storable; -mod storable_hint; -mod storage_key; -mod storage_layout; - -#[cfg(test)] -mod tests; - -use self::{ - storable::storable_derive, - storable_hint::storable_hint_derive, - storage_key::storage_key_derive, - storage_layout::storage_layout_derive, -}; -synstructure::decl_derive!( - [Storable] => - /// Derives `ink_storage`'s `Storable` trait for the given `struct`, `enum` or `union`. - /// - /// # Examples - /// - /// ``` - /// use ink_storage::traits::Storable; - /// - /// #[derive(Storable)] - /// struct NamedFields { - /// a: u32, - /// b: [u32; 1], - /// } - /// - /// let value = ::decode(&mut &[123, 123][..]); - /// ``` - storable_derive -); -synstructure::decl_derive!( - [StorableHint] => - /// Derives `ink_storage`'s `StorableHint` trait for the given `struct` or `enum`. - /// - /// If the type declaration contains generic `StorageKey`, - /// it will use it as salt to generate a combined storage key. - /// - /// # Examples - /// - /// ``` - /// use ink_storage::traits::{ - /// StorableHint, - /// StorageKey, - /// AutoStorableHint, - /// AutoKey, - /// ManualKey, - /// }; - /// use ink_storage::traits::Storable; - /// - /// #[derive(Default, StorableHint, Storable)] - /// struct NamedFields { - /// a: u32, - /// b: [u32; 32], - /// } - /// - /// let _: NamedFields = >::Type::default(); - /// let _: NamedFields = >>::Type::default(); - /// ``` - storable_hint_derive -); -synstructure::decl_derive!( - [StorageKey] => - /// Derives `ink_storage`'s `StorageKey` trait for the given `struct` or `enum`. - /// - /// # Examples - /// - /// ``` - /// use ink_storage::traits::{ - /// AutoStorableHint, - /// StorageKey, - /// ManualKey, - /// AutoKey, - /// }; - /// - /// #[derive(StorageKey)] - /// struct NamedFields { - /// a: u32, - /// b: [u32; 32], - /// } - /// - /// assert_eq!(::KEY, 0); - /// - /// #[derive(StorageKey)] - /// struct NamedFieldsManualKey { - /// a: >>::Type, - /// b: <[u32; 32] as AutoStorableHint>>::Type, - /// } - /// - /// assert_eq!( as StorageKey>::KEY, 0); - /// assert_eq!( as StorageKey>::KEY, 0); - /// assert_eq!(> as StorageKey>::KEY, 123); - /// ``` - storage_key_derive -); -synstructure::decl_derive!( - [StorageLayout] => - /// Derives `ink_storage`'s `StorageLayout` trait for the given `struct` or `enum`. - /// - /// # Examples - /// - /// ``` - /// use ink_metadata::layout::Layout::Struct; - /// use ink_storage::traits::StorageLayout; - /// - /// #[derive(StorageLayout)] - /// struct NamedFields { - /// a: u32, - /// b: [u32; 32], - /// } - /// - /// let key = 0x123; - /// let mut value = NamedFields { - /// a: 123, - /// b: [22; 32], - /// }; - /// - /// if let Struct(layout) = ::layout(&key) { - /// assert_eq!(*layout.fields()[0].name(), "a"); - /// assert_eq!(*layout.fields()[1].name(), "b"); - /// } - /// ``` - storage_layout_derive -); diff --git a/crates/storage/traits/src/lib.rs b/crates/storage/traits/src/lib.rs index 5be16919b3..8013a6ff2a 100644 --- a/crates/storage/traits/src/lib.rs +++ b/crates/storage/traits/src/lib.rs @@ -49,9 +49,3 @@ pub use self::{ StorageKey, }, }; -pub use ink_storage_derive::{ - Storable, - StorableHint, - StorageKey, - StorageLayout, -}; From 689265ccec1170436ae83fdc82ab7ff3d5f15504 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 13:47:29 +0100 Subject: [PATCH 02/13] Reexport storage traits and derives from ink crate --- crates/ink/src/lib.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/ink/src/lib.rs b/crates/ink/src/lib.rs index 78af6d57fe..0bef33a91b 100644 --- a/crates/ink/src/lib.rs +++ b/crates/ink/src/lib.rs @@ -32,7 +32,22 @@ pub use ink_env as env; pub use ink_metadata as metadata; pub use ink_prelude as prelude; pub use ink_primitives as primitives; -pub use ink_storage as storage; + +pub mod storage { + pub mod traits { + pub use ink_storage::traits::*; + pub use ink_macro::{ + Storable, + StorableHint, + StorageKey, + StorageLayout, + }; + } + pub use ink_storage::{ + Lazy, + Mapping, + }; +} pub use self::{ chain_extension::{ From 6bf11a57c467630ff9761ff97778d8b494241006 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 13:56:53 +0100 Subject: [PATCH 03/13] Fix macro storage tests --- crates/ink/macro/src/lib.rs | 48 +++++++++---------- crates/ink/macro/src/storage/tests/mod.rs | 7 +++ .../ink/macro/src/storage/tests/storable.rs | 2 +- .../macro/src/storage/tests/storable_hint.rs | 2 +- .../macro/src/storage/tests/storage_key.rs | 2 +- .../macro/src/storage/tests/storage_layout.rs | 2 +- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/crates/ink/macro/src/lib.rs b/crates/ink/macro/src/lib.rs index 1551724831..3794d76111 100644 --- a/crates/ink/macro/src/lib.rs +++ b/crates/ink/macro/src/lib.rs @@ -214,7 +214,7 @@ pub fn selector_bytes(input: TokenStream) -> TokenStream { /// The user is able to use a variety of built-in facilities, combine them in various ways /// or even provide their own implementations of storage data structures. /// -/// For more information visit the `ink_storage` crate documentation. +/// For more information visit the `ink::storage` crate documentation. /// /// **Example:** /// @@ -675,22 +675,22 @@ pub fn trait_definition(attr: TokenStream, item: TokenStream) -> TokenStream { /// /// ``` /// use ink_prelude::vec::Vec; -/// use ink_storage::{ +/// use ink::storage::{ /// Lazy, /// Mapping, /// }; -/// use ink_storage::traits::{ +/// use ink::storage::traits::{ /// StorageKey, /// StorableHint, /// }; -/// use ink_storage::traits::Storable; +/// use ink::storage::traits::Storable; /// /// // Deriving `scale::Decode` and `scale::Encode` also derives blanket implementation of all /// // required traits to be storable. /// #[derive(scale::Decode, scale::Encode)] /// #[cfg_attr( /// feature = "std", -/// derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) +/// derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) /// )] /// struct Packed { /// s1: u128, @@ -703,9 +703,9 @@ pub fn trait_definition(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[derive(scale::Decode, scale::Encode)] /// #[cfg_attr( /// feature = "std", -/// derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) +/// derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) /// )] -/// struct PackedGeneric { +/// struct PackedGeneric { /// s1: (u128, bool), /// s2: Vec, /// s3: String, @@ -723,9 +723,9 @@ pub fn trait_definition(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[derive(Storable, StorableHint, StorageKey)] /// #[cfg_attr( /// feature = "std", -/// derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) +/// derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) /// )] -/// struct NonPackedGeneric { +/// struct NonPackedGeneric { /// s1: u32, /// s2: T, /// s3: Mapping, @@ -735,7 +735,7 @@ pub fn trait_definition(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[derive(scale::Decode, scale::Encode)] /// #[cfg_attr( /// feature = "std", -/// derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) +/// derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) /// )] /// struct PackedComplex { /// s1: u128, @@ -753,7 +753,7 @@ pub fn trait_definition(attr: TokenStream, item: TokenStream) -> TokenStream { /// s5: Lazy, /// s6: PackedGeneric, /// s7: NonPackedGeneric, -/// // Fails because: the trait `ink_storage::traits::Packed` is not implemented for `NonPacked` +/// // Fails because: the trait `ink::storage::traits::Packed` is not implemented for `NonPacked` /// // s8: Mapping, /// } /// ``` @@ -770,16 +770,16 @@ pub fn trait_definition(attr: TokenStream, item: TokenStream) -> TokenStream { /// /// **Usage Example:** /// ``` -/// use ink_storage::Mapping; -/// use ink_storage::traits::{ +/// use ink::storage::Mapping; +/// use ink::storage::traits::{ /// StorableHint, /// StorageKey, /// }; -/// use ink_storage::traits::Storable; +/// use ink::storage::traits::Storable; /// /// #[ink::storage_item(derive = false)] /// #[derive(StorableHint, Storable, StorageKey)] -/// struct NonPackedGeneric { +/// struct NonPackedGeneric { /// s1: u32, /// s2: Mapping, /// } @@ -1264,12 +1264,12 @@ pub fn chain_extension(attr: TokenStream, item: TokenStream) -> TokenStream { synstructure::decl_derive!( [Storable] => - /// Derives `ink_storage`'s `Storable` trait for the given `struct`, `enum` or `union`. + /// Derives `ink::storage`'s `Storable` trait for the given `struct`, `enum` or `union`. /// /// # Examples /// /// ``` - /// use ink_storage::traits::Storable; + /// use ink::storage::traits::Storable; /// /// #[derive(Storable)] /// struct NamedFields { @@ -1283,7 +1283,7 @@ synstructure::decl_derive!( ); synstructure::decl_derive!( [StorableHint] => - /// Derives `ink_storage`'s `StorableHint` trait for the given `struct` or `enum`. + /// Derives `ink::storage`'s `StorableHint` trait for the given `struct` or `enum`. /// /// If the type declaration contains generic `StorageKey`, /// it will use it as salt to generate a combined storage key. @@ -1291,14 +1291,14 @@ synstructure::decl_derive!( /// # Examples /// /// ``` - /// use ink_storage::traits::{ + /// use ink::storage::traits::{ + /// Storable, /// StorableHint, /// StorageKey, /// AutoStorableHint, /// AutoKey, /// ManualKey, /// }; - /// use ink_storage::traits::Storable; /// /// #[derive(Default, StorableHint, Storable)] /// struct NamedFields { @@ -1313,12 +1313,12 @@ synstructure::decl_derive!( ); synstructure::decl_derive!( [StorageKey] => - /// Derives `ink_storage`'s `StorageKey` trait for the given `struct` or `enum`. + /// Derives `ink::storage`'s `StorageKey` trait for the given `struct` or `enum`. /// /// # Examples /// /// ``` - /// use ink_storage::traits::{ + /// use ink::storage::traits::{ /// AutoStorableHint, /// StorageKey, /// ManualKey, @@ -1347,13 +1347,13 @@ synstructure::decl_derive!( ); synstructure::decl_derive!( [StorageLayout] => - /// Derives `ink_storage`'s `StorageLayout` trait for the given `struct` or `enum`. + /// Derives `ink::storage`'s `StorageLayout` trait for the given `struct` or `enum`. /// /// # Examples /// /// ``` /// use ink_metadata::layout::Layout::Struct; - /// use ink_storage::traits::StorageLayout; + /// use ink::storage::traits::StorageLayout; /// /// #[derive(StorageLayout)] /// struct NamedFields { diff --git a/crates/ink/macro/src/storage/tests/mod.rs b/crates/ink/macro/src/storage/tests/mod.rs index 1c3e0143ea..8a0bbfbe70 100644 --- a/crates/ink/macro/src/storage/tests/mod.rs +++ b/crates/ink/macro/src/storage/tests/mod.rs @@ -17,6 +17,13 @@ mod storable_hint; mod storage_key; mod storage_layout; +use crate::storage::{ + storable::storable_derive, + storable_hint::storable_hint_derive, + storage_key::storage_key_derive, + storage_layout::storage_layout_derive, +}; + #[macro_export] macro_rules! test_derive { ($name:path { $($i:tt)* } expands to { $($o:tt)* }) => { diff --git a/crates/ink/macro/src/storage/tests/storable.rs b/crates/ink/macro/src/storage/tests/storable.rs index b59c1681fa..46f17a914e 100644 --- a/crates/ink/macro/src/storage/tests/storable.rs +++ b/crates/ink/macro/src/storage/tests/storable.rs @@ -20,7 +20,7 @@ #![allow(clippy::eq_op)] #![allow(clippy::match_single_binding)] -use crate::storable_derive; +use super::storable_derive; #[test] fn unit_struct_works() { diff --git a/crates/ink/macro/src/storage/tests/storable_hint.rs b/crates/ink/macro/src/storage/tests/storable_hint.rs index 91b5ca38cf..2bb50c5c91 100644 --- a/crates/ink/macro/src/storage/tests/storable_hint.rs +++ b/crates/ink/macro/src/storage/tests/storable_hint.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::storable_hint_derive; +use super::storable_hint_derive; #[test] fn unit_struct_works() { diff --git a/crates/ink/macro/src/storage/tests/storage_key.rs b/crates/ink/macro/src/storage/tests/storage_key.rs index d4de9f9c40..3541d12330 100644 --- a/crates/ink/macro/src/storage/tests/storage_key.rs +++ b/crates/ink/macro/src/storage/tests/storage_key.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::storage_key_derive; +use super::storage_key_derive; #[test] fn unit_struct_works() { diff --git a/crates/ink/macro/src/storage/tests/storage_layout.rs b/crates/ink/macro/src/storage/tests/storage_layout.rs index 198d5865f0..c3b072435b 100644 --- a/crates/ink/macro/src/storage/tests/storage_layout.rs +++ b/crates/ink/macro/src/storage/tests/storage_layout.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::storage_layout_derive; +use super::storage_layout_derive; #[test] fn unit_struct_works() { From e7e2a7d42cfffaf14b6b7721bc0cf5ac34cf5482 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 14:13:58 +0100 Subject: [PATCH 04/13] Fmt --- crates/ink/ir/src/ir/storage_item/mod.rs | 4 +++- crates/ink/ir/src/ir/utils.rs | 2 +- crates/ink/src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ink/ir/src/ir/storage_item/mod.rs b/crates/ink/ir/src/ir/storage_item/mod.rs index 1ad4b43358..bcf18dfde9 100644 --- a/crates/ink/ir/src/ir/storage_item/mod.rs +++ b/crates/ink/ir/src/ir/storage_item/mod.rs @@ -61,7 +61,9 @@ impl StorageItem { /// Returns all types that were used in the storage declaration. pub fn all_used_types(&self) -> Vec { let res: Vec<_> = match self.data().clone() { - syn::Data::Struct(st) => st.fields.iter().map(|field| field.ty.clone()).collect(), + syn::Data::Struct(st) => { + st.fields.iter().map(|field| field.ty.clone()).collect() + } syn::Data::Enum(en) => { en.variants .iter() diff --git a/crates/ink/ir/src/ir/utils.rs b/crates/ink/ir/src/ir/utils.rs index e0ea698e24..987162d8f5 100644 --- a/crates/ink/ir/src/ir/utils.rs +++ b/crates/ink/ir/src/ir/utils.rs @@ -152,7 +152,7 @@ pub fn find_storage_key_salt(input: &syn::DeriveInput) -> Option input.generics.params.iter().find_map(|param| { if let syn::GenericParam::Type(type_param) = param { if let Some(syn::TypeParamBound::Trait(trait_bound)) = - type_param.bounds.first() + type_param.bounds.first() { let segments = &trait_bound.path.segments; if let Some(last) = segments.last() { diff --git a/crates/ink/src/lib.rs b/crates/ink/src/lib.rs index 0bef33a91b..ab9ded0528 100644 --- a/crates/ink/src/lib.rs +++ b/crates/ink/src/lib.rs @@ -35,13 +35,13 @@ pub use ink_primitives as primitives; pub mod storage { pub mod traits { - pub use ink_storage::traits::*; pub use ink_macro::{ Storable, StorableHint, StorageKey, StorageLayout, }; + pub use ink_storage::traits::*; } pub use ink_storage::{ Lazy, From 0ac79cee874d0b8ef7bc6c4554b2a32a49e299ef Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:04:10 +0100 Subject: [PATCH 05/13] Remove storage/traits/codegen crate --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b39c651152..c0de6864f7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,7 +29,7 @@ variables: # CI_IMAGE is changed to "-:staging" when the CI image gets rebuilt # read more https://github.com/paritytech/scripts/pull/244 CI_IMAGE: "paritytech/ink-ci-linux:production" - PURELY_STD_CRATES: "ink/codegen storage/traits/codegen metadata engine" + PURELY_STD_CRATES: "ink/codegen metadata engine" ALSO_WASM_CRATES: "env storage storage/traits allocator prelude primitives ink ink/macro ink/ir" ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}" DELEGATOR_SUBCONTRACTS: "accumulator adder subber" From 30ba34eb442f5e4c68daa5cedbafb9fbdf03c3a8 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:07:29 +0100 Subject: [PATCH 06/13] Fix ui test --- crates/ink/tests/ui/contract/pass/storage-packed-fields.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ink/tests/ui/contract/pass/storage-packed-fields.rs b/crates/ink/tests/ui/contract/pass/storage-packed-fields.rs index 1149c7b5de..ebe8b7536b 100644 --- a/crates/ink/tests/ui/contract/pass/storage-packed-fields.rs +++ b/crates/ink/tests/ui/contract/pass/storage-packed-fields.rs @@ -1,6 +1,6 @@ #[ink::contract] mod contract { - use ink_storage::traits::StorageLayout; + use ink::storage::traits::StorageLayout; #[ink(storage)] pub struct Contract { From 03e6d2168ae11457335fd78271fe7d8d97910634 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:14:58 +0100 Subject: [PATCH 07/13] Attempt to fix UI tests --- .../tests/ui/storage_item/pass/argument_derive_false.rs | 4 ++-- .../tests/ui/storage_item/pass/complex_non_packed_enum.rs | 2 +- .../ui/storage_item/pass/complex_non_packed_struct.rs | 2 +- .../ink/tests/ui/storage_item/pass/complex_packed_enum.rs | 8 ++++---- .../tests/ui/storage_item/pass/complex_packed_struct.rs | 8 ++++---- .../tests/ui/storage_item/pass/default_storage_key_1.rs | 2 +- .../tests/ui/storage_item/pass/default_storage_key_3.rs | 6 +++--- .../tests/ui/storage_item/pass/default_storage_key_4.rs | 6 +++--- .../ink/tests/ui/storage_item/pass/packed_tuple_struct.rs | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/crates/ink/tests/ui/storage_item/pass/argument_derive_false.rs b/crates/ink/tests/ui/storage_item/pass/argument_derive_false.rs index d491db42ad..6e4e83caa5 100644 --- a/crates/ink/tests/ui/storage_item/pass/argument_derive_false.rs +++ b/crates/ink/tests/ui/storage_item/pass/argument_derive_false.rs @@ -1,5 +1,5 @@ -use ink_storage::traits::Storable; -use ink_storage::traits::{ +use ink::storage::traits::Storable; +use ink::storage::traits::{ ManualKey, StorageKey, }; diff --git a/crates/ink/tests/ui/storage_item/pass/complex_non_packed_enum.rs b/crates/ink/tests/ui/storage_item/pass/complex_non_packed_enum.rs index e65f0e8cc1..f34d0f8fd0 100644 --- a/crates/ink/tests/ui/storage_item/pass/complex_non_packed_enum.rs +++ b/crates/ink/tests/ui/storage_item/pass/complex_non_packed_enum.rs @@ -12,7 +12,7 @@ use ink_storage::{ #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] enum Packed { #[default] diff --git a/crates/ink/tests/ui/storage_item/pass/complex_non_packed_struct.rs b/crates/ink/tests/ui/storage_item/pass/complex_non_packed_struct.rs index 5a4f203da2..0912379506 100644 --- a/crates/ink/tests/ui/storage_item/pass/complex_non_packed_struct.rs +++ b/crates/ink/tests/ui/storage_item/pass/complex_non_packed_struct.rs @@ -12,7 +12,7 @@ use ink_storage::{ #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] struct Packed { a: u8, diff --git a/crates/ink/tests/ui/storage_item/pass/complex_packed_enum.rs b/crates/ink/tests/ui/storage_item/pass/complex_packed_enum.rs index 9ddd1f8e17..8bd302d8cb 100644 --- a/crates/ink/tests/ui/storage_item/pass/complex_packed_enum.rs +++ b/crates/ink/tests/ui/storage_item/pass/complex_packed_enum.rs @@ -5,12 +5,12 @@ use ink_prelude::{ }, vec::Vec, }; -use ink_storage::traits::Storable; +use ink::storage::traits::Storable; #[derive(Default, PartialEq, Eq, PartialOrd, Ord, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] enum Deep2 { #[default] @@ -31,7 +31,7 @@ enum Deep2 { #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] enum Deep1 { #[default] @@ -46,7 +46,7 @@ enum Deep1 { #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] struct Contract { a: Deep1, diff --git a/crates/ink/tests/ui/storage_item/pass/complex_packed_struct.rs b/crates/ink/tests/ui/storage_item/pass/complex_packed_struct.rs index fbaba78312..13e125ba97 100644 --- a/crates/ink/tests/ui/storage_item/pass/complex_packed_struct.rs +++ b/crates/ink/tests/ui/storage_item/pass/complex_packed_struct.rs @@ -5,12 +5,12 @@ use ink_prelude::{ }, vec::Vec, }; -use ink_storage::traits::Storable; +use ink::storage::traits::Storable; #[derive(Default, PartialEq, Eq, PartialOrd, Ord, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] struct Deep2 { a: u8, @@ -24,7 +24,7 @@ struct Deep2 { #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] struct Deep1 { a: Deep2, @@ -37,7 +37,7 @@ struct Deep1 { #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] struct Contract { a: Deep1, diff --git a/crates/ink/tests/ui/storage_item/pass/default_storage_key_1.rs b/crates/ink/tests/ui/storage_item/pass/default_storage_key_1.rs index 28eadb587b..78189bdc3e 100644 --- a/crates/ink/tests/ui/storage_item/pass/default_storage_key_1.rs +++ b/crates/ink/tests/ui/storage_item/pass/default_storage_key_1.rs @@ -1,4 +1,4 @@ -use ink_storage::traits::{ +use ink::storage::traits::{ ManualKey, StorageKey, }; diff --git a/crates/ink/tests/ui/storage_item/pass/default_storage_key_3.rs b/crates/ink/tests/ui/storage_item/pass/default_storage_key_3.rs index db2f47b9de..40839d9957 100644 --- a/crates/ink/tests/ui/storage_item/pass/default_storage_key_3.rs +++ b/crates/ink/tests/ui/storage_item/pass/default_storage_key_3.rs @@ -1,12 +1,12 @@ -use ink_storage::traits::ManualKey; +use ink::storage::traits::ManualKey; #[ink::storage_item] -struct Contract> { +struct Contract> { a: u16, b: u16, c: u16, } fn main() { - assert_eq!(::KEY, 123); + assert_eq!(::KEY, 123); } diff --git a/crates/ink/tests/ui/storage_item/pass/default_storage_key_4.rs b/crates/ink/tests/ui/storage_item/pass/default_storage_key_4.rs index 22a9a3780e..76d1da93de 100644 --- a/crates/ink/tests/ui/storage_item/pass/default_storage_key_4.rs +++ b/crates/ink/tests/ui/storage_item/pass/default_storage_key_4.rs @@ -1,12 +1,12 @@ -use ink_storage::traits::ManualKey; +use ink::storage::traits::ManualKey; #[ink::storage_item] -struct Contract> { +struct Contract> { a: u16, b: u16, c: u16, } fn main() { - assert_eq!(::KEY, 123); + assert_eq!(::KEY, 123); } diff --git a/crates/ink/tests/ui/storage_item/pass/packed_tuple_struct.rs b/crates/ink/tests/ui/storage_item/pass/packed_tuple_struct.rs index 7d265a835f..c70c5904bc 100644 --- a/crates/ink/tests/ui/storage_item/pass/packed_tuple_struct.rs +++ b/crates/ink/tests/ui/storage_item/pass/packed_tuple_struct.rs @@ -1,9 +1,9 @@ -use ink_storage::traits::Storable; +use ink::storage::traits::Storable; #[derive(Default, scale::Encode, scale::Decode)] #[cfg_attr( feature = "std", - derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout) + derive(scale_info::TypeInfo, ink::storage::traits::StorageLayout) )] struct Contract(String, u128); From acd77474afbb57f8c90c3c1375fd34342186d647 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:15:45 +0100 Subject: [PATCH 08/13] Attempt to fix docs job --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c0de6864f7..c970ecee63 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -282,7 +282,7 @@ docs: script: - cargo doc --no-deps --all-features -p scale-info -p ink_metadata -p ink_env - -p ink_storage -p ink_storage_traits -p ink_storage_codegen -p ink_storage_derive + -p ink_storage -p ink_storage_traits -p ink_storage_derive -p ink_primitives -p ink_prelude -p ink -p ink_macro -p ink_ir -p ink_codegen - mv ${CARGO_TARGET_DIR}/doc ./crate-docs From d38c099df840bb52ed630b3f4b34ddc486841855 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:21:56 +0100 Subject: [PATCH 09/13] Try to fox codecov job --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c970ecee63..4f9cce23dd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -302,6 +302,7 @@ codecov: QUICKCHECK_TESTS: 1 INK_COVERAGE_REPORTING: "true" CARGO_INCREMENTAL: 0 + RUSTC_BOOTSTRAP: "1" # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md RUSTFLAGS: "-Zprofile -Zmir-opt-level=0 -Ccodegen-units=1 -Clink-dead-code -Copt-level=0 -Coverflow-checks=off" From 9bafbac29ac2aee5b9e482675c426d416ccc0162 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:24:05 +0100 Subject: [PATCH 10/13] Update traits crate description --- crates/storage/traits/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/storage/traits/Cargo.toml b/crates/storage/traits/Cargo.toml index ba75e39def..5073b45769 100644 --- a/crates/storage/traits/Cargo.toml +++ b/crates/storage/traits/Cargo.toml @@ -7,9 +7,9 @@ edition = "2021" license = "Apache-2.0" readme = "../README.md" repository = "https://github.com/paritytech/ink" -documentation = "https://docs.rs/ink_storage_derive" +documentation = "https://docs.rs/ink_storage_traits" homepage = "https://www.parity.io/" -description = "[ink!] Utils codegen crate related to ink_storage." +description = "[ink!] defines traits for using ink storage." keywords = ["wasm", "parity", "webassembly", "blockchain", "edsl"] categories = ["no-std", "embedded"] include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE"] From e877c902d660a2e869f1947b8a85ef22a2b1ff65 Mon Sep 17 00:00:00 2001 From: ascjones Date: Fri, 16 Sep 2022 15:24:37 +0100 Subject: [PATCH 11/13] Attempt to fix docs job --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4f9cce23dd..d76a7cb9ba 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -282,7 +282,7 @@ docs: script: - cargo doc --no-deps --all-features -p scale-info -p ink_metadata -p ink_env - -p ink_storage -p ink_storage_traits -p ink_storage_derive + -p ink_storage -p ink_storage_traits -p ink_primitives -p ink_prelude -p ink -p ink_macro -p ink_ir -p ink_codegen - mv ${CARGO_TARGET_DIR}/doc ./crate-docs From 1a3116bd68222549061116908b01a8435d139510 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Tue, 20 Sep 2022 11:52:04 +0100 Subject: [PATCH 12/13] Update crates/ink/ir/src/ir/utils.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Müller --- crates/ink/ir/src/ir/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ink/ir/src/ir/utils.rs b/crates/ink/ir/src/ir/utils.rs index 987162d8f5..6f4b47d256 100644 --- a/crates/ink/ir/src/ir/utils.rs +++ b/crates/ink/ir/src/ir/utils.rs @@ -147,7 +147,7 @@ where /// Finds the salt of a struct, enum or union. /// The salt is any generic that has bound `StorageKey`. -/// In most cases it is parent storage key or auto-generated storage key. +/// In most cases it is the parent storage key or the auto-generated storage key. pub fn find_storage_key_salt(input: &syn::DeriveInput) -> Option { input.generics.params.iter().find_map(|param| { if let syn::GenericParam::Type(type_param) = param { From d8da53d9ffbca8a1cbca6f3f88fbdd4a7c2b652b Mon Sep 17 00:00:00 2001 From: ascjones Date: Tue, 20 Sep 2022 12:03:07 +0100 Subject: [PATCH 13/13] Add comment --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d76a7cb9ba..f0e997f966 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -302,6 +302,8 @@ codecov: QUICKCHECK_TESTS: 1 INK_COVERAGE_REPORTING: "true" CARGO_INCREMENTAL: 0 + # Needed because `codecov` requires nightly features to work + # (see `-Z` in the `RUSTFLAGS` below). RUSTC_BOOTSTRAP: "1" # Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md RUSTFLAGS: "-Zprofile -Zmir-opt-level=0 -Ccodegen-units=1