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

Derive StorageAccess impl for enums #3460

Merged
merged 15 commits into from
Jul 16, 2023

Conversation

maciejka
Copy link
Contributor

@maciejka maciejka commented Jun 20, 2023

Btw should it be:
#[derive(storage_access::StorageAccess)]
or:
#[derive(starknet::StorageAccess)]
or just:
#[derive(StorageAccess)]


This change is Reviewable

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @maciejka)


crates/cairo-lang-starknet/src/plugin/mod.rs line 51 at r2 (raw file):

                storage_access::handle_enum(db, enum_ast)
            }
            ast::Item::Enum(enum_ast) => handle_enum(db, enum_ast),

remove use ..::handle_enum(similar to how the struct is handled)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[derive(starknet::StorageAccess)] AFAIK - if it is different it is a bug.

Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @maciejka)

@maciejka
Copy link
Contributor Author

Reviewed 1 of 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @maciejka)

crates/cairo-lang-starknet/src/plugin/mod.rs line 51 at r2 (raw file):

                storage_access::handle_enum(db, enum_ast)
            }
            ast::Item::Enum(enum_ast) => handle_enum(db, enum_ast),

remove use ..::handle_enum(similar to how the struct is handled)

Fixed.

@maciejka
Copy link
Contributor Author

maciejka commented Jul 12, 2023

#[derive(starknet::StorageAccess)] AFAIK - if it is different it is a bug.

Reviewable status: 1 of 3 files reviewed, 1 unresolved discussion (waiting on @maciejka)

It was storage_access::StorageAccess, changed to starknet::StorageAccess. It will break early adopters contracts who tried v2.0.0.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 10 files at r3, 1 of 3 files at r4, all commit messages.
Reviewable status: 6 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)


crates/cairo-lang-starknet/src/plugin/storage_access.rs line 186 at r4 (raw file):

                tc.ty(db).as_syntax_node().get_text_without_trivia(db)
            }
        };

instead of special type handling - just add a normal impl for empty tuples StorageAccess in the corelib.

Code quote:

        let variant_type = match variant.type_clause(db) {
            ast::OptionTypeClause::Empty(_) => "()".to_string(),
            ast::OptionTypeClause::TypeClause(tc) => {
                tc.ty(db).as_syntax_node().get_text_without_trivia(db)
            }
        };

crates/cairo-lang-starknet/src/plugin/storage_access.rs line 290 at r4 (raw file):

                match value {{
                    {match_size}
                }}

we are probably going to make it size and remove the internal - as well as make the function a const.

so i suggest not actually being inner value dependent:
1 + max(field1.size_internal(), max(field2.size_internal(), max(field3.size_internal(), field4.size_internal())))

Code quote:

            fn size_internal(value: {enum_name}) -> u8 {{
                match value {{
                    {match_size}
                }}

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand - but this is required.

Reviewable status: 6 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 6 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)


crates/cairo-lang-starknet/src/plugin/storage_access.rs line 186 at r4 (raw file):

Previously, orizi wrote…

instead of special type handling - just add a normal impl for empty tuples StorageAccess in the corelib.

automatic implementation up to size 4 now is on main.


crates/cairo-lang-starknet/src/plugin/storage_access.rs line 290 at r4 (raw file):

Previously, orizi wrote…

we are probably going to make it size and remove the internal - as well as make the function a const.

so i suggest not actually being inner value dependent:
1 + max(field1.size_internal(), max(field2.size_internal(), max(field3.size_internal(), field4.size_internal())))

this was changed in main to size.

@maciejka
Copy link
Contributor Author

Previously, orizi wrote…
this was changed in main to size.

Updated implementation according to your suggestions.
Would would please share the resoning behind making size function a const?
Not sure why clippy on CI complains. Locally it works just fine.

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size issue:
Assume you have a field with non const size, and after it another field: any change to the first field, may cause changes to the second one just because of offsets, where this could have been avoided.
Therefore each field should have its own span in the actual strip of 256 felts.

The clippy issue? I would assume there was some stable rust version update, will check tomorrow.

Reviewed 3 of 8 files at r5, all commit messages.
Reviewable status: 5 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 8 files at r5.
Reviewable status: 9 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 9 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)


crates/cairo-lang-starknet/src/plugin/storage_access.rs line 177 at r5 (raw file):

        match_idx.push(format!(
            "if idx == {i} {{ \

use formatdoc instead of all the ''

@maciejka
Copy link
Contributor Author

Reviewable status: 9 of 10 files reviewed, 2 unresolved discussions (waiting on @maciejka)

crates/cairo-lang-starknet/src/plugin/storage_access.rs line 177 at r5 (raw file):

        match_idx.push(format!(
            "if idx == {i} {{ \

use formatdoc instead of all the ''

Replaced format with formatdoc, generated code is more readble but I had to add one more depencency (indent).

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 3 of 4 files at r6.
Reviewable status: 12 of 13 files reviewed, all discussions resolved

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 4 files at r6.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @maciejka)

Copy link
Contributor

@spapinistarkware spapinistarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 10 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @maciejka)

Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @maciejka)

@orizi orizi added this pull request to the merge queue Jul 16, 2023
Merged via the queue into starkware-libs:main with commit 1d645d0 Jul 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants