Sitelet https://github.com/starkware-libs/cairo/pull/10015
Skip to content

(opt): remove cancel_ops phase, subsumed by variable forwarding - #10015

Merged
eytan-starkware merged 1 commit into
mainfrom
eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding
Jun 8, 2026
Merged

eytan-starkware merged 1 commit into
mainfrom
eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding

Conversation

@eytan-starkware

Copy link
Copy Markdown
Contributor

Summary


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

⚠️ Note:
To keep maintainer workload sustainable, we generally do not accept PRs that
are only minor wording, grammar, formatting, or style changes.
Such PRs may be closed without detailed review.


Why is this change needed?


What was the behavior or documentation before?


What is the behavior or documentation after?


Related issue or discussion (if any)


Additional context

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal branch from 1c51736 to 2bd0ebc Compare May 31, 2026 12:58
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from e6124f2 to fc9cef2 Compare May 31, 2026 12:58

eytan-starkware commented May 31, 2026 •

Copy link
Copy Markdown
Contributor Author

@cursor

cursor Bot commented May 31, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes the compiler’s default lowering optimization pipeline for all code; behavior should be equivalent but any gap between the old pass and variable forwarding could affect generated IR/Sierra.

Overview
Removes the cancel_ops lowering optimization pass and relies on variable_forwarding instead, which already covers the same removable statements (struct construct/destructure, snap/desnap, etc.).

The default optimization pipeline no longer runs CancelOps (including the extra pass that ran after reboxing). OptimizationPhase::CancelOps and cancel_ops.rs are deleted; strategy.rs and const-folding / variable-forwarding test setups now use VariableForwarding where CancelOps was used.

Legacy cancel_ops snapshot tests remain wired through cancel_ops_test → VariableForwarding with a TODO to migrate them. Expected lowering, const-folding, profiling, and Starknet account contract artifacts are refreshed to match the slimmer pipeline.

Reviewed by Cursor Bugbot for commit dc87ae5. Bugbot is set up for automated code reviews on this repo. Configure here.

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 32 files and all commit messages, and made 3 comments.
Reviewable status: 32 of 46 files reviewed, 3 unresolved discussions (waiting on eytan-starkware, ilyalesokhin-starkware, and TomerStarkware).


crates/cairo-lang-lowering/src/optimizations/test_data/cancel_ops at r1 (raw file):
wire to forwarding.
move or delete in following PR.


crates/cairo-lang-semantic/src/expr/expansion_test_data/inline_macros line 272 at r1 (raw file):

 --> lib.cairo:6:1
take_ident!($)
^^^^^^^^^^^^^^

revert


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

store_temp<Box<felt252>>([20]) -> ([20]);
unbox<felt252>([20]) -> ([22]);
snapshot_take<Array<felt252>>([8]) -> ([23], [24]);

regression.

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 12 files.
Reviewable status: 44 of 46 files reviewed, 3 unresolved discussions (waiting on eytan-starkware, ilyalesokhin-starkware, and TomerStarkware).

@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal branch from 2bd0ebc to d1bd315 Compare June 1, 2026 12:18
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from fc9cef2 to 261a77a Compare June 1, 2026 12:18
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from 261a77a to 99bbc03 Compare June 1, 2026 12:20
@graphite-app
graphite-app Bot changed the base branch from eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal to graphite-base/10015 June 1, 2026 12:56

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eytan-starkware made 3 comments.
Reviewable status: 44 of 47 files reviewed, 3 unresolved discussions (waiting on ilyalesokhin-starkware, orizi, and TomerStarkware).


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

Previously, orizi wrote…

wire to forwarding.
move or delete in following PR.

Done.


crates/cairo-lang-semantic/src/expr/expansion_test_data/inline_macros line 272 at r1 (raw file):

Previously, orizi wrote…

revert

Done.


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

Previously, orizi wrote…

regression.

Yes. Acceptable no?

