Skip to content

Commit

Permalink
Replace array impls with const generics (#754)
Browse files Browse the repository at this point in the history
* Replace array impls with const generics

* remove dead code comment

* bump scale codec version
  • Loading branch information
austinabell authored Apr 7, 2021
1 parent 53e9a66 commit 641fd38
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 81 deletions.
2 changes: 1 addition & 1 deletion crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ink_allocator = { version = "3.0.0-rc3", path = "../allocator/", default-feature
ink_primitives = { version = "3.0.0-rc3", path = "../primitives/", default-features = false }
ink_prelude = { version = "3.0.0-rc3", path = "../prelude/", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
num-traits = { version = "0.2", default-features = false, features = ["i128"] }
cfg-if = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ink_metadata = { version = "3.0.0-rc3", path = "../metadata", default-features =
ink_prelude = { version = "3.0.0-rc3", path = "../prelude/", default-features = false }
ink_lang_macro = { version = "3.0.0-rc3", path = "macro", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from"] }
static_assertions = "1.1"

Expand Down
2 changes: 1 addition & 1 deletion crates/lang/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ either = { version = "1.5", default-features = false }
regex = "1.3"
blake2 = "0.9"
heck = "0.3.1"
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
impl-serde = "0.3.1"

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion crates/lang/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ink_lang_ir = { version = "3.0.0-rc3", path = "../ir", default-features = false
ink_lang_codegen = { version = "3.0.0-rc3", path = "../codegen", default-features = false }
ink_primitives = { version = "3.0.0-rc3", path = "../../primitives/", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
syn = "1"
proc-macro2 = "1"

Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]

[dependencies]
ink_prelude = { version = "3.0.0-rc3", path = "../prelude/", default-features = false }
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ink_primitives = { version = "3.0.0-rc3", path = "../primitives/", default-featu
ink_storage_derive = { version = "3.0.0-rc3", path = "derive", default-features = false }
ink_prelude = { version = "3.0.0-rc3", path = "../prelude/", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
derive_more = { version = "0.99", default-features = false, features = ["from", "display"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }
cfg-if = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ proc-macro2 = "1.0"
synstructure = "0.12.4"

[dev-dependencies]
scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive", "full"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive", "full"] }
ink_env = { version = "3.0.0-rc3", path = "../../env" }
ink_primitives = { version = "3.0.0-rc3", path = "../../primitives" }
ink_metadata = { version = "3.0.0-rc3", path = "../../metadata" }
Expand Down
101 changes: 41 additions & 60 deletions crates/storage/src/traits/impls/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,74 +20,55 @@ use crate::traits::{
use array_init::array_init;
use ink_primitives::Key;

#[rustfmt::skip]
macro_rules! forward_supported_array_lens {
( $mac:ident ) => {
$mac! {
1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32,
}
};
}
impl<T, const N: usize> SpreadLayout for [T; N]
where
T: SpreadLayout,
{
const FOOTPRINT: u64 = N as u64 * <T as SpreadLayout>::FOOTPRINT;
const REQUIRES_DEEP_CLEAN_UP: bool = <T as SpreadLayout>::REQUIRES_DEEP_CLEAN_UP;

macro_rules! impl_layout_for_array {
( $($len:literal),* $(,)? ) => {
$(
impl<T> SpreadLayout for [T; $len]
where
T: SpreadLayout,
{
const FOOTPRINT: u64 = $len * <T as SpreadLayout>::FOOTPRINT;
const REQUIRES_DEEP_CLEAN_UP: bool = <T as SpreadLayout>::REQUIRES_DEEP_CLEAN_UP;

fn push_spread(&self, ptr: &mut KeyPtr) {
for elem in self {
<T as SpreadLayout>::push_spread(elem, ptr)
}
}
fn push_spread(&self, ptr: &mut KeyPtr) {
for elem in self {
<T as SpreadLayout>::push_spread(elem, ptr)
}
}

fn clear_spread(&self, ptr: &mut KeyPtr) {
for elem in self {
<T as SpreadLayout>::clear_spread(elem, ptr)
}
}
fn clear_spread(&self, ptr: &mut KeyPtr) {
for elem in self {
<T as SpreadLayout>::clear_spread(elem, ptr)
}
}

fn pull_spread(ptr: &mut KeyPtr) -> Self {
array_init::<_, T, $len>(|_| <T as SpreadLayout>::pull_spread(ptr))
}
}
fn pull_spread(ptr: &mut KeyPtr) -> Self {
array_init::<_, T, N>(|_| <T as SpreadLayout>::pull_spread(ptr))
}
}

impl<T> PackedLayout for [T; $len]
where
T: PackedLayout,
{
#[inline]
fn push_packed(&self, at: &Key) {
for elem in self {
<T as PackedLayout>::push_packed(elem, at)
}
}
impl<T, const N: usize> PackedLayout for [T; N]
where
T: PackedLayout,
{
#[inline]
fn push_packed(&self, at: &Key) {
for elem in self {
<T as PackedLayout>::push_packed(elem, at)
}
}

#[inline]
fn clear_packed(&self, at: &Key) {
for elem in self {
<T as PackedLayout>::clear_packed(elem, at)
}
}
#[inline]
fn clear_packed(&self, at: &Key) {
for elem in self {
<T as PackedLayout>::clear_packed(elem, at)
}
}

#[inline]
fn pull_packed(&mut self, at: &Key) {
for elem in self {
<T as PackedLayout>::pull_packed(elem, at)
}
}
}
)*
#[inline]
fn pull_packed(&mut self, at: &Key) {
for elem in self {
<T as PackedLayout>::pull_packed(elem, at)
}
}
}
forward_supported_array_lens!(impl_layout_for_array);

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion examples/contract-terminate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/contract-transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/delegator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }

adder = { version = "3.0.0-rc3", path = "adder", default-features = false, features = ["ink-as-dependency"] }
subber = { version = "3.0.0-rc3", path = "subber", default-features = false, features = ["ink-as-dependency"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/delegator/accumulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../../crates/env", default-feature
ink_storage = { version = "3.0.0-rc3", path = "../../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/delegator/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ink_lang = { version = "3.0.0-rc3", path = "../../../crates/lang", default-featu

accumulator = { version = "3.0.0-rc3", path = "../accumulator", default-features = false, features = ["ink-as-dependency"] }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/delegator/subber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ink_lang = { version = "3.0.0-rc3", path = "../../../crates/lang", default-featu

accumulator = { version = "3.0.0-rc3", path = "../accumulator", default-features = false, features = ["ink-as-dependency"] }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/erc20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/erc721/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/flipper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/incrementer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/multisig_plain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-fe
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }
ink_prelude = { version = "3.0.0-rc3", path = "../../crates/prelude", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/trait-erc20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down
2 changes: 1 addition & 1 deletion examples/trait-flipper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ink_env = { version = "3.0.0-rc3", path = "../../crates/env", default-features =
ink_storage = { version = "3.0.0-rc3", path = "../../crates/storage", default-features = false }
ink_lang = { version = "3.0.0-rc3", path = "../../crates/lang", default-features = false }

scale = { package = "parity-scale-codec", version = "2.0", default-features = false, features = ["derive"] }
scale = { package = "parity-scale-codec", version = "2.1", default-features = false, features = ["derive"] }
scale-info = { version = "0.6", default-features = false, features = ["derive"], optional = true }

# Should be removed once bitvecto-rs/bitvec#105 is resolved
Expand Down

0 comments on commit 641fd38

Please sign in to comment.