Skip to content

Conversation

@eytan-starkware
Copy link
Contributor

@eytan-starkware eytan-starkware commented Dec 8, 2025

Enable reboxing optimization for snapshotted structs.

This PR extends the reboxing optimization to support structs wrapped in snapshots. Previously, the optimization would skip any struct that had snapshots, as indicated by the removed code that checked for n_snapshots > 0. Now, the optimization properly handles snapshots by:

  1. Importing wrap_in_snapshots from the semantic types module
  2. Applying the appropriate number of snapshots to member types when deconstructing boxed structs
  3. Removing the early return that skipped snapshotted structs

The PR also adds test cases for reboxing with snapshots.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

eytan-starkware commented Dec 8, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

@ilyalesokhin-starkware reviewed 4 of 4 files at r1.
Reviewable status: all files reviewed (commit messages unreviewed), all discussions resolved (waiting on @giladchase and @orizi)

Copy link
Collaborator

@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.

@orizi reviewed 3 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @eytan-starkware and @giladchase)


crates/cairo-lang-lowering/src/optimizations/test_data/reboxing line 813 at r1 (raw file):

    let member_a = unboxed.a;
    (BoxTrait::new(member_a), unboxed.non_drop)
}

Suggestion:

fn main(a: Box<@A>) -> (Box<@felt252>, @NonDrop) {
    (BoxTrait::new(a.a), a.non_drop)
}

@eytan-starkware eytan-starkware changed the base branch from eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc to graphite-base/8954 December 8, 2025 13:07
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_reboxing_also_applied_on_box_of_snapshots branch from 48105ae to ad75ba7 Compare December 8, 2025 13:34
@eytan-starkware eytan-starkware changed the base branch from graphite-base/8954 to eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc December 8, 2025 13:34
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_reboxing_also_applied_on_box_of_snapshots branch from ad75ba7 to 2326263 Compare December 8, 2025 13:44
Copy link
Collaborator

@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.

@orizi reviewed 4 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @eytan-starkware and @giladchase)

Copy link
Contributor Author

@eytan-starkware eytan-starkware 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: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @giladchase, @ilyalesokhin-starkware, and @orizi)


crates/cairo-lang-lowering/src/optimizations/test_data/reboxing line 813 at r1 (raw file):

    let member_a = unboxed.a;
    (BoxTrait::new(member_a), unboxed.non_drop)
}

Done.

Copy link
Collaborator

@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.

:lgtm:

@orizi reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_reboxing_also_applied_on_box_of_snapshots branch from 2326263 to ef335a5 Compare December 9, 2025 10:06
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc branch from 0a0e49c to f7f38b9 Compare December 9, 2025 10:06
Copy link
Contributor

@ilyalesokhin-starkware ilyalesokhin-starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@ilyalesokhin-starkware reviewed all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc branch from f7f38b9 to f373f7d Compare December 10, 2025 08:42
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_reboxing_also_applied_on_box_of_snapshots branch from ef335a5 to 630ce29 Compare December 10, 2025 08:42
@eytan-starkware eytan-starkware changed the base branch from eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc to graphite-base/8954 December 10, 2025 10:31
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_reboxing_also_applied_on_box_of_snapshots branch from 630ce29 to 1dd5922 Compare December 10, 2025 10:32
@eytan-starkware eytan-starkware changed the base branch from graphite-base/8954 to eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc December 10, 2025 10:32
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_automatically_detecting_reboxing_of_struct_member_and_applying_struct_box_deconstruct_libfunc branch from cc5f6b4 to 04c6b94 Compare December 10, 2025 12:08
@eytan-starkware eytan-starkware force-pushed the eytan_graphite/_optimization_reboxing_also_applied_on_box_of_snapshots branch from 1dd5922 to 2e496a0 Compare December 10, 2025 12:08
Copy link
Collaborator

@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.

@orizi reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @giladchase)

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.

5 participants