Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SpreadLayout and StorageLayout derive macro hygiene #926

Merged
merged 2 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions crates/storage/derive/src/spread_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn max_n(args: &[TokenStream2]) -> TokenStream2 {
Some((head, rest)) => {
let rest = max_n(rest);
quote! {
[#head, #rest][(#head < #rest) as usize]
[#head, #rest][(#head < #rest) as ::core::primitive::usize]
}
}
None => quote! { 0u64 },
Expand Down Expand Up @@ -103,8 +103,8 @@ fn spread_layout_struct_derive(s: &synstructure::Structure) -> TokenStream2 {
s.gen_impl(quote! {
gen impl ::ink_storage::traits::SpreadLayout for @Self {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = #footprint_body;
const REQUIRES_DEEP_CLEAN_UP: bool = #requires_deep_clean_up_body;
const FOOTPRINT: ::core::primitive::u64 = #footprint_body;
const REQUIRES_DEEP_CLEAN_UP: ::core::primitive::bool = #requires_deep_clean_up_body;

fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
#pull_body
Expand Down Expand Up @@ -154,7 +154,7 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
});
quote! {
#pat => {
{ <u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&#index, __key_ptr); }
{ <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&#index, __key_ptr); }
#(
{ #fields }
)*
Expand All @@ -169,12 +169,12 @@ fn spread_layout_enum_derive(s: &synstructure::Structure) -> TokenStream2 {
s.gen_impl(quote! {
gen impl ::ink_storage::traits::SpreadLayout for @Self {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = 1 + #footprint_body;
const FOOTPRINT: ::core::primitive::u64 = 1 + #footprint_body;

const REQUIRES_DEEP_CLEAN_UP: bool = #requires_deep_clean_up_body;
const REQUIRES_DEEP_CLEAN_UP: ::core::primitive::bool = #requires_deep_clean_up_body;

fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
match <u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr) {
match <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr) {
#pull_body
_ => unreachable!("encountered invalid enum discriminant"),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/derive/src/storage_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ fn field_layout<'a>(
let ident = match field.ident.as_ref() {
Some(ident) => {
let ident_str = ident.to_string();
quote! { Some(#ident_str) }
quote! { ::core::option::Option::Some(#ident_str) }
}
None => quote! { None },
None => quote! { ::core::option::Option::None },
};
let ty = &field.ty;
quote! {
Expand Down
56 changes: 28 additions & 28 deletions crates/storage/derive/src/tests/spread_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ fn unit_struct_works() {
const _: () = {
impl ::ink_storage::traits::SpreadLayout for UnitStruct {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = [0u64, 0u64][(0u64 < 0u64) as usize];
const FOOTPRINT: ::core::primitive::u64 = [0u64, 0u64][(0u64 < 0u64) as ::core::primitive::usize];

const REQUIRES_DEEP_CLEAN_UP : bool = (false || false );
const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (false || false );

fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
UnitStruct
Expand Down Expand Up @@ -71,7 +71,7 @@ fn struct_works() {
const _: () = {
impl ::ink_storage::traits::SpreadLayout for NamedFields {
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = [
const FOOTPRINT: ::core::primitive::u64 = [
(((0u64 + <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
Expand All @@ -80,10 +80,10 @@ fn struct_works() {
+ <i32 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <[u8; 32] as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <Box<i32> as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize
< 0u64) as ::core::primitive::usize
];

const REQUIRES_DEEP_CLEAN_UP : bool = (
const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
false || (
(
(
Expand Down Expand Up @@ -181,7 +181,7 @@ fn enum_works() {
const _: () = {
impl ::ink_storage::traits::SpreadLayout for MixedEnum {
#[allow(unused_comparisons)]
const FOOTPRINT : u64 = 1 + [
const FOOTPRINT : ::core::primitive::u64 = 1 + [
0u64 ,
[
(
Expand Down Expand Up @@ -211,7 +211,7 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
][
(
Expand Down Expand Up @@ -241,9 +241,9 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
) as usize
) as ::core::primitive::usize
]
][
(
Expand Down Expand Up @@ -274,7 +274,7 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
][
(
Expand Down Expand Up @@ -304,14 +304,14 @@ fn enum_works() {
+ <(bool, i32) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT
)
< 0u64
) as usize
) as ::core::primitive::usize
]
) as usize
) as ::core::primitive::usize
]
) as usize
) as ::core::primitive::usize
];

const REQUIRES_DEEP_CLEAN_UP : bool = (
const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
(
(false || false)
|| (
Expand All @@ -332,7 +332,7 @@ fn enum_works() {
);

fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
match <u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr)
match <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr)
{
0u8 => MixedEnum::A,
1u8 => MixedEnum::B(
Expand All @@ -350,15 +350,15 @@ fn enum_works() {
match self {
MixedEnum::A => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&0u8,
__key_ptr
);
}
}
MixedEnum::B(__binding_0, __binding_1,) => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&1u8,
__key_ptr
);
Expand All @@ -381,7 +381,7 @@ fn enum_works() {
b: __binding_1,
} => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(
&2u8, __key_ptr
);
}
Expand Down Expand Up @@ -459,16 +459,16 @@ fn generic_struct_works() {
T2: ::ink_storage::traits::SpreadLayout
{
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = [
const FOOTPRINT: ::core::primitive::u64 = [
((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
0u64
][(((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <(T1, T2) as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize
< 0u64) as ::core::primitive::usize
];

const REQUIRES_DEEP_CLEAN_UP : bool = (
const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
false || (
(
false
Expand Down Expand Up @@ -555,7 +555,7 @@ fn generic_enum_works() {
T2: ::ink_storage::traits::SpreadLayout
{
#[allow(unused_comparisons)]
const FOOTPRINT: u64 = 1 + [
const FOOTPRINT: ::core::primitive::u64 = 1 + [
((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT),
[
Expand All @@ -565,7 +565,7 @@ fn generic_enum_works() {
][(((0u64
+ <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize]
< 0u64) as ::core::primitive::usize]
][(((0u64 + <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< [
Expand All @@ -575,10 +575,10 @@ fn generic_enum_works() {
][(((0u64
+ <T1 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
+ <T2 as ::ink_storage::traits::SpreadLayout>::FOOTPRINT)
< 0u64) as usize]) as usize
< 0u64) as ::core::primitive::usize]) as ::core::primitive::usize
];

const REQUIRES_DEEP_CLEAN_UP : bool = (
const REQUIRES_DEEP_CLEAN_UP : ::core::primitive::bool = (
(
false || (
(
Expand All @@ -598,7 +598,7 @@ fn generic_enum_works() {
);

fn pull_spread(__key_ptr: &mut ::ink_storage::traits::KeyPtr) -> Self {
match <u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr)
match <::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr)
{
0u8 => GenericEnum::Tuple(
<T1 as ::ink_storage::traits::SpreadLayout>::pull_spread(__key_ptr),
Expand All @@ -616,7 +616,7 @@ fn generic_enum_works() {
match self {
GenericEnum::Tuple(__binding_0, __binding_1,) => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&0u8, __key_ptr);
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&0u8, __key_ptr);
}
{
::ink_storage::traits::SpreadLayout::push_spread(
Expand All @@ -636,7 +636,7 @@ fn generic_enum_works() {
b: __binding_1,
} => {
{
<u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&1u8, __key_ptr);
<::core::primitive::u8 as ::ink_storage::traits::SpreadLayout>::push_spread(&1u8, __key_ptr);
}
{
::ink_storage::traits::SpreadLayout::push_spread(
Expand Down
24 changes: 12 additions & 12 deletions crates/storage/derive/src/tests/storage_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ fn tuple_struct_works() {
::ink_metadata::layout::Layout::Struct(
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
])
Expand Down Expand Up @@ -84,15 +84,15 @@ fn named_fields_struct_works() {
::ink_metadata::layout::Layout::Struct(
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
Some("a"),
::core::option::Option::Some("a"),
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("b"),
::core::option::Option::Some("b"),
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("c"),
::core::option::Option::Some("c"),
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
])
Expand Down Expand Up @@ -191,15 +191,15 @@ fn mixed_enum_works() {
::ink_metadata::layout::Discriminant::from(1usize),
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
None,
::core::option::Option::None,
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
]),
Expand All @@ -212,15 +212,15 @@ fn mixed_enum_works() {
::ink_metadata::layout::Discriminant::from(2usize),
::ink_metadata::layout::StructLayout::new(vec![
::ink_metadata::layout::FieldLayout::new(
Some("a"),
::core::option::Option::Some("a"),
<bool as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("b"),
::core::option::Option::Some("b"),
<u32 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
::ink_metadata::layout::FieldLayout::new(
Some("c"),
::core::option::Option::Some("c"),
<i64 as ::ink_storage::traits::StorageLayout>::layout(__key_ptr),
),
]),
Expand Down