Add new test cases for SSA
Add these as a separate commit so we can see how later PRs in the stack change them
Lauren Tan committed
Feb 8, 2023 at 10:26 UTC
1809ffd06d4b37f1012284c6cc19558e1f74ced5
6 files changed
+220
compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.expect.md
new
+68
@@ -0,0 +1,68 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function Component(props) {
6
+ let x = [];
7
+ let y;
8
+ if (props.p0) {
9
+ x.push(props.p1);
10
+ y = x;
11
+ }
12
+ return (
13
+ <Component>
14
+ {x}
15
+ {y}
16
+ </Component>
17
+ );
18
+}
19
+
20
+```
21
+
22
+## Code
23
+
24
+```javascript
25
+function Component(props) {
26
+ const $ = React.unstable_useMemoCache();
27
+ const c_0 = $[0] !== props.p0;
28
+ const c_1 = $[1] !== props.p1;
29
+ let x;
30
+ let y$0;
31
+ if (c_0 || c_1) {
32
+ x = [];
33
+ const y = undefined;
34
+ y$0 = y;
35
+ if (props.p0) {
36
+ x.push(props.p1);
37
+ const y$1 = x;
38
+ y$0 = y$1;
39
+ }
40
+ $[0] = props.p0;
41
+ $[1] = props.p1;
42
+ $[2] = x;
43
+ $[3] = y$0;
44
+ } else {
45
+ x = $[2];
46
+ y$0 = $[3];
47
+ }
48
+ const c_4 = $[4] !== x;
49
+ const c_5 = $[5] !== y$0;
50
+ let t0;
51
+ if (c_4 || c_5) {
52
+ t0 = (
53
+ <Component>
54
+ {x}
55
+ {y$0}
56
+ </Component>
57
+ );
58
+ $[4] = x;
59
+ $[5] = y$0;
60
+ $[6] = t0;
61
+ } else {
62
+ t0 = $[6];
63
+ }
64
+ return t0;
65
+}
66
+
67
+```
68
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.js
new
+14
@@ -0,0 +1,14 @@
1
+function Component(props) {
2
+ let x = [];
3
+ let y;
4
+ if (props.p0) {
5
+ x.push(props.p1);
6
+ y = x;
7
+ }
8
+ return (
9
+ <Component>
10
+ {x}
11
+ {y}
12
+ </Component>
13
+ );
14
+}
compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.expect.md
new
+56
@@ -0,0 +1,56 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function foo(props) {
6
+ let x = [];
7
+ x.push(props.bar);
8
+ if (props.cond) {
9
+ x = {};
10
+ x = [];
11
+ x.push(props.foo);
12
+ }
13
+ mut(x);
14
+ return x;
15
+}
16
+
17
+```
18
+
19
+## Code
20
+
21
+```javascript
22
+function foo(props) {
23
+ const $ = React.unstable_useMemoCache();
24
+ const c_0 = $[0] !== props.bar;
25
+ let x;
26
+ if (c_0) {
27
+ x = [];
28
+ x.push(props.bar);
29
+ $[0] = props.bar;
30
+ $[1] = x;
31
+ } else {
32
+ x = $[1];
33
+ }
34
+ const c_2 = $[2] !== props.cond;
35
+ const c_3 = $[3] !== props.foo;
36
+ let x$0;
37
+ if (c_2 || c_3) {
38
+ x$0 = x;
39
+ if (props.cond) {
40
+ const x$1 = [];
41
+ x$1.push(props.foo);
42
+ x$0 = x$1;
43
+ }
44
+
45
+ mut(x$0);
46
+ $[2] = props.cond;
47
+ $[3] = props.foo;
48
+ $[4] = x$0;
49
+ } else {
50
+ x$0 = $[4];
51
+ }
52
+ return x$0;
53
+}
54
+
55
+```
56
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.js
new
+11
@@ -0,0 +1,11 @@
1
+function foo(props) {
2
+ let x = [];
3
+ x.push(props.bar);
4
+ if (props.cond) {
5
+ x = {};
6
+ x = [];
7
+ x.push(props.foo);
8
+ }
9
+ mut(x);
10
+ return x;
11
+}
compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.expect.md
new
+61
@@ -0,0 +1,61 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function foo(props) {
6
+ let x = [];
7
+ x.push(props.bar);
8
+ if (props.cond) {
9
+ x = {};
10
+ x = [];
11
+ x.push(props.foo);
12
+ }
13
+ return x;
14
+}
15
+
16
+```
17
+
18
+## Code
19
+
20
+```javascript
21
+function foo(props) {
22
+ const $ = React.unstable_useMemoCache();
23
+ const c_0 = $[0] !== props.bar;
24
+ let x;
25
+ if (c_0) {
26
+ x = [];
27
+ x.push(props.bar);
28
+ $[0] = props.bar;
29
+ $[1] = x;
30
+ } else {
31
+ x = $[1];
32
+ }
33
+ const c_2 = $[2] !== props.cond;
34
+ const c_3 = $[3] !== props.foo;
35
+ let x$0;
36
+ if (c_2 || c_3) {
37
+ x$0 = x;
38
+ if (props.cond) {
39
+ const c_5 = $[5] !== props.foo;
40
+ let x$1;
41
+ if (c_5) {
42
+ x$1 = [];
43
+ x$1.push(props.foo);
44
+ $[5] = props.foo;
45
+ $[6] = x$1;
46
+ } else {
47
+ x$1 = $[6];
48
+ }
49
+ x$0 = x$1;
50
+ }
51
+ $[2] = props.cond;
52
+ $[3] = props.foo;
53
+ $[4] = x$0;
54
+ } else {
55
+ x$0 = $[4];
56
+ }
57
+ return x$0;
58
+}
59
+
60
+```
61
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.js
new
+10
@@ -0,0 +1,10 @@
1
+function foo(props) {
2
+ let x = [];
3
+ x.push(props.bar);
4
+ if (props.cond) {
5
+ x = {};
6
+ x = [];
7
+ x.push(props.foo);
8
+ }
9
+ return x;
10
+}