Skip to content
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

fix(ssa refactor): Fix ssa-gen of nested ifs #1406

Merged
merged 1 commit into from
May 25, 2023
Merged

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented May 25, 2023

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.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher jfecher changed the title Fix ssa-gen of nested ifs fix(ssa refactor): Fix ssa-gen of nested ifs May 25, 2023
@kevaundray kevaundray added this pull request to the merge queue May 25, 2023
Merged via the queue into master with commit 5fd976e May 25, 2023
@kevaundray kevaundray deleted the jf/fix-nested-ifs branch May 25, 2023 23:24
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.

Compiler crash when compiling nested if expressions with --experimental-ssa flag
2 participants