-
Notifications
You must be signed in to change notification settings - Fork 732
refactor(sierra-to-casm): Made edit_state based on &mut self.
#9495
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(sierra-to-casm): Made edit_state based on &mut self.
#9495
Conversation
587af38 to
79e3410
Compare
561ab13 to
ea40ca4
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eytan-starkware reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: 2 of 4 files reviewed, 2 unresolved discussions (waiting on @orizi and @TomerStarkware).
crates/cairo-lang-sierra/src/edit_state.rs line 28 at r1 (raw file):
/// Trait for editing the state of variables in a map. pub trait EditState<V> { /// Extracts out the given ids from the map, failing if some id is missing.
Extracts = removes. Please improve comment to be clear
crates/cairo-lang-sierra/src/edit_state_test.rs line 6 at r1 (raw file):
use crate::edit_state::{EditState, EditStateError}; use crate::ids::VarId;
The tests seem roundabout. Why hide the map behind a new take and put functions, and then create the map with a from?
79e3410 to
4dbf235
Compare
ea40ca4 to
020210a
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomerStarkware reviewed 4 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @orizi).
SIERRA_UPDATE_PATCH_CHANGE_TAG=No interface changes.
4dbf235 to
a5ffe57
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @eytan-starkware).
crates/cairo-lang-sierra/src/edit_state.rs line 28 at r1 (raw file):
Previously, eytan-starkware wrote…
Extracts = removes. Please improve comment to be clear
Done.
crates/cairo-lang-sierra/src/edit_state_test.rs line 6 at r1 (raw file):
Previously, eytan-starkware wrote…
The tests seem roundabout. Why hide the map behind a new take and put functions, and then create the map with a from?
because it makes the tests short.
eytan-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eytan-starkware reviewed 4 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @orizi).

Summary
Refactored variable state management in Sierra by introducing an
EditStatetrait to replace the standalonetake_argsandput_resultsfunctions. This change improves code organization by moving the state manipulation logic into a trait implementation forOrderedHashMap<VarId, V>.Type of change
Please check one:
Why is this change needed?
The previous approach used standalone functions to manipulate variable state, which required returning a new state object each time. This led to more verbose code with multiple variable reassignments. The new trait-based approach allows for more idiomatic in-place modifications, making the code cleaner and easier to maintain.
What was the behavior or documentation before?
Previously, state manipulation required calling standalone functions
take_argsandput_resultsthat would return a new state object, requiring explicit reassignment:What is the behavior or documentation after?
Now, state manipulation is done through the
EditStatetrait methods that modify the state in-place:This eliminates the need for explicit reassignment and makes the code more concise.
Additional context
This change maintains the same functionality while improving code organization. The implementation updates all relevant code in the Sierra codebase to use the new trait methods, including tests that verify the behavior remains consistent.