@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from 99bbc03 to 69e0cd4 Compare June 1, 2026 13:42
@eytan-starkware
eytan-starkware changed the base branch from graphite-base/10015 to eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal June 1, 2026 13:42

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 9 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware, ilyalesokhin-starkware, and TomerStarkware).


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

Previously, eytan-starkware wrote…

Yes. Acceptable no?

mostly depends on why this happens.

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eytan-starkware made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ilyalesokhin-starkware, orizi, and TomerStarkware).


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

Previously, orizi wrote…

mostly depends on why this happens.

I had claude check this, it is around how the removal cascading works (or doesn't in this case): For the fib_array case the producer is a lowering snapshot statement, which has two outputs (orig, snap). VF forwards the desnap consumers onto orig, which makes snap dead — but it can't DCE the snapshot statement because the other output (orig) is still live. A two-output op with one live output survives ordinary dead-code elimination. Sierra-gen then lowers that surviving statement to exactly what Ori flagged:

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

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: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware, ilyalesokhin-starkware, and TomerStarkware).


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

Previously, eytan-starkware wrote…

I had claude check this, it is around how the removal cascading works (or doesn't in this case): For the fib_array case the producer is a lowering snapshot statement, which has two outputs (orig, snap). VF forwards the desnap consumers onto orig, which makes snap dead — but it can't DCE the snapshot statement because the other output (orig) is still live. A two-output op with one live output survives ordinary dead-code elimination. Sierra-gen then lowers that surviving statement to exactly what Ori flagged:

it previously was removed by cancel ops?

@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal branch from 1e2cf54 to ed21f8d Compare June 7, 2026 11:52
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from 69e0cd4 to aa346da Compare June 7, 2026 11:52
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from aa346da to 4e59c47 Compare June 7, 2026 11:52
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal branch from ed21f8d to 286b3d4 Compare June 7, 2026 11:52
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from 4e59c47 to ade0cef Compare June 7, 2026 11:56
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal branch 2 times, most recently from 1292dc5 to ee2b6a5 Compare June 7, 2026 13:43
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from ade0cef to 36cf5df Compare June 7, 2026 13:43
@graphite-app
graphite-app Bot changed the base branch from eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal to graphite-base/10015 June 7, 2026 14:17
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from 36cf5df to c5e773d Compare June 8, 2026 06:27
@eytan-starkware
eytan-starkware changed the base branch from graphite-base/10015 to eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal June 8, 2026 06:27

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 3 files and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware, ilyalesokhin-starkware, and TomerStarkware).

@graphite-app
graphite-app Bot changed the base branch from eytan_graphite/_optimization_non-copy_variable_forwarding_with_chain_removal to main June 8, 2026 07:22
@eytan-starkware
eytan-starkware force-pushed the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch from c5e773d to dc87ae5 Compare June 8, 2026 07:22
@graphite-app

graphite-app Bot commented Jun 8, 2026

Copy link
Copy Markdown

Merge activity

  • Jun 8, 7:23 AM UTC: Graphite rebased this pull request, because this pull request is set to merge when ready.

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eytan-starkware made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ilyalesokhin-starkware, orizi, and TomerStarkware).


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

Previously, orizi wrote…

it previously was removed by cancel ops?

Yes

@eytan-starkware eytan-starkware left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@eytan-starkware made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ilyalesokhin-starkware, orizi, and TomerStarkware).


tests/test_data/fib_array.sierra line 114 at r1 (raw file):

Previously, eytan-starkware wrote…

Yes

Though only in combination with VF. Apperantly before VF it didn't

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@orizi made 1 comment and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on ilyalesokhin-starkware and TomerStarkware).

@eytan-starkware
eytan-starkware added this pull request to the merge queue Jun 8, 2026
Merged via the queue into main with commit b03aa6f Jun 8, 2026
54 checks passed
@eytan-starkware
eytan-starkware deleted the eytan_graphite/_opt_remove_cancel_ops_phase_subsumed_by_variable_forwarding branch June 8, 2026 13:30
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