-
Notifications
You must be signed in to change notification settings - Fork 738
Updating enum_boxed_match according to audit.
#9600
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
base: main
Are you sure you want to change the base?
Updating enum_boxed_match according to audit.
#9600
Conversation
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e9942c64c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
6e9942c to
46e06c6
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 1 comment.
Reviewable status: 0 of 7 files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware and @liorgold2).
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 resolved 1 discussion.
Reviewable status: 0 of 7 files reviewed, all discussions resolved (waiting on @ilyalesokhin-starkware and @liorgold2).
46e06c6 to
40ff896
Compare
|
Suggestion: // Fix boxed_enum_ptr to account for the `inc_ap` above.
assert!(boxed_enum_ptr.apply_known_ap_change(1)); |
|
this also works, right? Suggestion: |
ilyalesokhin-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.
@ilyalesokhin-starkware reviewed 8 files and all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @liorgold2 and @orizi).
40ff896 to
d961458
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 @ilyalesokhin-starkware and @liorgold2).
tests/e2e_test_data/libfuncs/enum line 770 at r3 (raw file):
Previously, ilyalesokhin-starkware wrote…
this also works, right?
yes it does.
crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 471 at r3 (raw file):
}]; assert!(boxed_enum_ptr.apply_known_ap_change(1));
Done.
|
Previously, orizi wrote…
Lior said he prefers that syntax. |
728d02f to
ec182e0
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 1 comment.
Reviewable status: 7 of 8 files reviewed, 2 unresolved discussions (waiting on @ilyalesokhin-starkware and @liorgold2).
tests/e2e_test_data/libfuncs/enum line 770 at r3 (raw file):
Previously, ilyalesokhin-starkware wrote…
Lior said he prefers that syntax.
Done.
|
Why did the branch_align disappear? Code quote: |
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 1 comment.
Reviewable status: 6 of 8 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @liorgold2).
tests/e2e_test_data/libfuncs/enum line 862 at r1 (raw file):
Previously, ilyalesokhin-starkware wrote…
Why did the branch_align disappear?
lior's suggested change made this function not be considered as a branch on sierra-gen - so no branch-align was caused.
in general we may want to consider this for "single-branch-matches" but not for this PR.
ec182e0 to
94fce36
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 1 comment.
Reviewable status: 6 of 8 files reviewed, 3 unresolved discussions (waiting on @ilyalesokhin-starkware and @liorgold2).
tests/e2e_test_data/libfuncs/enum line 862 at r1 (raw file):
Previously, orizi wrote…
lior's suggested change made this function not be considered as a branch on sierra-gen - so no branch-align was caused.
in general we may want to consider this for "single-branch-matches" but not for this PR.
fixed underlying issue in another PR.
94fce36 to
ef10664
Compare
liorgold2
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.
@liorgold2 reviewed 3 files and all commit messages, and made 1 comment.
Reviewable status: 5 of 8 files reviewed, 4 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi).
tests/e2e_test_data/libfuncs/enum line 812 at r8 (raw file):
enum B { Value1: A, Value2: A,
Actually, let's have the second item larger, which will put the inner selectors in different locations due to padding. E.g.
enum B {
Value1: A,
Value2: (A, felt252, felt252)
liorgold2
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.
@liorgold2 reviewed 3 files and made 3 comments.
Reviewable status: 6 of 8 files reviewed, 7 unresolved discussions (waiting on @ilyalesokhin-starkware and @orizi).
crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs line 412 at r8 (raw file):
// plus the regular match cost - but only when branching is actually needed. let n = signature.branch_signatures.len(); match n {
Suggestion:
match signature.branch_signatures.len() {crates/cairo-lang-sierra/src/extensions/modules/enm.rs line 397 at r8 (raw file):
) -> Result<(Vec<ConcreteTypeId>, bool), SpecializationError> { let type_info = context.get_type_info(ty)?; let (inner_ty, is_snapshot) = peel_snapshot(ty, type_info)?;
There was a question whether it's ok to peel at most one snapshot. What happens with Box<@@T>?
crates/cairo-lang-sierra/src/extensions/modules/enm.rs line 461 at r8 (raw file):
context, enum_type.clone(), variants.iter().cloned(),
Is this efficient? Does it create an interator that clones all items when necessary?
Code quote:
variants.iter().cloned(),SIERRA_UPDATE_PATCH_CHANGE_TAG=Updating not yet allowed function.
ef10664 to
a64c3d3
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 4 comments.
Reviewable status: 6 of 8 files reviewed, 7 unresolved discussions (waiting on @ilyalesokhin-starkware and @liorgold2).
crates/cairo-lang-sierra/src/extensions/modules/enm.rs line 397 at r8 (raw file):
Previously, liorgold2 wrote…
There was a question whether it's ok to peel at most one snapshot. What happens with
Box<@@T>?
there's no such thing at the sierra level - there's either one or none.
crates/cairo-lang-sierra/src/extensions/modules/enm.rs line 461 at r8 (raw file):
Previously, liorgold2 wrote…
Is this efficient? Does it create an interator that clones all items when necessary?
it only clones on "next" calls - no cloning of the vector is performed.
tests/e2e_test_data/libfuncs/enum line 812 at r8 (raw file):
Previously, liorgold2 wrote…
Actually, let's have the second item larger, which will put the inner selectors in different locations due to padding. E.g.
enum B {
Value1: A,
Value2: (A, felt252, felt252)
Done.
crates/cairo-lang-sierra-gas/src/core_libfunc_cost_base.rs line 412 at r8 (raw file):
// plus the regular match cost - but only when branching is actually needed. let n = signature.branch_signatures.len(); match n {
Done.
ilyalesokhin-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.
@ilyalesokhin-starkware partially reviewed 3 files and resolved 3 discussions.
Reviewable status: 7 of 8 files reviewed, 4 unresolved discussions (waiting on @liorgold2).
liorgold2
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.
@liorgold2 partially reviewed 6 files and all commit messages, made 1 comment, and resolved 4 discussions.
Reviewable status: 7 of 8 files reviewed, 1 unresolved discussion (waiting on @orizi).
crates/cairo-lang-sierra-to-casm/src/invocations/enm.rs line 444 at r9 (raw file):
if num_branches == 1 { // The box should point to: base_addr + 1 (selector). let variant_box = CellExpression::add_with_const(boxed_enum_ptr, orig_offset + 1);
Consider checked\_add or explicitly checking orig_offset < ... before.
Code quote:
orig_offset + 1
liorgold2
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.
@liorgold2 reviewed 3 files.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi).
liorgold2
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.
@liorgold2 made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @orizi).

Summary
Improved the implementation of
enum_boxed_matchlibfunc to handle single-variant enums more efficiently. This PR fixes the code generation for boxed enum matching, particularly for the case of enums with a single variant where no branching is needed.Type of change
Please check one:
Why is this change needed?
The current implementation of
enum_boxed_matchwas not correctly handling single-variant enums. It was generating unnecessary code for the single-variant case, which should be a simple pass-through operation without branching logic.What was the behavior or documentation before?
Previously, the
enum_boxed_matchlibfunc was generating unnecessary code for single-variant enums, treating them similarly to multi-variant enums which require branching logic.What is the behavior or documentation after?
Now, for single-variant enums, the
enum_boxed_matchlibfunc generates simpler, more efficient code that directly returns the variant box without any branching. The implementation also includes better handling of offsets and cleaner code for the multi-variant cases.Additional context
Added several test cases to verify the correct behavior for single-variant and multi-variant boxed enum matching. The changes also include some refactoring to improve code clarity and maintainability, particularly in the utility functions for type handling.