fix(ssa refactor): Fix ssa-gen of nested ifs #1406
Merged
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*
Fixes a problem where the experimental ssa IR would crash while compiling nested if statements.
Although the crash was during function inlining, the error was actually the ssa-gen pass generated malformed SSA IR that was later given as input to inlining. The issue was when codegening if statements we would compile the then branch, then switch to compile the else branch, then switch back to the then branch to set its terminator. This is invalid if the then branch itself contains several blocks as we'd be setting the terminator of the first block rather than the final block. This caused nested if statements to be essentially erased from the program, but it was still possible to refer to their block arguments from blocks that are unreachable, which triggers the assert during function inlining.
Resolves #1392
Summary*
The fix is to change the ordering of ssa-gen for if statements slightly to terminate the then branch before switching to the else branch so that we do not need to switch back.
Documentation
This PR requires documentation updates when merged.
Additional Context
PR Checklist*
cargo fmt
on default settings.