-
Notifications
You must be signed in to change notification settings - Fork 97
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
Mutable variables in dynamic branches prevent full constant folding in partial evaluation #2087
Labels
bug
Something isn't working
Comments
swernli
added a commit
that referenced
this issue
Jan 4, 2025
…n partial evaluation This fixes the bug by having partial evaluation more explicitly track different variable mappings to literals across branches and recombining those mappings that match (ie: are constant) when all branches are done. This also includes partial eval and RIR SSA pass fixes to correctly support immutable and mutable copies of dynamic variables. New test cases for several combinations of constant folding at partial eval are included, as well as a new test case confirming RIR SSA fix. Fixes #2087
swernli
added a commit
that referenced
this issue
Jan 4, 2025
…n partial evaluation This fixes the bug by having partial evaluation more explicitly track different variable mappings to literals across branches and recombining those mappings that match (ie: are constant) when all branches are done. This also includes partial eval and RIR SSA pass fixes to correctly support immutable and mutable copies of dynamic variables. New test cases for several combinations of constant folding at partial eval are included, as well as a new test case confirming RIR SSA fix. Fixes #2087
This was referenced Jan 7, 2025
github-merge-queue bot
pushed a commit
that referenced
this issue
Jan 9, 2025
…n partial evaluation (#2089) This fixes the bug by having partial evaluation more explicitly track different variable mappings to literals across branches and recombining those mappings that match (ie: are constant) when all branches are done. This also includes partial eval and RIR SSA pass fixes to correctly support immutable and mutable copies of dynamic variables. New test cases for several combinations of constant folding at partial eval are included, as well as a new test case confirming RIR SSA fix. Fixes #2087
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given a mutable variable used in a quantum condition block, partial eval can't track that despite
value
being in a dynamic condition, it is statically constant.This leads to a variable being used in the CFG for the else block, which is converted into a constant during SSA transformation. This leaves SSA instructions performing mathematical computation on constant values.
This currently causes a panic in the compiler which assumes all constant operations were resolved during partial evaluation.
Actual:
In SSA processing:
Is turned into:
Which causes the panic. Given that partial evaluation can't fully perform constant folding, we most likely need to implement more SSA passes for constant folding, dead code elimination, at a minimum.
Workaround:
Save off the current
mut
value and use it on the rhs of the expressions in the conditional blocks:The text was updated successfully, but these errors were encountered: