@samitouri / QOS-React-2 / commits / 0e1bba87ea

[be][cleanup] Split primitive tests to individual fixtures

Followup to #1273 No changes, just moving test functions to their own fixture files.

mofeiZ committed Mar 6, 2023 at 18:25 UTC 0e1bba87ea9d8469468e4aec0ba5445bdb0f6427
8 files changed +174 -127
compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep-nested-scope.expect.md new
+79
@@ -0,0 +1,79 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// bar(props.b) is an allocating expression that produces a primitive, which means
6 +// that Forget should memoize it.
7 +// Correctness:
8 +// - y depends on either bar(props.b) or bar(props.b) + 1
9 +function AllocatingPrimitiveAsDepNested(props) {
10 + let x = {};
11 + mutate(x);
12 + let y = foo(bar(props.b) + 1);
13 + mutate(x, props.a);
14 + return [x, y];
15 +}
16 +
17 +```
18 +
19 +## Code
20 +
21 +```javascript
22 +// bar(props.b) is an allocating expression that produces a primitive, which means
23 +// that Forget should memoize it.
24 +// Correctness:
25 +// - y depends on either bar(props.b) or bar(props.b) + 1
26 +function AllocatingPrimitiveAsDepNested(props) {
27 + const $ = React.unstable_useMemoCache(11);
28 + const c_0 = $[0] !== props.b;
29 + const c_1 = $[1] !== props.a;
30 + let x;
31 + let y;
32 + if (c_0 || c_1) {
33 + x = {};
34 + mutate(x);
35 + const c_4 = $[4] !== props.b;
36 + let t0;
37 + if (c_4) {
38 + t0 = bar(props.b);
39 + $[4] = props.b;
40 + $[5] = t0;
41 + } else {
42 + t0 = $[5];
43 + }
44 + const t1 = t0 + 1;
45 + const c_6 = $[6] !== t1;
46 + let t2;
47 + if (c_6) {
48 + t2 = foo(t1);
49 + $[6] = t1;
50 + $[7] = t2;
51 + } else {
52 + t2 = $[7];
53 + }
54 + y = t2;
55 + mutate(x, props.a);
56 + $[0] = props.b;
57 + $[1] = props.a;
58 + $[2] = x;
59 + $[3] = y;
60 + } else {
61 + x = $[2];
62 + y = $[3];
63 + }
64 + const c_8 = $[8] !== x;
65 + const c_9 = $[9] !== y;
66 + let t3;
67 + if (c_8 || c_9) {
68 + t3 = [x, y];
69 + $[8] = x;
70 + $[9] = y;
71 + $[10] = t3;
72 + } else {
73 + t3 = $[10];
74 + }
75 + return t3;
76 +}
77 +
78 +```
79 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep-nested-scope.js new
+11
@@ -0,0 +1,11 @@
1 +// bar(props.b) is an allocating expression that produces a primitive, which means
2 +// that Forget should memoize it.
3 +// Correctness:
4 +// - y depends on either bar(props.b) or bar(props.b) + 1
5 +function AllocatingPrimitiveAsDepNested(props) {
6 + let x = {};
7 + mutate(x);
8 + let y = foo(bar(props.b) + 1);
9 + mutate(x, props.a);
10 + return [x, y];
11 +}
compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep.expect.md
-60
@@ -11,14 +11,6 @@ function AllocatingPrimitiveAsDep(props) {
11 return y;
12 }
13
14 -function PrimitiveAsDepNested(props) {
15 - let x = {};
16 - mutate(x);
17 - let y = foo(bar(props.b) + 1);
18 - mutate(x, props.a);
19 - return [x, y];
20 -}
21 -
14 ```
15
16 ## Code
@@ -53,57 +45,5 @@ function AllocatingPrimitiveAsDep(props) {
45 return y;
46 }
47
56 -function PrimitiveAsDepNested(props) {
57 - const $ = React.unstable_useMemoCache(11);
58 - const c_0 = $[0] !== props.b;
59 - const c_1 = $[1] !== props.a;
60 - let x;
61 - let y;
62 - if (c_0 || c_1) {
63 - x = {};
64 - mutate(x);
65 - const c_4 = $[4] !== props.b;
66 - let t0;
67 - if (c_4) {
68 - t0 = bar(props.b);
69 - $[4] = props.b;
70 - $[5] = t0;
71 - } else {
72 - t0 = $[5];
73 - }
74 - const t1 = t0 + 1;
75 - const c_6 = $[6] !== t1;
76 - let t2;
77 - if (c_6) {
78 - t2 = foo(t1);
79 - $[6] = t1;
80 - $[7] = t2;
81 - } else {
82 - t2 = $[7];
83 - }
84 - y = t2;
85 - mutate(x, props.a);
86 - $[0] = props.b;
87 - $[1] = props.a;
88 - $[2] = x;
89 - $[3] = y;
90 - } else {
91 - x = $[2];
92 - y = $[3];
93 - }
94 - const c_8 = $[8] !== x;
95 - const c_9 = $[9] !== y;
96 - let t3;
97 - if (c_8 || c_9) {
98 - t3 = [x, y];
99 - $[8] = x;
100 - $[9] = y;
101 - $[10] = t3;
102 - } else {
103 - t3 = $[10];
104 - }
105 - return t3;
106 -}
107 -
48 ```
49
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/allocating-primitive-as-dep.js
-8
@@ -6,11 +6,3 @@ function AllocatingPrimitiveAsDep(props) {
6 let y = foo(bar(props).b + 1);
7 return y;
8 }
9 -
10 -function PrimitiveAsDepNested(props) {
11 - let x = {};
12 - mutate(x);
13 - let y = foo(bar(props.b) + 1);
14 - mutate(x, props.a);
15 - return [x, y];
16 -}
compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep-nested-scope.expect.md new
+72
@@ -0,0 +1,72 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// props.b + 1 is an non-allocating expression, which means Forget can
6 +// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
7 +// separately from props.b)
8 +// Correctness:
9 +// y depends on either props.b or props.b + 1
10 +function PrimitiveAsDepNested(props) {
11 + let x = {};
12 + mutate(x);
13 + let y = foo(props.b + 1);
14 + mutate(x, props.a);
15 + return [x, y];
16 +}
17 +
18 +```
19 +
20 +## Code
21 +
22 +```javascript
23 +// props.b + 1 is an non-allocating expression, which means Forget can
24 +// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
25 +// separately from props.b)
26 +// Correctness:
27 +// y depends on either props.b or props.b + 1
28 +function PrimitiveAsDepNested(props) {
29 + const $ = React.unstable_useMemoCache(9);
30 + const c_0 = $[0] !== props.b;
31 + const c_1 = $[1] !== props.a;
32 + let x;
33 + let y;
34 + if (c_0 || c_1) {
35 + x = {};
36 + mutate(x);
37 + const t0 = props.b + 1;
38 + const c_4 = $[4] !== t0;
39 + let t1;
40 + if (c_4) {
41 + t1 = foo(t0);
42 + $[4] = t0;
43 + $[5] = t1;
44 + } else {
45 + t1 = $[5];
46 + }
47 + y = t1;
48 + mutate(x, props.a);
49 + $[0] = props.b;
50 + $[1] = props.a;
51 + $[2] = x;
52 + $[3] = y;
53 + } else {
54 + x = $[2];
55 + y = $[3];
56 + }
57 + const c_6 = $[6] !== x;
58 + const c_7 = $[7] !== y;
59 + let t2;
60 + if (c_6 || c_7) {
61 + t2 = [x, y];
62 + $[6] = x;
63 + $[7] = y;
64 + $[8] = t2;
65 + } else {
66 + t2 = $[8];
67 + }
68 + return t2;
69 +}
70 +
71 +```
72 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep-nested-scope.js new
+12
@@ -0,0 +1,12 @@
1 +// props.b + 1 is an non-allocating expression, which means Forget can
2 +// emit it trivially and repeatedly (e.g. no need to memoize props.b + 1
3 +// separately from props.b)
4 +// Correctness:
5 +// y depends on either props.b or props.b + 1
6 +function PrimitiveAsDepNested(props) {
7 + let x = {};
8 + mutate(x);
9 + let y = foo(props.b + 1);
10 + mutate(x, props.a);
11 + return [x, y];
12 +}
compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep.expect.md
-51
@@ -12,14 +12,6 @@ function PrimitiveAsDep(props) {
12 return y;
13 }
14
15 -function PrimitiveAsDepNested(props) {
16 - let x = {};
17 - mutate(x);
18 - let y = foo(props.b + 1);
19 - mutate(x, props.a);
20 - return [x, y];
21 -}
22 -
15 ```
16
17 ## Code
@@ -46,48 +38,5 @@ function PrimitiveAsDep(props) {
38 return y;
39 }
40
49 -function PrimitiveAsDepNested(props) {
50 - const $ = React.unstable_useMemoCache(9);
51 - const c_0 = $[0] !== props.b;
52 - const c_1 = $[1] !== props.a;
53 - let x;
54 - let y;
55 - if (c_0 || c_1) {
56 - x = {};
57 - mutate(x);
58 - const t0 = props.b + 1;
59 - const c_4 = $[4] !== t0;
60 - let t1;
61 - if (c_4) {
62 - t1 = foo(t0);
63 - $[4] = t0;
64 - $[5] = t1;
65 - } else {
66 - t1 = $[5];
67 - }
68 - y = t1;
69 - mutate(x, props.a);
70 - $[0] = props.b;
71 - $[1] = props.a;
72 - $[2] = x;
73 - $[3] = y;
74 - } else {
75 - x = $[2];
76 - y = $[3];
77 - }
78 - const c_6 = $[6] !== x;
79 - const c_7 = $[7] !== y;
80 - let t2;
81 - if (c_6 || c_7) {
82 - t2 = [x, y];
83 - $[6] = x;
84 - $[7] = y;
85 - $[8] = t2;
86 - } else {
87 - t2 = $[8];
88 - }
89 - return t2;
90 -}
91 -
41 ```
42
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/primitive-as-dep.js
-8
@@ -7,11 +7,3 @@ function PrimitiveAsDep(props) {
7 let y = foo(props.b + 1);
8 return y;
9 }
10 -
11 -function PrimitiveAsDepNested(props) {
12 - let x = {};
13 - mutate(x);
14 - let y = foo(props.b + 1);
15 - mutate(x, props.a);
16 - return [x, y];
17 -}