Skip to content

bugfix(lowering): propagate snapshot pop success values#9783

Open
jcastil0 wants to merge 3 commits intostarkware-libs:mainfrom
jcastil0:lowering-snapshot-pop-success-values
Open

bugfix(lowering): propagate snapshot pop success values#9783
jcastil0 wants to merge 3 commits intostarkware-libs:mainfrom
jcastil0:lowering-snapshot-pop-success-values

Conversation

@jcastil0
Copy link
Copy Markdown
Contributor

@jcastil0 jcastil0 commented Mar 25, 2026

Summary

Propagate known values through array_snapshot_pop_front and array_snapshot_pop_back on the success path during const folding, so later lowering passes can keep folding the remaining snapshot array and the popped boxed snapshot.


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?

Const folding already tracks empty array_snapshot_pop_front / array_snapshot_pop_back cases, but it drops the known values on the non-empty success path.

As a result, later lowering optimization cannot keep folding operations that consume the remaining snapshot array or the popped element, even when both are fully known at compile time.


What was the behavior or documentation before?

For known non-empty snapshot arrays, const folding did not propagate the success outputs of array_snapshot_pop_front and array_snapshot_pop_back.

The empty path kept shape information, but the success path lost it.


What is the behavior or documentation after?

For known non-empty snapshot arrays, const folding now propagates:

  • the remaining snapshot array to the first success output
  • the popped element as Box<@T> to the second success output

Related issue or discussion (if any)


Additional context

This change stays within lowering const-folding and adds focused tests for both array_snapshot_pop_front and array_snapshot_pop_back success paths.


Note

Medium Risk
Touches lowering const-folding logic for array_snapshot_pop_front/back, which can affect compile-time evaluation and downstream optimizations if the propagated VarInfo is wrong, but scope is limited to these two libfuncs.

Overview
Const folding now propagates the success-path outputs of array_snapshot_pop_front/array_snapshot_pop_back: it tracks the remaining snapshot array and the popped element (as Box<@T>), instead of dropping this information on non-empty arrays.

Adds focused optimizer test cases asserting that these propagated values enable further folding (e.g., folding two pops on a known [1, 2] snapshot to a constant result).

Written by Cursor Bugbot for commit 1db7cc2. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
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 made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on jcastil0).


crates/cairo-lang-lowering/src/optimizations/const_folding_test.rs line 90 at r1 (raw file):

}

fn alloc_var<'db>(

add a test in the const_folding test file - not a specialized test for your case.

@jcastil0
Copy link
Copy Markdown
Contributor Author

@orizi made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on jcastil0).

crates/cairo-lang-lowering/src/optimizations/const_folding_test.rs line 90 at r1 (raw file):

}

fn alloc_var<'db>(

add a test in the const_folding test file - not a specialized test for your case.

Moved it into the shared const_folding test file and dropped the specialized test.

@orizi made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on jcastil0).

crates/cairo-lang-lowering/src/optimizations/const_folding_test.rs line 90 at r1 (raw file):

}

fn alloc_var<'db>(

add a test in the const_folding test file - not a specialized test for your case.

@orizi Hi
Moved it into the shared const_folding test file and dropped the specialized test.

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