Skip to content

Const-fold non-empty span pops#9752

Open
odupontt wants to merge 3 commits intostarkware-libs:mainfrom
odupontt:spanpops
Open

Const-fold non-empty span pops#9752
odupontt wants to merge 3 commits intostarkware-libs:mainfrom
odupontt:spanpops

Conversation

@odupontt
Copy link
Copy Markdown
Contributor

@odupontt odupontt commented Mar 18, 2026

This completes the existing const-folding for snapshot pops by propagating the success values of span.pop_front() and span.pop_back() when the span is known to be non-empty. The empty case was already optimized and the original implementation left an explicit TODO for the success path, so this change closes a real gap rather than introducing new behavior. Regression tests were added for both non-empty cases.


Note

Medium Risk
Changes const-folding control-flow rewriting for array_snapshot_pop_front/back success paths, which can affect generated lowering and requires correct materialization of tracked values and snapshot/boxing semantics. Scope is localized to the lowering optimizer and covered by new regression tests.

Overview
Extends const-folding for span.pop_front()/span.pop_back() when the span is known non-empty, rewriting the match to jump directly to the Some arm while also propagating both the remaining span and the popped element.

Adds try_materialize_var_info to synthesize the necessary lowered statements (consts, snapshots, struct/enum construction, boxing, and array rebuild via array_new/array_append) when the optimizer needs real variables for tracked VarInfo values. Updates lowering test data with new regression cases for the non-empty pop_front and pop_back optimizations.

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

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.

2 participants