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

Compiler Logical Negation Constant Propagation #29622

Closed
nikeee opened this issue May 28, 2024 · 0 comments · Fixed by #29623
Closed

Compiler Logical Negation Constant Propagation #29622

nikeee opened this issue May 28, 2024 · 0 comments · Fixed by #29623

Comments

@nikeee
Copy link
Contributor

nikeee commented May 28, 2024

Consider the following constant propagation:

Input:

function foo() {
  const b = true;
  if (!b) {
    console.log("bar");
  } else {
    console.log("baz");
  }

  return {
    b0: !true,
    n0: !0,
    n1: !1,
    n2: !2,
    s0: !"",
    s1: !"a",
    s2: !"ab",
    n: !null,
  };
}

Output:

function foo() {
  console.log("baz");
  return {
    b0: false,
    n0: true,
    n1: false,
    n2: false,
    s0: true,
    s1: false,
    s2: false,
    n: true,
  };
}

I think it can benefit dead code elimination. Is this in scope for the react compiler or is this considered as the job of the bundler? If so, is it open for contributions?

nikeee added a commit to nikeee/react that referenced this issue May 28, 2024
nikeee added a commit to nikeee/react that referenced this issue May 28, 2024
nikeee added a commit to nikeee/react that referenced this issue May 28, 2024
nikeee added a commit to nikeee/react that referenced this issue May 29, 2024
josephsavona pushed a commit that referenced this issue May 29, 2024
## Summary

Resolves #29622

## How did you test this change?
I verified the implementation using the test.

Note:
This PR was done without waiting for approval in #29622, so feel free to
just close it.
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 a pull request may close this issue.

1 participant