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

BUG-2199 + EAS-2222: Fix for the FSRT Multiple Definitions for Same Variable Bug #50

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

swathiatgit
Copy link

@swathiatgit swathiatgit commented Aug 6, 2024

FSRT should be in “static single assignment form”, i.e. there should be exactly one definition of each variable, as this simplifies later analysis. This PR fixes this bug with mutable iteration over the created environment, and ensures that every variable has one definition.

More on the bug: Take this code example below:

function foo(a) {
  let b = a - 20;
  let c = b + 1;
  b = 10;
  return b * 10;
}

The above function currently gives this IR:

Variables:
%0: return value
%1: local definition of b
%2: local definition of c
%3: local definition of b
%4: local definition of b
%5: global ref to a
%6: temporary
%7: global ref to b
%8: temporary
%9: global ref to c
%10: temporary
bb0:
    %6 = %5 - 20
    %7 = %6 
    %8 = %7 + 1
    %9 = %8
    %7 = 10 // second assignment of %7
    _ = 10
    %10 = %7 * 10
    %0 = %10
    return

Note that in the current output of our IR that every “use” of the variable %7 only needs to consider the definition of “%7 = 10”. Thus, we can replace the assignment “%7 = 10” with “%11 = 10” and all following uses of “%7” with the new variable “%11”.

Copy link

Thank you for your submission! Like many open source projects, we ask that you sign our CLA (Contributor License Agreement) before we can accept your contribution.
If your email is listed below, please ensure that you sign the CLA with the same email address.

The following users still need to sign our CLA:
[email protected]

Already signed the CLA? To re-check, try refreshing the page.

crates/forge_analyzer/src/definitions.rs Outdated Show resolved Hide resolved
crates/forge_analyzer/src/definitions.rs Outdated Show resolved Hide resolved
crates/forge_analyzer/src/definitions.rs Show resolved Hide resolved
crates/forge_analyzer/src/definitions.rs Outdated Show resolved Hide resolved
crates/forge_analyzer/src/definitions.rs Outdated Show resolved Hide resolved
crates/forge_analyzer/src/definitions.rs Outdated Show resolved Hide resolved
crates/forge_analyzer/src/definitions.rs Outdated Show resolved Hide resolved
@swathiatgit swathiatgit requested a review from jwong101 August 15, 2024 15:58
Copy link
Contributor

@jwong101 jwong101 left a comment

Choose a reason for hiding this comment

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

Lgtm. Once you rebase/cleanup your commits I'll merge it in.

@jwong101 jwong101 merged commit 636c2b6 into atlassian-labs:main Aug 19, 2024
3 checks passed
@swathiatgit swathiatgit deleted the swathi/2222 branch August 28, 2024 03:49
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