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

refactor: use Nullable<u256> in Stack #47

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

enitrat
Copy link
Collaborator

@enitrat enitrat commented Aug 3, 2023

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #45

What is the new behavior?

  • Stack uses Nullable<u256> instead of using helper functions storing (low,high) limbs

Does this introduce a breaking change?

  • Yes
  • No

Other information

Stack tests available_gas values have been reduced to a value close to the minimum required - it will allow us to detect eventual efficiency decreases

Copy link
Collaborator

@ftupas ftupas left a comment

Choose a reason for hiding this comment

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

Looks good! Just some minor comments 🚀

Comment on lines +1 to +2
const STACK_OVERFLOW: felt252 = 'Kakarot: StackOverflow';
const STACK_UNDERFLOW: felt252 = 'Kakarot: StackUnderflow';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice to create errors like these!

Comment on lines +30 to +38
// This should be in the corelib
trait NullableTraitExt<T> {
fn new(value: T) -> Nullable<T>;
}

impl DestructStack of Destruct<Stack> {
fn destruct(self: Stack) nopanic {
self.items.squash();
impl NullableTraitExtImpl of NullableTraitExt<u256> {
fn new(value: u256) -> Nullable<u256> {
let nullable = nullable_from_box(BoxTrait::new(value));
nullable
Copy link
Collaborator

@ftupas ftupas Aug 3, 2023

Choose a reason for hiding this comment

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

Would it make sense to add a TODO here to remove it once available in corelib?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah indeed!

src/stack.cairo Show resolved Hide resolved
Copy link
Member

@ClementWalter ClementWalter left a comment

Choose a reason for hiding this comment

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

lgtm, do we have an idea of the overhead introduced by the Box? in any case, I'd rather go cleaner first, then optimize

@ClementWalter ClementWalter added this pull request to the merge queue Aug 3, 2023
Merged via the queue into main with commit c8887b8 Aug 3, 2023
2 checks passed
@ClementWalter ClementWalter deleted the refactor/nullable-u256-stack branch August 3, 2023 10:18
@enitrat
Copy link
Collaborator Author

enitrat commented Aug 3, 2023

we have an idea of the overhead introduced by the Box

Very little, I compared the previous implementation with this one by running the tests with minimal gas values for both and it was roughly equal.

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