From 41b62945ad8943598bf05edae95883087b2c65b5 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 26 Nov 2020 21:17:13 +0100 Subject: [PATCH 01/16] Get rid of `generic-array` --- crates/storage/Cargo.toml | 1 - .../storage/src/collections/smallvec/impls.rs | 25 +--- .../storage/src/collections/smallvec/iter.rs | 34 ++--- .../storage/src/collections/smallvec/mod.rs | 22 +-- .../src/collections/smallvec/storage.rs | 10 +- .../storage/src/collections/smallvec/tests.rs | 35 +++-- crates/storage/src/lazy/lazy_array.rs | 141 ++++++------------ crates/storage/src/lazy/mod.rs | 1 - crates/storage/src/lib.rs | 4 + 9 files changed, 92 insertions(+), 181 deletions(-) diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index 48f37668268..45f076cd6d5 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -26,7 +26,6 @@ derive_more = { version = "0.99", default-features = false, features = ["from", scale-info = { version = "0.4", default-features = false, features = ["derive"], optional = true } cfg-if = "1.0" array-init = "1.0" -generic-array = "0.14.1" # Workaround: we actually just need criterion as a dev-dependency, but # there is an issue with a doubly included std lib when executing diff --git a/crates/storage/src/collections/smallvec/impls.rs b/crates/storage/src/collections/smallvec/impls.rs index 0ea65304758..45de5f4af42 100644 --- a/crates/storage/src/collections/smallvec/impls.rs +++ b/crates/storage/src/collections/smallvec/impls.rs @@ -17,7 +17,6 @@ use super::{ SmallVec, }; use crate::{ - lazy::LazyArrayLength, traits::PackedLayout, }; use core::iter::{ @@ -25,20 +24,18 @@ use core::iter::{ FromIterator, }; -impl Drop for SmallVec +impl Drop for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn drop(&mut self) { self.clear_cells() } } -impl core::ops::Index for SmallVec +impl core::ops::Index for SmallVec where T: PackedLayout, - N: LazyArrayLength, { type Output = T; @@ -56,10 +53,9 @@ where } } -impl core::ops::IndexMut for SmallVec +impl core::ops::IndexMut for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn index_mut(&mut self, index: u32) -> &mut Self::Output { let len = self.len(); @@ -75,10 +71,9 @@ where } } -impl<'a, T: 'a, N> IntoIterator for &'a SmallVec +impl<'a, T: 'a, const N: usize> IntoIterator for &'a SmallVec where T: PackedLayout, - N: LazyArrayLength, { type Item = &'a T; type IntoIter = Iter<'a, T, N>; @@ -88,10 +83,9 @@ where } } -impl Extend for SmallVec +impl Extend for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn extend(&mut self, iter: I) where @@ -103,10 +97,9 @@ where } } -impl FromIterator for SmallVec +impl FromIterator for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn from_iter(iter: I) -> Self where @@ -118,10 +111,9 @@ where } } -impl core::cmp::PartialEq for SmallVec +impl core::cmp::PartialEq for SmallVec where T: PartialEq + PackedLayout, - N: LazyArrayLength, { fn eq(&self, other: &Self) -> bool { if self.len() != other.len() { @@ -131,9 +123,8 @@ where } } -impl core::cmp::Eq for SmallVec +impl core::cmp::Eq for SmallVec where T: Eq + PackedLayout, - N: LazyArrayLength, { } diff --git a/crates/storage/src/collections/smallvec/iter.rs b/crates/storage/src/collections/smallvec/iter.rs index 66a0f197993..05149b4ae30 100644 --- a/crates/storage/src/collections/smallvec/iter.rs +++ b/crates/storage/src/collections/smallvec/iter.rs @@ -15,16 +15,14 @@ use super::SmallVec; use crate::{ collections::extend_lifetime, - lazy::LazyArrayLength, traits::PackedLayout, }; /// An iterator over shared references to the elements of a small storage vector. #[derive(Debug, Clone, Copy)] -pub struct Iter<'a, T, N> +pub struct Iter<'a, T, const N: usize> where T: PackedLayout, - N: LazyArrayLength, { /// The storage vector to iterate over. vec: &'a SmallVec, @@ -34,10 +32,9 @@ where end: u32, } -impl<'a, T, N> Iter<'a, T, N> +impl<'a, T, const N: usize> Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { /// Creates a new iterator for the given storage vector. pub(crate) fn new(vec: &'a SmallVec) -> Self { @@ -54,10 +51,9 @@ where } } -impl<'a, T, N> Iterator for Iter<'a, T, N> +impl<'a, T, const N: usize> Iterator for Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { type Item = &'a T; @@ -86,17 +82,15 @@ where } } -impl<'a, T, N> ExactSizeIterator for Iter<'a, T, N> +impl<'a, T, const N: usize> ExactSizeIterator for Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { } -impl<'a, T, N> DoubleEndedIterator for Iter<'a, T, N> +impl<'a, T, const N: usize> DoubleEndedIterator for Iter<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { fn next_back(&mut self) -> Option { ::nth_back(self, 0) @@ -118,10 +112,9 @@ where /// An iterator over exclusive references to the elements of a small storage vector. #[derive(Debug)] -pub struct IterMut<'a, T, N> +pub struct IterMut<'a, T, const N: usize> where T: PackedLayout, - N: LazyArrayLength, { /// The storage vector to iterate over. vec: &'a mut SmallVec, @@ -131,10 +124,9 @@ where end: u32, } -impl<'a, T, N> IterMut<'a, T, N> +impl<'a, T, const N: usize> IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { /// Creates a new iterator for the given storage vector. pub(crate) fn new(vec: &'a mut SmallVec) -> Self { @@ -152,10 +144,9 @@ where } } -impl<'a, T, N> IterMut<'a, T, N> +impl<'a, T, const N: usize> IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { fn get_mut<'b>(&'b mut self, at: u32) -> Option<&'a mut T> { self.vec.get_mut(at).map(|value| { @@ -171,10 +162,9 @@ where } } -impl<'a, T, N> Iterator for IterMut<'a, T, N> +impl<'a, T, const N: usize> Iterator for IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { type Item = &'a mut T; @@ -203,17 +193,15 @@ where } } -impl<'a, T, N> ExactSizeIterator for IterMut<'a, T, N> +impl<'a, T, const N: usize> ExactSizeIterator for IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { } -impl<'a, T, N> DoubleEndedIterator for IterMut<'a, T, N> +impl<'a, T, const N: usize> DoubleEndedIterator for IterMut<'a, T, N> where T: PackedLayout, - N: LazyArrayLength, { fn next_back(&mut self) -> Option { ::nth_back(self, 0) diff --git a/crates/storage/src/collections/smallvec/mod.rs b/crates/storage/src/collections/smallvec/mod.rs index 9463aa87726..4dfe55af051 100644 --- a/crates/storage/src/collections/smallvec/mod.rs +++ b/crates/storage/src/collections/smallvec/mod.rs @@ -34,7 +34,6 @@ use crate::{ lazy::{ Lazy, LazyArray, - LazyArrayLength, }, traits::PackedLayout, }; @@ -55,10 +54,9 @@ type Index = u32; /// `Vec` due to the internal differences. /// - Allows to store up to N elements. #[derive(Debug)] -pub struct SmallVec +pub struct SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// The current length of the small vector. len: Lazy, @@ -66,20 +64,18 @@ where elems: LazyArray, } -impl Default for SmallVec +impl Default for SmallVec where T: PackedLayout, - N: LazyArrayLength, { fn default() -> Self { Self::new() } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Clears the underlying storage cells of the storage vector. /// @@ -102,10 +98,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Creates a new empty vector. pub fn new() -> Self { @@ -134,10 +129,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Returns an iterator yielding shared references to all elements. /// @@ -195,10 +189,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Appends an element to the back of the vector. pub fn push(&mut self, value: T) { @@ -212,10 +205,9 @@ where } } -impl SmallVec +impl SmallVec where T: PackedLayout, - N: LazyArrayLength, { /// Pops the last element from the vector and returns it. // diff --git a/crates/storage/src/collections/smallvec/storage.rs b/crates/storage/src/collections/smallvec/storage.rs index 4b41c07ac18..94817253e76 100644 --- a/crates/storage/src/collections/smallvec/storage.rs +++ b/crates/storage/src/collections/smallvec/storage.rs @@ -14,14 +14,12 @@ use super::SmallVec; use crate::{ - lazy::LazyArrayLength, traits::{ KeyPtr, PackedLayout, SpreadLayout, }, }; -use generic_array::typenum::Unsigned; #[cfg(feature = "std")] const _: () = { @@ -36,10 +34,9 @@ const _: () = { }; use scale_info::TypeInfo; - impl StorageLayout for SmallVec + impl StorageLayout for SmallVec where T: PackedLayout + TypeInfo + 'static, - N: LazyArrayLength, { fn layout(key_ptr: &mut KeyPtr) -> Layout { Layout::Struct(StructLayout::new(vec![ @@ -53,12 +50,11 @@ const _: () = { } }; -impl SpreadLayout for SmallVec +impl SpreadLayout for SmallVec where T: PackedLayout, - N: LazyArrayLength, { - const FOOTPRINT: u64 = 1 + ::U64; + const FOOTPRINT: u64 = 1 + N as u64; fn pull_spread(ptr: &mut KeyPtr) -> Self { Self { diff --git a/crates/storage/src/collections/smallvec/tests.rs b/crates/storage/src/collections/smallvec/tests.rs index 961e9721c21..8c096ff1639 100644 --- a/crates/storage/src/collections/smallvec/tests.rs +++ b/crates/storage/src/collections/smallvec/tests.rs @@ -20,17 +20,16 @@ use crate::{ }, Lazy, }; -use generic_array::typenum::*; use ink_primitives::Key; #[test] fn new_vec_works() { - let vec = >::new(); + let vec = >::new(); assert!(vec.is_empty()); assert_eq!(vec.len(), 0); assert_eq!(vec.get(0), None); assert!(vec.iter().next().is_none()); - let default = as Default>::default(); + let default = as Default>::default(); assert!(default.is_empty()); assert_eq!(default.len(), 0); assert_eq!(vec.get(0), None); @@ -40,7 +39,7 @@ fn new_vec_works() { #[test] fn from_iterator_works() { let some_primes = [b'A', b'B', b'C', b'D']; - assert_eq!(some_primes.iter().copied().collect::>(), { + assert_eq!(some_primes.iter().copied().collect::>(), { let mut vec = SmallVec::new(); for prime in &some_primes { vec.push(*prime) @@ -53,20 +52,20 @@ fn from_iterator_works() { #[should_panic] fn from_iterator_too_many() { let some_primes = [b'A', b'B', b'C', b'D', b'E']; - let _ = some_primes.iter().copied().collect::>(); + let _ = some_primes.iter().copied().collect::>(); } #[test] fn from_empty_iterator_works() { assert_eq!( - [].iter().copied().collect::>(), + [].iter().copied().collect::>(), SmallVec::new(), ); } #[test] fn first_last_of_empty() { - let mut vec = >::new(); + let mut vec = >::new(); assert_eq!(vec.first(), None); assert_eq!(vec.first_mut(), None); assert_eq!(vec.last(), None); @@ -75,14 +74,14 @@ fn first_last_of_empty() { #[test] fn pop_on_empty_works() { - let mut vec = >::new(); + let mut vec = >::new(); assert_eq!(vec.pop(), None); } #[test] fn push_pop_first_last_works() { /// Asserts conditions are met for the given storage vector. - fn assert_vec(vec: &SmallVec, len: u32, first: F, last: L) + fn assert_vec(vec: &SmallVec, len: u32, first: F, last: L) where F: Into>, L: Into>, @@ -127,18 +126,18 @@ fn push_beyond_limits_fails() { let mut vec = [b'A', b'B', b'C', b'D'] .iter() .copied() - .collect::>(); + .collect::>(); vec.push(b'E'); } /// Creates a storage vector from the given slice. -fn vec_from_slice(slice: &[u8]) -> SmallVec { - slice.iter().copied().collect::>() +fn vec_from_slice(slice: &[u8]) -> SmallVec { + slice.iter().copied().collect::>() } /// Asserts that the the given ordered storage vector elements are equal to the /// ordered elements of the given slice. -fn assert_eq_slice(vec: &SmallVec, slice: &[u8]) { +fn assert_eq_slice(vec: &SmallVec, slice: &[u8]) { assert_eq!(vec.len() as usize, slice.len()); let vec_copy = vec.iter().copied().collect::>(); assert_eq!(vec_copy.as_slice(), slice); @@ -371,7 +370,7 @@ fn spread_layout_push_pull_works() -> ink_env::Result<()> { // Load the pushed storage vector into another instance and check that // both instances are equal: let vec2 = - as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); + as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); assert_eq!(vec1, vec2); Ok(()) }) @@ -392,7 +391,7 @@ fn spread_layout_clear_works() { // vector's length property cannot read a value: SpreadLayout::clear_spread(&vec1, &mut KeyPtr::from(root_key)); let _ = - as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); + as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); Ok(()) }) .unwrap() @@ -405,7 +404,7 @@ fn storage_is_cleared_completely_after_pull_lazy() { let root_key = Key::from([0x42; 32]); let lazy_vec = Lazy::new(vec_from_slice(&[b'a', b'b', b'c', b'd'])); SpreadLayout::push_spread(&lazy_vec, &mut KeyPtr::from(root_key)); - let pulled_vec = > as SpreadLayout>::pull_spread( + let pulled_vec = > as SpreadLayout>::pull_spread( &mut KeyPtr::from(root_key), ); @@ -438,7 +437,7 @@ fn drop_works() { let setup_result = std::panic::catch_unwind(|| { let vec = vec_from_slice(&[b'a', b'b', b'c', b'd']); SpreadLayout::push_spread(&vec, &mut KeyPtr::from(root_key)); - let _ = as SpreadLayout>::pull_spread(&mut KeyPtr::from( + let _ = as SpreadLayout>::pull_spread(&mut KeyPtr::from( root_key, )); // vec is dropped which should clear the cells @@ -456,7 +455,7 @@ fn drop_works() { assert_eq!(used_cells, 0); let _ = - as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); + as SpreadLayout>::pull_spread(&mut KeyPtr::from(root_key)); Ok(()) }) .unwrap() diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index e5dea0d4343..055874a2133 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -31,37 +31,11 @@ use core::{ mem, ptr::NonNull, }; -use generic_array::{ - typenum::{ - UInt, - UTerm, - Unsigned, - B0, - B1, - }, - ArrayLength, - GenericArray, -}; use ink_primitives::Key; /// The index type used in the lazy storage chunk. pub type Index = u32; -/// Utility trait for helping with lazy array construction. -pub trait LazyArrayLength: - ArrayLength>>> + Unsigned -{ -} -impl LazyArrayLength for UTerm {} -impl>>>> LazyArrayLength - for UInt -{ -} -impl>>>> LazyArrayLength - for UInt -{ -} - /// A lazy storage array that spans over N storage cells. /// /// Storage data structure to emulate storage arrays: `[T; N]`. @@ -75,9 +49,7 @@ impl>>>> LazyArrayLength /// This is mainly used as low-level storage primitives by other high-level /// storage primitives in order to manage the contract storage for a whole /// chunk of storage cells. -pub struct LazyArray -where - N: LazyArrayLength, +pub struct LazyArray { /// The offset key for the N cells. /// @@ -104,13 +76,12 @@ const _: () = { }; use scale_info::TypeInfo; - impl StorageLayout for LazyArray + impl StorageLayout for LazyArray where T: TypeInfo + 'static, - N: LazyArrayLength, { fn layout(key_ptr: &mut KeyPtr) -> Layout { - let capacity = ::U32; + let capacity = N as u32; Layout::Array(ArrayLayout::new( LayoutKey::from(key_ptr.advance_by(capacity as u64)), capacity, @@ -123,15 +94,13 @@ const _: () = { } }; -struct DebugEntryArray<'a, T, N>(&'a EntryArray) +struct DebugEntryArray<'a, T, const N: usize>(&'a EntryArray) where - T: Debug, - N: LazyArrayLength; + T: Debug; -impl<'a, T, N> Debug for DebugEntryArray<'a, T, N> +impl<'a, T, const N: usize> Debug for DebugEntryArray<'a, T, N> where T: Debug, - N: LazyArrayLength, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_map() @@ -145,10 +114,9 @@ where } } -impl Debug for LazyArray +impl Debug for LazyArray where T: Debug, - N: LazyArrayLength, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("LazyArray") @@ -160,8 +128,7 @@ where #[test] fn debug_impl_works() { - use generic_array::typenum::U4; - let mut larray = >::new(); + let mut larray = >::new(); // Empty imap. assert_eq!( format!("{:?}", &larray), @@ -194,21 +161,18 @@ fn debug_impl_works() { } /// Returns the capacity for an array with the given array length. -fn array_capacity() -> u32 -where - N: LazyArrayLength, +fn array_capacity() -> u32 { - ::U32 + N as u32 } /// The underlying array cache for the [`LazyArray`]. #[derive(Debug)] -pub struct EntryArray -where - N: LazyArrayLength, +pub struct EntryArray { /// The cache entries of the entry array. - entries: GenericArray>>, N>, + //entries: GenericArray>>, N>, + entries: [CacheCell>>; N], } #[derive(Debug)] @@ -217,9 +181,7 @@ pub struct EntriesIter<'a, T> { } impl<'a, T> EntriesIter<'a, T> { - pub fn new(entry_array: &'a EntryArray) -> Self - where - N: LazyArrayLength, + pub fn new(entry_array: &'a EntryArray) -> Self { Self { iter: entry_array.entries.iter(), @@ -254,30 +216,24 @@ impl<'a, T> DoubleEndedIterator for EntriesIter<'a, T> { impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} -impl EntryArray -where - N: LazyArrayLength, +impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { Self { - entries: Default::default(), + entries: [(); N].map(|_|Default::default()) } } } -impl Default for EntryArray -where - N: LazyArrayLength, +impl Default for EntryArray { fn default() -> Self { Self::new() } } -impl EntryArray -where - N: LazyArrayLength, +impl EntryArray { /// Returns the constant capacity of the lazy array. #[inline] @@ -325,10 +281,9 @@ where } } -impl LazyArray +impl LazyArray where T: PackedLayout, - N: LazyArrayLength, { /// Clears the underlying storage of the entry at the given index. /// @@ -356,18 +311,14 @@ where } } -impl Default for LazyArray -where - N: LazyArrayLength, +impl Default for LazyArray { fn default() -> Self { Self::new() } } -impl LazyArray -where - N: LazyArrayLength, +impl LazyArray { /// Creates a new empty lazy array. /// @@ -428,12 +379,11 @@ where } } -impl SpreadLayout for LazyArray +impl SpreadLayout for LazyArray where T: PackedLayout, - N: LazyArrayLength, { - const FOOTPRINT: u64 = ::U64; + const FOOTPRINT: u64 = N as u64; fn pull_spread(ptr: &mut KeyPtr) -> Self { Self::lazy(*ExtKeyPtr::next_for::(ptr)) @@ -458,9 +408,7 @@ where } } -impl LazyArray -where - N: LazyArrayLength, +impl LazyArray { /// Returns the offset key for the given index if not out of bounds. pub fn key_at(&self, at: Index) -> Option { @@ -471,10 +419,9 @@ where } } -impl LazyArray +impl LazyArray where T: PackedLayout, - N: LazyArrayLength, { /// Loads the entry at the given index. /// @@ -604,22 +551,18 @@ mod tests { }, Index, LazyArray, - LazyArrayLength, }; use crate::traits::{ KeyPtr, SpreadLayout, }; - use generic_array::typenum::U4; use ink_primitives::Key; /// Asserts that the cached entries of the given `imap` is equal to the `expected` slice. - fn assert_cached_entries( + fn assert_cached_entries( larray: &LazyArray, expected: &[(Index, StorageEntry)], - ) where - N: LazyArrayLength, - { + ) { let mut len = 0; for (given, expected) in larray .cached_entries() @@ -641,7 +584,7 @@ mod tests { #[test] fn new_works() { - let larray = >::new(); + let larray = >::new(); // Key must be none. assert_eq!(larray.key(), None); assert_eq!(larray.key_at(0), None); @@ -649,7 +592,7 @@ mod tests { // Cached elements must be empty. assert_cached_entries(&larray, &[]); // Same as default: - let default_larray = >::default(); + let default_larray = >::default(); assert_eq!(default_larray.key(), larray.key()); assert_eq!(default_larray.key_at(0), larray.key_at(0)); assert_eq!(larray.capacity(), 4); @@ -659,7 +602,7 @@ mod tests { #[test] fn lazy_works() { let key = Key::from([0x42; 32]); - let larray = >::lazy(key); + let larray = >::lazy(key); // Key must be Some. assert_eq!(larray.key(), Some(&key)); assert_eq!(larray.key_at(0), Some(key)); @@ -671,7 +614,7 @@ mod tests { #[test] fn get_works() { - let mut larray = >::new(); + let mut larray = >::new(); let nothing_changed = &[ (0, StorageEntry::new(None, EntryState::Preserved)), (1, StorageEntry::new(Some(b'B'), EntryState::Mutated)), @@ -701,13 +644,13 @@ mod tests { #[test] #[should_panic(expected = "index is out of bounds")] fn get_out_of_bounds_works() { - let larray = >::new(); + let larray = >::new(); let _ = larray.get(4); } #[test] fn put_get_works() { - let mut larray = >::new(); + let mut larray = >::new(); // Assert that the array cache is empty at first. assert_cached_entries(&larray, &[]); // Put none values. @@ -750,13 +693,13 @@ mod tests { #[test] #[should_panic(expected = "index is out of bounds")] fn put_get_out_of_bounds_works() { - let mut larray = >::new(); + let mut larray = >::new(); let _ = larray.put_get(4, Some(b'A')); } #[test] fn put_works() { - let mut larray = >::new(); + let mut larray = >::new(); // Put some values. larray.put(0, None); larray.put(1, Some(b'B')); @@ -792,13 +735,13 @@ mod tests { #[test] #[should_panic(expected = "index out of bounds: the len is 4 but the index is 4")] fn put_out_of_bounds_works() { - let mut larray = >::new(); + let mut larray = >::new(); larray.put(4, Some(b'A')); } #[test] fn swap_works() { - let mut larray = >::new(); + let mut larray = >::new(); let nothing_changed = &[ (0, StorageEntry::new(Some(b'A'), EntryState::Mutated)), (1, StorageEntry::new(Some(b'B'), EntryState::Mutated)), @@ -847,21 +790,21 @@ mod tests { #[test] #[should_panic(expected = "b is out of bounds")] fn swap_rhs_out_of_bounds() { - let mut larray = >::new(); + let mut larray = >::new(); larray.swap(0, 4); } #[test] #[should_panic(expected = "a is out of bounds")] fn swap_both_out_of_bounds() { - let mut larray = >::new(); + let mut larray = >::new(); larray.swap(4, 4); } #[test] fn spread_layout_works() -> ink_env::Result<()> { ink_env::test::run_test::(|_| { - let mut larray = >::new(); + let mut larray = >::new(); let nothing_changed = &[ (0, StorageEntry::new(Some(b'A'), EntryState::Mutated)), (1, StorageEntry::new(Some(b'B'), EntryState::Mutated)), @@ -879,7 +822,7 @@ mod tests { // Then: Compare both instances to be equal. let root_key = Key::from([0x42; 32]); SpreadLayout::push_spread(&larray, &mut KeyPtr::from(root_key)); - let larray2 = as SpreadLayout>::pull_spread( + let larray2 = as SpreadLayout>::pull_spread( &mut KeyPtr::from(root_key), ); assert_cached_entries(&larray2, &[]); @@ -908,7 +851,7 @@ mod tests { larray2.clear_packed_at(1); larray2.clear_packed_at(2); // Not really needed here. larray2.clear_packed_at(3); // Not really needed here. - let larray3 = as SpreadLayout>::pull_spread( + let larray3 = as SpreadLayout>::pull_spread( &mut KeyPtr::from(root_key), ); assert_cached_entries(&larray3, &[]); diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index a4ed0d1fa63..bb3368efd80 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -43,7 +43,6 @@ use self::{ pub use self::{ lazy_array::{ LazyArray, - LazyArrayLength, }, lazy_cell::LazyCell, lazy_hmap::LazyHashMap, diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index be69590be49..91357473d98 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -20,6 +20,10 @@ //! FFI to interface with SRML contracts and a primitive blockchain //! emulator for simple off-chain testing. +#![feature(array_map)] +#![feature(array_methods)] +#![feature(min_const_generics)] + #![cfg_attr(not(feature = "std"), no_std)] #![deny( missing_docs, From 26bd5678b1208de5c752800f739eb08ba8cf0068 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 26 Nov 2020 22:45:20 +0100 Subject: [PATCH 02/16] Remove comment --- crates/storage/src/lazy/lazy_array.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index 055874a2133..3464300dfa5 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -171,7 +171,6 @@ fn array_capacity() -> u32 pub struct EntryArray { /// The cache entries of the entry array. - //entries: GenericArray>>, N>, entries: [CacheCell>>; N], } From b58062d98301670fec6667424c942fb390efc975 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 26 Nov 2020 23:03:31 +0100 Subject: [PATCH 03/16] Fmt and get rid of feature flags --- .../storage/src/collections/smallvec/impls.rs | 10 +--- .../storage/src/collections/smallvec/iter.rs | 12 +---- .../src/collections/smallvec/storage.rs | 10 ++-- crates/storage/src/lazy/lazy_array.rs | 46 +++++++++---------- crates/storage/src/lazy/mod.rs | 4 +- crates/storage/src/lib.rs | 2 - 6 files changed, 31 insertions(+), 53 deletions(-) diff --git a/crates/storage/src/collections/smallvec/impls.rs b/crates/storage/src/collections/smallvec/impls.rs index 45de5f4af42..87280852e61 100644 --- a/crates/storage/src/collections/smallvec/impls.rs +++ b/crates/storage/src/collections/smallvec/impls.rs @@ -16,9 +16,7 @@ use super::{ Iter, SmallVec, }; -use crate::{ - traits::PackedLayout, -}; +use crate::traits::PackedLayout; use core::iter::{ Extend, FromIterator, @@ -123,8 +121,4 @@ where } } -impl core::cmp::Eq for SmallVec -where - T: Eq + PackedLayout, -{ -} +impl core::cmp::Eq for SmallVec where T: Eq + PackedLayout {} diff --git a/crates/storage/src/collections/smallvec/iter.rs b/crates/storage/src/collections/smallvec/iter.rs index 05149b4ae30..12fb25ce5b5 100644 --- a/crates/storage/src/collections/smallvec/iter.rs +++ b/crates/storage/src/collections/smallvec/iter.rs @@ -82,11 +82,7 @@ where } } -impl<'a, T, const N: usize> ExactSizeIterator for Iter<'a, T, N> -where - T: PackedLayout, -{ -} +impl<'a, T, const N: usize> ExactSizeIterator for Iter<'a, T, N> where T: PackedLayout {} impl<'a, T, const N: usize> DoubleEndedIterator for Iter<'a, T, N> where @@ -193,11 +189,7 @@ where } } -impl<'a, T, const N: usize> ExactSizeIterator for IterMut<'a, T, N> -where - T: PackedLayout, -{ -} +impl<'a, T, const N: usize> ExactSizeIterator for IterMut<'a, T, N> where T: PackedLayout {} impl<'a, T, const N: usize> DoubleEndedIterator for IterMut<'a, T, N> where diff --git a/crates/storage/src/collections/smallvec/storage.rs b/crates/storage/src/collections/smallvec/storage.rs index 94817253e76..7b14149f880 100644 --- a/crates/storage/src/collections/smallvec/storage.rs +++ b/crates/storage/src/collections/smallvec/storage.rs @@ -13,12 +13,10 @@ // limitations under the License. use super::SmallVec; -use crate::{ - traits::{ - KeyPtr, - PackedLayout, - SpreadLayout, - }, +use crate::traits::{ + KeyPtr, + PackedLayout, + SpreadLayout, }; #[cfg(feature = "std")] diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index 3464300dfa5..cc1206b97ae 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -26,8 +26,10 @@ use crate::traits::{ SpreadLayout, }; use core::{ + convert::TryInto, fmt, fmt::Debug, + iter, mem, ptr::NonNull, }; @@ -49,8 +51,7 @@ pub type Index = u32; /// This is mainly used as low-level storage primitives by other high-level /// storage primitives in order to manage the contract storage for a whole /// chunk of storage cells. -pub struct LazyArray -{ +pub struct LazyArray { /// The offset key for the N cells. /// /// If the lazy chunk has been initialized during contract initialization @@ -161,15 +162,13 @@ fn debug_impl_works() { } /// Returns the capacity for an array with the given array length. -fn array_capacity() -> u32 -{ +fn array_capacity() -> u32 { N as u32 } /// The underlying array cache for the [`LazyArray`]. #[derive(Debug)] -pub struct EntryArray -{ +pub struct EntryArray { /// The cache entries of the entry array. entries: [CacheCell>>; N], } @@ -180,8 +179,7 @@ pub struct EntriesIter<'a, T> { } impl<'a, T> EntriesIter<'a, T> { - pub fn new(entry_array: &'a EntryArray) -> Self - { + pub fn new(entry_array: &'a EntryArray) -> Self { Self { iter: entry_array.entries.iter(), } @@ -215,25 +213,28 @@ impl<'a, T> DoubleEndedIterator for EntriesIter<'a, T> { impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} -impl EntryArray -{ +impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { - Self { - entries: [(); N].map(|_|Default::default()) - } + let entries = iter::repeat_with(|| Default::default()) + .take(N) + .collect::>>>>() + .try_into(); + let entries = match entries { + Ok(entries) => entries, + Err(_) => unreachable!("try_into must work"), + }; + Self { entries } } } -impl Default for EntryArray -{ +impl Default for EntryArray { fn default() -> Self { Self::new() } } -impl EntryArray -{ +impl EntryArray { /// Returns the constant capacity of the lazy array. #[inline] pub fn capacity() -> u32 { @@ -244,7 +245,7 @@ impl EntryArray /// returns the old value if any. fn put(&self, at: Index, new_value: Option) -> Option { mem::replace( - unsafe { self.entries.as_slice()[at as usize].get_ptr().as_mut() }, + unsafe { self.entries[at as usize].get_ptr().as_mut() }, Some(StorageEntry::new(new_value, EntryState::Mutated)), ) .map(StorageEntry::into_value) @@ -310,15 +311,13 @@ where } } -impl Default for LazyArray -{ +impl Default for LazyArray { fn default() -> Self { Self::new() } } -impl LazyArray -{ +impl LazyArray { /// Creates a new empty lazy array. /// /// # Note @@ -407,8 +406,7 @@ where } } -impl LazyArray -{ +impl LazyArray { /// Returns the offset key for the given index if not out of bounds. pub fn key_at(&self, at: Index) -> Option { if at >= self.capacity() { diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index bb3368efd80..aaa1af85951 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -41,9 +41,7 @@ use self::{ }; #[doc(inline)] pub use self::{ - lazy_array::{ - LazyArray, - }, + lazy_array::LazyArray, lazy_cell::LazyCell, lazy_hmap::LazyHashMap, lazy_imap::LazyIndexMap, diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 91357473d98..84807314e6f 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -20,8 +20,6 @@ //! FFI to interface with SRML contracts and a primitive blockchain //! emulator for simple off-chain testing. -#![feature(array_map)] -#![feature(array_methods)] #![feature(min_const_generics)] #![cfg_attr(not(feature = "std"), no_std)] From 1038b991f78018ceffdb7fe655d61b61186f437e Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 26 Nov 2020 23:24:31 +0100 Subject: [PATCH 04/16] Include Vec --- crates/storage/src/lazy/lazy_array.rs | 1 + crates/storage/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index cc1206b97ae..3938b77e50d 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -33,6 +33,7 @@ use core::{ mem, ptr::NonNull, }; +use ink_prelude::vec::Vec; use ink_primitives::Key; /// The index type used in the lazy storage chunk. diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 84807314e6f..4a04109322f 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -21,7 +21,6 @@ //! emulator for simple off-chain testing. #![feature(min_const_generics)] - #![cfg_attr(not(feature = "std"), no_std)] #![deny( missing_docs, From 3472393f7cf0f2a5a2167835e66d7e11c0f24028 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 26 Nov 2020 23:25:22 +0100 Subject: [PATCH 05/16] Make clippy happy --- crates/storage/src/lazy/cache_cell.rs | 5 ----- crates/storage/src/lazy/lazy_array.rs | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/storage/src/lazy/cache_cell.rs b/crates/storage/src/lazy/cache_cell.rs index e77fd7b08e5..7d4bd581e77 100644 --- a/crates/storage/src/lazy/cache_cell.rs +++ b/crates/storage/src/lazy/cache_cell.rs @@ -36,11 +36,6 @@ impl CacheCell { inner: UnsafeCell::new(value), } } - - /// Returns the inner value. - pub fn into_inner(self) -> T { - self.inner.into_inner() - } } impl Debug for CacheCell diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index 3938b77e50d..fe6ea989bf3 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -217,7 +217,7 @@ impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { - let entries = iter::repeat_with(|| Default::default()) + let entries = iter::repeat_with(Default::default) .take(N) .collect::>>>>() .try_into(); From 821c2f8e23933a4255e1e94202ba7750f9c5a946 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 2 Dec 2020 16:08:38 +0100 Subject: [PATCH 06/16] Add `into_inner` back in --- crates/storage/src/lazy/cache_cell.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/storage/src/lazy/cache_cell.rs b/crates/storage/src/lazy/cache_cell.rs index 7d4bd581e77..bcd8dbb3c2d 100644 --- a/crates/storage/src/lazy/cache_cell.rs +++ b/crates/storage/src/lazy/cache_cell.rs @@ -36,6 +36,12 @@ impl CacheCell { inner: UnsafeCell::new(value), } } + + /// Returns the inner value. + #[allow(dead_code)] + pub fn into_inner(self) -> T { + self.inner.into_inner() + } } impl Debug for CacheCell From e53d752965f6d99894312f77ec7e37086d7940d9 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 2 Dec 2020 16:14:52 +0100 Subject: [PATCH 07/16] Do not allocate heap memory --- crates/storage/src/lazy/lazy_array.rs | 12 +----------- crates/storage/src/lib.rs | 1 + 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index fe6ea989bf3..f8b4a70fdee 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -26,14 +26,11 @@ use crate::traits::{ SpreadLayout, }; use core::{ - convert::TryInto, fmt, fmt::Debug, - iter, mem, ptr::NonNull, }; -use ink_prelude::vec::Vec; use ink_primitives::Key; /// The index type used in the lazy storage chunk. @@ -217,14 +214,7 @@ impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { - let entries = iter::repeat_with(Default::default) - .take(N) - .collect::>>>>() - .try_into(); - let entries = match entries { - Ok(entries) => entries, - Err(_) => unreachable!("try_into must work"), - }; + let entries = [(); N].map(|_| Default::default()); Self { entries } } } diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index 4a04109322f..f04eb54f723 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -21,6 +21,7 @@ //! emulator for simple off-chain testing. #![feature(min_const_generics)] +#![feature(array_map)] #![cfg_attr(not(feature = "std"), no_std)] #![deny( missing_docs, From 5ff3a749bad53aeab4858b084961e43c2d07def9 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 3 Dec 2020 20:41:37 +0100 Subject: [PATCH 08/16] Use `array_init` for initializing --- crates/storage/src/lazy/lazy_array.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index f8b4a70fdee..20fef7bd171 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -214,8 +214,9 @@ impl<'a, T> ExactSizeIterator for EntriesIter<'a, T> {} impl EntryArray { /// Creates a new entry array cache. pub fn new() -> Self { - let entries = [(); N].map(|_| Default::default()); - Self { entries } + Self { + entries: array_init::array_init(|_| Default::default()), + } } } From 2c6d8e5cb5c7be1b293d820b107d6b04f14a5bcd Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 3 Dec 2020 20:42:12 +0100 Subject: [PATCH 09/16] Revert me: Activate `const-generics` feature in `array-init` --- crates/storage/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index 45f076cd6d5..e901f3e48f5 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -25,7 +25,7 @@ scale = { package = "parity-scale-codec", version = "1.3", default-features = fa derive_more = { version = "0.99", default-features = false, features = ["from", "display"] } scale-info = { version = "0.4", default-features = false, features = ["derive"], optional = true } cfg-if = "1.0" -array-init = "1.0" +array-init = { version = "1.0", default-features = false, features = ["const-generics"] } # Workaround: we actually just need criterion as a dev-dependency, but # there is an issue with a doubly included std lib when executing From ddb478d98f8031749f1b5af2cda25c265f3dc3b8 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 3 Dec 2020 22:51:49 +0100 Subject: [PATCH 10/16] Remove `feature(array_map)` --- crates/storage/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index f04eb54f723..4a04109322f 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -21,7 +21,6 @@ //! emulator for simple off-chain testing. #![feature(min_const_generics)] -#![feature(array_map)] #![cfg_attr(not(feature = "std"), no_std)] #![deny( missing_docs, From 30c5219f8f9fc4ae9f7719704eddc09ef218cc9b Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Tue, 2 Feb 2021 14:26:19 +0100 Subject: [PATCH 11/16] Remove feature flag, since it is now stable on nightly --- crates/storage/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index e385d8a24d1..03ff22236da 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -20,7 +20,6 @@ //! FFI to interface with SRML contracts and a primitive blockchain //! emulator for simple off-chain testing. -#![feature(min_const_generics)] #![cfg_attr(not(feature = "std"), no_std)] #![deny( missing_docs, From 66b82074b950bd284bd7ded7005825bc27c3e43c Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 4 Feb 2021 10:18:47 +0100 Subject: [PATCH 12/16] Add feature `ink-unstable` --- crates/storage/Cargo.toml | 1 + crates/storage/src/collections/mod.rs | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/storage/Cargo.toml b/crates/storage/Cargo.toml index 1bd2b0eea9c..84a31831e5b 100644 --- a/crates/storage/Cargo.toml +++ b/crates/storage/Cargo.toml @@ -53,6 +53,7 @@ std = [ "scale-info/std", ] ink-fuzz-tests = ["std"] +ink-unstable = ["std"] [[bench]] name = "bench_lazy" diff --git a/crates/storage/src/collections/mod.rs b/crates/storage/src/collections/mod.rs index 7a4d0b33bad..5956ef1e1ff 100644 --- a/crates/storage/src/collections/mod.rs +++ b/crates/storage/src/collections/mod.rs @@ -22,6 +22,7 @@ pub mod binary_heap; pub mod bitstash; pub mod bitvec; pub mod hashmap; +#[cfg(feature = "ink-unstable")] pub mod smallvec; pub mod stash; pub mod vec; @@ -32,11 +33,14 @@ pub use self::{ bitstash::BitStash, bitvec::Bitvec, hashmap::HashMap, - smallvec::SmallVec, stash::Stash, vec::Vec, }; +#[cfg(feature = "ink-unstable")] +#[doc(inline)] +pub use self::smallvec::SmallVec; + /// Extends the lifetime 'a to the outliving lifetime 'b for the given reference. /// /// # Note From ba19616758efb112bc221978eb7b1e5f2e195783 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 4 Feb 2021 11:22:45 +0100 Subject: [PATCH 13/16] Put `LazyArray` behind `ink-unstable` feature --- crates/storage/src/lazy/entry.rs | 9 +++++---- crates/storage/src/lazy/mod.rs | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/storage/src/lazy/entry.rs b/crates/storage/src/lazy/entry.rs index 3c73db03ee4..5867aa40bd1 100644 --- a/crates/storage/src/lazy/entry.rs +++ b/crates/storage/src/lazy/entry.rs @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(feature = "ink-unstable")] +#[doc(inline)] +use crate::lazy::LazyArray; #[cfg(doc)] -use crate::lazy::{ - LazyArray, - LazyIndexMap, -}; +use crate::lazy::LazyIndexMap; + use crate::traits::{ clear_packed_root, clear_spread_root_opt, diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index 35057a48a40..adc00b57411 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -32,6 +32,9 @@ mod lazy_array; mod lazy_cell; mod lazy_imap; +#[cfg(feature = "ink-unstable")] +#[doc(inline)] +pub use self::lazy_array::LazyArray; use self::{ cache_cell::CacheCell, entry::{ @@ -41,11 +44,11 @@ use self::{ }; #[doc(inline)] pub use self::{ - lazy_array::LazyArray, lazy_cell::LazyCell, lazy_hmap::LazyHashMap, lazy_imap::LazyIndexMap, }; + use crate::traits::{ KeyPtr, SpreadLayout, From f1de266797af24bec740748ffaaae6773d45de79 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 4 Feb 2021 11:34:38 +0100 Subject: [PATCH 14/16] Remove newline --- crates/storage/src/lazy/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index 23ce1242d55..0c10f231435 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -48,7 +48,6 @@ pub use self::{ lazy_hmap::LazyHashMap, lazy_imap::LazyIndexMap, }; - use crate::traits::{ KeyPtr, SpreadLayout, From f35e08fc595c0f8ee460e0429de6c33a80c09442 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 4 Feb 2021 11:51:12 +0100 Subject: [PATCH 15/16] Allow dead code in `LazyArray` when `ink-unstable` missing --- crates/storage/src/lazy/lazy_array.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index f168bea549a..884a7480f6b 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg(not(feature = "ink-unstable"))] +#![allow(dead_code)] + use super::{ CacheCell, EntryState, From 73804b3d22331c289ab01dde3b698ef3c3f71cf2 Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 4 Feb 2021 12:13:34 +0100 Subject: [PATCH 16/16] Remove unnecessary allow --- crates/storage/src/collections/smallvec/storage.rs | 7 +++---- crates/storage/src/lazy/lazy_array.rs | 3 --- crates/storage/src/lazy/mod.rs | 1 + 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/storage/src/collections/smallvec/storage.rs b/crates/storage/src/collections/smallvec/storage.rs index cabbe2d1d87..510ec1b7252 100644 --- a/crates/storage/src/collections/smallvec/storage.rs +++ b/crates/storage/src/collections/smallvec/storage.rs @@ -21,10 +21,9 @@ use crate::traits::{ #[cfg(feature = "std")] const _: () = { - use crate::{ - lazy::LazyArray, - traits::StorageLayout, - }; + #[cfg(feature = "ink-unstable")] + use crate::lazy::LazyArray; + use crate::traits::StorageLayout; use ink_metadata::layout::{ FieldLayout, Layout, diff --git a/crates/storage/src/lazy/lazy_array.rs b/crates/storage/src/lazy/lazy_array.rs index 884a7480f6b..f168bea549a 100644 --- a/crates/storage/src/lazy/lazy_array.rs +++ b/crates/storage/src/lazy/lazy_array.rs @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg(not(feature = "ink-unstable"))] -#![allow(dead_code)] - use super::{ CacheCell, EntryState, diff --git a/crates/storage/src/lazy/mod.rs b/crates/storage/src/lazy/mod.rs index 0c10f231435..be22d26f6d0 100644 --- a/crates/storage/src/lazy/mod.rs +++ b/crates/storage/src/lazy/mod.rs @@ -28,6 +28,7 @@ pub mod lazy_hmap; mod cache_cell; mod entry; +#[cfg(feature = "ink-unstable")] mod lazy_array; mod lazy_cell; mod lazy_imap;