From ff855b1d3495e6c671ff08f2188fea134d4d9672 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Wed, 8 Mar 2023 20:49:28 -0800 Subject: [PATCH] Repro case for product bug Simplified version of the example. As I eventually uncovered in #1342, the issue is cascading redundant phis not getting rewritten. --- .../__tests__/fixtures/hir/_bug.ssa.expect.md | 63 +++++++++++++++++++ .../src/__tests__/fixtures/hir/_bug.ssa.js | 15 +++++ 2 files changed, 78 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.js diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.expect.md b/compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.expect.md new file mode 100644 index 0000000000000..5dd7d9f93dfa8 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.expect.md @@ -0,0 +1,63 @@ + +## Input + +```javascript +function Component(props) { + let x = 0; + const values = []; + const y = props.a || props.b; + values.push(y); + if (props.c) { + x = 1; + } + values.push(x); + if (props.d) { + x = 2; + } + values.push(x); + return values; +} + +``` + +## Code + +```javascript +function Component(props) { + const $ = React.unstable_useMemoCache(4); + const c_0 = $[0] !== props; + let values; + if (c_0) { + values = []; + const c_2 = $[2] !== props; + let t0; + if (c_2) { + t0 = props.a || props.b; + $[2] = props; + $[3] = t0; + } else { + t0 = $[3]; + } + const y = t0; + values.push(y); + let x$0 = x; + if (props.c) { + x = 1; + } + + values.push(x$0); + if (props.d) { + x = 2; + } + + values.push(x); + $[0] = props; + $[1] = values; + } else { + values = $[1]; + } + return values; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.js b/compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.js new file mode 100644 index 0000000000000..780282f157082 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.js @@ -0,0 +1,15 @@ +function Component(props) { + let x = 0; + const values = []; + const y = props.a || props.b; + values.push(y); + if (props.c) { + x = 1; + } + values.push(x); + if (props.d) { + x = 2; + } + values.push(x); + return values; +}