fix(ssa refactor): Reset condition value during flattening pass #1811
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves #1792 / #1806
Summary*
When flattening the cfg there is an optimization to set the value of an
if
's condition to a constanttrue
/false
within the then/else branch respectively since there is no other way to get to these branches without this being true.This means for code such as:
We can optimize it to:
Since we know
c
is always true within the then branch. This allows us to remove this particularconstrain
entirely afterward.The problem in #1792 arised when we forgot to reset the condition
c
back toc
, so even after the if ended we still hadc = true
orc = false
in the context. This PR fixes this by simply resettingc
to its old value after finishing an if statement.There is another, related fix in this PR that we now avoid setting
c = true
orc = false
ifc
is already a known constant. If this happened, we could be settingtrue = false
orfalse = true
which would not be good.Documentation
This PR requires documentation updates when merged.
Additional Context
PR Checklist*
cargo fmt
on default settings.