@samitouri / QOS-React-2 / commits / ff855b1d34

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.

Joe Savona committed Mar 8, 2023 at 20:49 UTC ff855b1d3495e6c671ff08f2188fea134d4d9672
2 files changed +78
compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.expect.md new
+63
@@ -0,0 +1,63 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + let x = 0;
7 + const values = [];
8 + const y = props.a || props.b;
9 + values.push(y);
10 + if (props.c) {
11 + x = 1;
12 + }
13 + values.push(x);
14 + if (props.d) {
15 + x = 2;
16 + }
17 + values.push(x);
18 + return values;
19 +}
20 +
21 +```
22 +
23 +## Code
24 +
25 +```javascript
26 +function Component(props) {
27 + const $ = React.unstable_useMemoCache(4);
28 + const c_0 = $[0] !== props;
29 + let values;
30 + if (c_0) {
31 + values = [];
32 + const c_2 = $[2] !== props;
33 + let t0;
34 + if (c_2) {
35 + t0 = props.a || props.b;
36 + $[2] = props;
37 + $[3] = t0;
38 + } else {
39 + t0 = $[3];
40 + }
41 + const y = t0;
42 + values.push(y);
43 + let x$0 = x;
44 + if (props.c) {
45 + x = 1;
46 + }
47 +
48 + values.push(x$0);
49 + if (props.d) {
50 + x = 2;
51 + }
52 +
53 + values.push(x);
54 + $[0] = props;
55 + $[1] = values;
56 + } else {
57 + values = $[1];
58 + }
59 + return values;
60 +}
61 +
62 +```
63 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/_bug.ssa.js new
+15
@@ -0,0 +1,15 @@
1 +function Component(props) {
2 + let x = 0;
3 + const values = [];
4 + const y = props.a || props.b;
5 + values.push(y);
6 + if (props.c) {
7 + x = 1;
8 + }
9 + values.push(x);
10 + if (props.d) {
11 + x = 2;
12 + }
13 + values.push(x);
14 + return values;
15 +}