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): function inlining orphans calls #1747

Merged
merged 7 commits into from
Jun 21, 2023

Conversation

joss-aztec
Copy link
Contributor

@joss-aztec joss-aztec commented Jun 19, 2023

Description

Problem*

After inlining the following program:

use dep::std;

fn main(cond: bool) {
    let res = inner1(cond);
    std::println(res);
}

fn inner1(cond: bool) -> Field {
    inner2(cond)
}

fn inner2(cond: bool) -> Field {
    if cond { 1 } else { 2 }
}

it would incorrectly reduce to:

fn main f3 {
  b0(v0: u1):
    call println(v3)
    return 
}

This was happening because at the close of the call to inner1, the block mapping was inappropriately used for identifying the location of the "return terminator", thus the function builder was switching to b0, instead of continuing from the end of the last inlined function.

Summary*

Annotate the inlined location analogous to a "return terminator" by using the the current_block instead of a stale mapping.

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.

@joss-aztec joss-aztec requested a review from jfecher June 19, 2023 13:31
@joss-aztec joss-aztec marked this pull request as ready for review June 19, 2023 13:31
@joss-aztec
Copy link
Contributor Author

This PR in conjunction with #1749 fixes the test named 8_integration.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

Looks good, and good test.

I think we should change some wordings in the documentation though. Since blocks is not a 1 to 1 mapping as you mention lets remove mentions of this and update the docs accordingly.

@jfecher jfecher enabled auto-merge June 20, 2023 16:50
@jfecher jfecher added this pull request to the merge queue Jun 20, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jun 20, 2023
@joss-aztec joss-aztec added this pull request to the merge queue Jun 21, 2023
Merged via the queue into master with commit f30a90f Jun 21, 2023
@joss-aztec joss-aztec deleted the joss/fix-inlining branch June 21, 2023 07:43
This was referenced Jun 21, 2023
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.

2 participants