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

Added const for starknet types. #6961

Merged
merged 1 commit into from
Jan 15, 2025
Merged

Added const for starknet types. #6961

merged 1 commit into from
Jan 15, 2025

Conversation

orizi
Copy link
Collaborator

@orizi orizi commented Dec 31, 2024

No description provided.

@orizi orizi requested a review from liorgold2 December 31, 2024 09:50
@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator

@liorgold2 liorgold2 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 2 files at r1, all commit messages.
Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @orizi)


a discussion (no related file):
Missing failure test (initializing with an invalid value)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 12 at r1 (raw file):

use super::int::unsigned128::Uint128Type;
use super::non_zero::NonZeroType;
use super::starknet::interoperability::{ClassHashType, ContractAddressType};

Are we ok with this dependency? (I guess we are)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 74 at r1 (raw file):

) -> Result<(), SpecializationError> {
    let inner_type_info = context.get_type_info(inner_ty.clone())?;
    let type_range = if inner_type_info.long_id.generic_id == StructType::ID {

This is slightly confusing.
Split to two paragraphs:

if ... {
    return validate...(...);
} else if ... {
    return validate...(...);
} else if ... {
    return validate...(...);
}

let type_range = if ... {
    ...
} else {
    ...
}
...

Copy link
Collaborator

@liorgold2 liorgold2 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: 1 of 2 files reviewed, 4 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 81 at r1 (raw file):

        return validate_const_nz_data(context, &inner_type_info, inner_data);
    } else if [ContractAddressType::id(), ClassHashType::id()]
        .contains(&inner_type_info.long_id.generic_id)

Move this to a variable. It appears many times in this function and will make this particular line shorter.

Code quote:

inner_type_info.long_id.generic_id

Copy link
Collaborator

@liorgold2 liorgold2 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: 1 of 2 files reviewed, 5 unresolved discussions (waiting on @orizi)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 83 at r1 (raw file):

        .contains(&inner_type_info.long_id.generic_id)
    {
        Range::half_open(0, BigInt::one().shl(251))

I guess this appears in the libfunc as well, so I prefer to have it defined once, in a starknet module and not here.

Code quote:

BigInt::one().shl(251)

Copy link
Collaborator

@liorgold2 liorgold2 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 2 files at r1.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @orizi)

Copy link
Collaborator Author

@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: all files reviewed, 5 unresolved discussions (waiting on @liorgold2)


a discussion (no related file):

Previously, liorgold2 wrote…

Missing failure test (initializing with an invalid value)

Done.


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 12 at r1 (raw file):

Previously, liorgold2 wrote…

Are we ok with this dependency? (I guess we are)

Don't think we have much of a choice.


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 74 at r1 (raw file):

Previously, liorgold2 wrote…

This is slightly confusing.
Split to two paragraphs:

if ... {
    return validate...(...);
} else if ... {
    return validate...(...);
} else if ... {
    return validate...(...);
}

let type_range = if ... {
    ...
} else {
    ...
}
...

Done.


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 81 at r1 (raw file):

Previously, liorgold2 wrote…

Move this to a variable. It appears many times in this function and will make this particular line shorter.

Done.

Copy link
Collaborator Author

@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: all files reviewed, 5 unresolved discussions (waiting on @liorgold2)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 83 at r1 (raw file):

Previously, liorgold2 wrote…

I guess this appears in the libfunc as well, so I prefer to have it defined once, in a starknet module and not here.

Done.

@orizi orizi force-pushed the orizi/const-starknet branch from c7d7e1e to df56776 Compare January 14, 2025 08:30
Copy link
Collaborator

@liorgold2 liorgold2 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: 1 of 3 files reviewed, 3 unresolved discussions

Copy link
Collaborator

@liorgold2 liorgold2 left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @orizi)

Copy link

@shaharsamocha7 shaharsamocha7 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 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 83 at r2 (raw file):

        return validate_const_nz_data(context, &inner_type_info, inner_data);
    }
    let type_range = if *inner_generic_id == ContractAddressType::id() {

Why these cases are not in from_type_info

Code quote:

    let type_range = if *inner_generic_id == ContractAddressType::id() {

Copy link
Collaborator Author

@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: all files reviewed, 1 unresolved discussion (waiting on @shaharsamocha7)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 83 at r2 (raw file):

Previously, shaharsamocha7 wrote…

Why these cases are not in from_type_info

they'd be considered a valid BoundedInt in that case, and this is probably bad.

Copy link
Collaborator

@liorgold2 liorgold2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @shaharsamocha7)

Copy link

@shaharsamocha7 shaharsamocha7 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: all files reviewed, 1 unresolved discussion (waiting on @orizi)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 83 at r2 (raw file):

Previously, orizi wrote…

they'd be considered a valid BoundedInt in that case, and this is probably bad.

you also have bytes31 there.
Unblocking

@orizi orizi added this pull request to the merge queue Jan 15, 2025
Copy link
Collaborator Author

@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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @orizi)


crates/cairo-lang-sierra/src/extensions/modules/const_type.rs line 83 at r2 (raw file):

Previously, shaharsamocha7 wrote…

you also have bytes31 there.
Unblocking

I consider Bytes31 as u248, more than i consider ContractAddress and ClassHash as u251.

Merged via the queue into dev-v2.10.0 with commit 13bec09 Jan 15, 2025
48 checks passed
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.

4 participants