Skip to content

Conversation

@orizi
Copy link
Collaborator

@orizi orizi commented Jan 4, 2026

Summary

Added a new utility method add_with_const to CellExpression that creates a cell expression representing the sum of a cell reference and a constant value, with an optimization to return the cell directly when the value is zero. This method is then used to simplify and improve the implementation of boxed struct operations in the Sierra-to-CASM compiler.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The code for handling boxed structs and local-to-box conversions contained duplicated logic for adding offsets to cell references. This PR extracts this common pattern into a reusable utility method, making the code more maintainable and less error-prone. Additionally, it refactors the struct boxed deconstruct implementation to handle offsets more consistently.


What was the behavior or documentation before?

Before this change, offset calculations for boxed structs were implemented directly in each function that needed them, with duplicated logic for handling the special case of zero offsets.


What is the behavior or documentation after?

After this change, a new utility method add_with_const handles offset calculations consistently, with proper optimization for zero offsets. The boxed struct deconstruction logic has been refactored into a separate helper function that uses this new utility.


Additional context

This refactoring improves code maintainability while preserving the same functionality. The new boxed_members_cell_exprs helper function also provides better error handling and documentation for the boxed struct deconstruction process.

Copy link
Collaborator Author

orizi commented Jan 4, 2026

@reviewable-StarkWare
Copy link

This change is Reviewable

@orizi orizi marked this pull request as ready for review January 4, 2026 11:58
@orizi orizi mentioned this pull request Jan 4, 2026
5 tasks
Copy link
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware and @liorgold2).

SIERRA_UPDATE_PATCH_CHANGE_TAG=Update of not-enabled libfuncs.
@orizi orizi force-pushed the orizi/01-04-merged_smalldiffhelper_and_build_128bit_diff_fns branch from e09326b to abde00a Compare January 4, 2026 14:01
@orizi orizi force-pushed the orizi/01-04-refactored_box_getting_libfuncs_by_cellexpression_add_with_const_ branch from b275fd7 to dd8b310 Compare January 4, 2026 14:01
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