@samitouri / QOS-React / commits / 5ac4034e14

[compiler] Fork fixtures for enablePropagateDepsInHIR

- flip `enablePropagateDepsInHIR` to off by default - fork fixtures which produce compilation differences in #30894 to separate directory `propagate-scope-deps-hir-fork`, to be cleaned up when we remove this flag ghstack-source-id: 7d5b8dc29788a65c272c846af9877b09fbf2cd60 Pull Request resolved: https://github.com/facebook/react/pull/30949

Mofei Zhang committed Sep 12, 2024 at 16:59 UTC 5ac4034e14a72c0edf602585c10fd2725fb376c5
69 files changed +2445 -19
compiler/packages/babel-plugin-react-compiler/src/HIR/Environment.ts
+1 -1
@@ -223,7 +223,7 @@ const EnvironmentConfigSchema = z.object({
223 */
224 enableUseTypeAnnotations: z.boolean().default(false),
225
226 - enablePropagateDepsInHIR: z.boolean().default(true),
226 + enablePropagateDepsInHIR: z.boolean().default(false),
227
228 /**
229 * Enables inference of optional dependency chains. Without this flag
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-as-memo-dep.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
6 function Component(props) {
7 const data = useMemo(() => {
8 return props?.items.edges?.nodes.map();
@@ -15,7 +15,7 @@ function Component(props) {
15 ## Code
16
17 ```javascript
18 -import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
18 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
19 function Component(props) {
20 const $ = _c(4);
21
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-as-memo-dep.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
2 function Component(props) {
3 const data = useMemo(() => {
4 return props?.items.edges?.nodes.map();
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-inverted-optionals-parallel-paths.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
6 import {ValidateMemoization} from 'shared-runtime';
7 function Component(props) {
8 const data = useMemo(() => {
@@ -19,7 +19,7 @@ function Component(props) {
19 ## Code
20
21 ```javascript
22 -import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
22 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
23 import { ValidateMemoization } from "shared-runtime";
24 function Component(props) {
25 const $ = _c(2);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-inverted-optionals-parallel-paths.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
2 import {ValidateMemoization} from 'shared-runtime';
3 function Component(props) {
4 const data = useMemo(() => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-single-with-unconditional.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
6 import {ValidateMemoization} from 'shared-runtime';
7 function Component(props) {
8 const data = useMemo(() => {
@@ -19,7 +19,7 @@ function Component(props) {
19 ## Code
20
21 ```javascript
22 -import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
22 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
23 import { ValidateMemoization } from "shared-runtime";
24 function Component(props) {
25 const $ = _c(7);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-single-with-unconditional.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
2 import {ValidateMemoization} from 'shared-runtime';
3 function Component(props) {
4 const data = useMemo(() => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-single.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
6 import {ValidateMemoization} from 'shared-runtime';
7 function Component(props) {
8 const data = useMemo(() => {
@@ -18,7 +18,7 @@ function Component(props) {
18 ## Code
19
20 ```javascript
21 -import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
21 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
22 import { ValidateMemoization } from "shared-runtime";
23 function Component(props) {
24 const $ = _c(7);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-single.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
2 import {ValidateMemoization} from 'shared-runtime';
3 function Component(props) {
4 const data = useMemo(() => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-with-conditional-optional.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
6 import {ValidateMemoization} from 'shared-runtime';
7 function Component(props) {
8 const data = useMemo(() => {
@@ -23,7 +23,7 @@ function Component(props) {
23 ## Code
24
25 ```javascript
26 -import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
26 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
27 import { ValidateMemoization } from "shared-runtime";
28 function Component(props) {
29 const $ = _c(9);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-with-conditional-optional.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
2 import {ValidateMemoization} from 'shared-runtime';
3 function Component(props) {
4 const data = useMemo(() => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-with-conditional.expect.md
+2 -2
@@ -2,7 +2,7 @@
2 ## Input
3
4 ```javascript
5 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
6 import {ValidateMemoization} from 'shared-runtime';
7 function Component(props) {
8 const data = useMemo(() => {
@@ -23,7 +23,7 @@ function Component(props) {
23 ## Code
24
25 ```javascript
26 -import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
26 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
27 import { ValidateMemoization } from "shared-runtime";
28 function Component(props) {
29 const $ = _c(9);
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/optional-member-expression-with-conditional.js
+1 -1
@@ -1,4 +1,4 @@
1 -// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR:false
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies
2 import {ValidateMemoization} from 'shared-runtime';
3 function Component(props) {
4 const data = useMemo(() => {
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.expect.md new
+48
@@ -0,0 +1,48 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
6 +function Component(props) {
7 + const data = useMemo(() => {
8 + return props?.items.edges?.nodes.map();
9 + }, [props?.items.edges?.nodes]);
10 + return <Foo data={data} />;
11 +}
12 +
13 +```
14 +
15 +## Code
16 +
17 +```javascript
18 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
19 +function Component(props) {
20 + const $ = _c(4);
21 +
22 + props?.items.edges?.nodes;
23 + let t0;
24 + let t1;
25 + if ($[0] !== props?.items.edges?.nodes) {
26 + t1 = props?.items.edges?.nodes.map();
27 + $[0] = props?.items.edges?.nodes;
28 + $[1] = t1;
29 + } else {
30 + t1 = $[1];
31 + }
32 + t0 = t1;
33 + const data = t0;
34 + let t2;
35 + if ($[2] !== data) {
36 + t2 = <Foo data={data} />;
37 + $[2] = data;
38 + $[3] = t2;
39 + } else {
40 + t2 = $[3];
41 + }
42 + return t2;
43 +}
44 +
45 +```
46 +
47 +### Eval output
48 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-as-memo-dep.js new
+7
@@ -0,0 +1,7 @@
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
2 +function Component(props) {
3 + const data = useMemo(() => {
4 + return props?.items.edges?.nodes.map();
5 + }, [props?.items.edges?.nodes]);
6 + return <Foo data={data} />;
7 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.expect.md new
+46
@@ -0,0 +1,46 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
6 +import {ValidateMemoization} from 'shared-runtime';
7 +function Component(props) {
8 + const data = useMemo(() => {
9 + const x = [];
10 + x.push(props?.a.b?.c.d?.e);
11 + x.push(props.a?.b.c?.d.e);
12 + return x;
13 + }, [props.a.b.c.d.e]);
14 + return <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
15 +}
16 +
17 +```
18 +
19 +## Code
20 +
21 +```javascript
22 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
23 +import { ValidateMemoization } from "shared-runtime";
24 +function Component(props) {
25 + const $ = _c(2);
26 + let t0;
27 +
28 + const x$0 = [];
29 + x$0.push(props?.a.b?.c.d?.e);
30 + x$0.push(props.a?.b.c?.d.e);
31 + t0 = x$0;
32 + let t1;
33 + if ($[0] !== props.a.b.c.d.e) {
34 + t1 = <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
35 + $[0] = props.a.b.c.d.e;
36 + $[1] = t1;
37 + } else {
38 + t1 = $[1];
39 + }
40 + return t1;
41 +}
42 +
43 +```
44 +
45 +### Eval output
46 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-inverted-optionals-parallel-paths.js new
+11
@@ -0,0 +1,11 @@
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
2 +import {ValidateMemoization} from 'shared-runtime';
3 +function Component(props) {
4 + const data = useMemo(() => {
5 + const x = [];
6 + x.push(props?.a.b?.c.d?.e);
7 + x.push(props.a?.b.c?.d.e);
8 + return x;
9 + }, [props.a.b.c.d.e]);
10 + return <ValidateMemoization inputs={[props.a.b.c.d.e]} output={x} />;
11 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.expect.md new
+62
@@ -0,0 +1,62 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
6 +import {ValidateMemoization} from 'shared-runtime';
7 +function Component(props) {
8 + const data = useMemo(() => {
9 + const x = [];
10 + x.push(props?.items);
11 + x.push(props.items);
12 + return x;
13 + }, [props.items]);
14 + return <ValidateMemoization inputs={[props.items]} output={data} />;
15 +}
16 +
17 +```
18 +
19 +## Code
20 +
21 +```javascript
22 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
23 +import { ValidateMemoization } from "shared-runtime";
24 +function Component(props) {
25 + const $ = _c(7);
26 + let t0;
27 + let x;
28 + if ($[0] !== props.items) {
29 + x = [];
30 + x.push(props?.items);
31 + x.push(props.items);
32 + $[0] = props.items;
33 + $[1] = x;
34 + } else {
35 + x = $[1];
36 + }
37 + t0 = x;
38 + const data = t0;
39 + let t1;
40 + if ($[2] !== props.items) {
41 + t1 = [props.items];
42 + $[2] = props.items;
43 + $[3] = t1;
44 + } else {
45 + t1 = $[3];
46 + }
47 + let t2;
48 + if ($[4] !== t1 || $[5] !== data) {
49 + t2 = <ValidateMemoization inputs={t1} output={data} />;
50 + $[4] = t1;
51 + $[5] = data;
52 + $[6] = t2;
53 + } else {
54 + t2 = $[6];
55 + }
56 + return t2;
57 +}
58 +
59 +```
60 +
61 +### Eval output
62 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single-with-unconditional.js new
+11
@@ -0,0 +1,11 @@
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
2 +import {ValidateMemoization} from 'shared-runtime';
3 +function Component(props) {
4 + const data = useMemo(() => {
5 + const x = [];
6 + x.push(props?.items);
7 + x.push(props.items);
8 + return x;
9 + }, [props.items]);
10 + return <ValidateMemoization inputs={[props.items]} output={data} />;
11 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.expect.md new
+63
@@ -0,0 +1,63 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
6 +import {ValidateMemoization} from 'shared-runtime';
7 +function Component(props) {
8 + const data = useMemo(() => {
9 + const x = [];
10 + x.push(props?.items);
11 + return x;
12 + }, [props?.items]);
13 + return <ValidateMemoization inputs={[props?.items]} output={data} />;
14 +}
15 +
16 +```
17 +
18 +## Code
19 +
20 +```javascript
21 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
22 +import { ValidateMemoization } from "shared-runtime";
23 +function Component(props) {
24 + const $ = _c(7);
25 +
26 + props?.items;
27 + let t0;
28 + let x;
29 + if ($[0] !== props?.items) {
30 + x = [];
31 + x.push(props?.items);
32 + $[0] = props?.items;
33 + $[1] = x;
34 + } else {
35 + x = $[1];
36 + }
37 + t0 = x;
38 + const data = t0;
39 + const t1 = props?.items;
40 + let t2;
41 + if ($[2] !== t1) {
42 + t2 = [t1];
43 + $[2] = t1;
44 + $[3] = t2;
45 + } else {
46 + t2 = $[3];
47 + }
48 + let t3;
49 + if ($[4] !== t2 || $[5] !== data) {
50 + t3 = <ValidateMemoization inputs={t2} output={data} />;
51 + $[4] = t2;
52 + $[5] = data;
53 + $[6] = t3;
54 + } else {
55 + t3 = $[6];
56 + }
57 + return t3;
58 +}
59 +
60 +```
61 +
62 +### Eval output
63 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-single.js new
+10
@@ -0,0 +1,10 @@
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
2 +import {ValidateMemoization} from 'shared-runtime';
3 +function Component(props) {
4 + const data = useMemo(() => {
5 + const x = [];
6 + x.push(props?.items);
7 + return x;
8 + }, [props?.items]);
9 + return <ValidateMemoization inputs={[props?.items]} output={data} />;
10 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-with-conditional-optional.expect.md new
+74
@@ -0,0 +1,74 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
6 +import {ValidateMemoization} from 'shared-runtime';
7 +function Component(props) {
8 + const data = useMemo(() => {
9 + const x = [];
10 + x.push(props?.items);
11 + if (props.cond) {
12 + x.push(props?.items);
13 + }
14 + return x;
15 + }, [props?.items, props.cond]);
16 + return (
17 + <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
18 + );
19 +}
20 +
21 +```
22 +
23 +## Code
24 +
25 +```javascript
26 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
27 +import { ValidateMemoization } from "shared-runtime";
28 +function Component(props) {
29 + const $ = _c(9);
30 +
31 + props?.items;
32 + let t0;
33 + let x;
34 + if ($[0] !== props?.items || $[1] !== props.cond) {
35 + x = [];
36 + x.push(props?.items);
37 + if (props.cond) {
38 + x.push(props?.items);
39 + }
40 + $[0] = props?.items;
41 + $[1] = props.cond;
42 + $[2] = x;
43 + } else {
44 + x = $[2];
45 + }
46 + t0 = x;
47 + const data = t0;
48 +
49 + const t1 = props?.items;
50 + let t2;
51 + if ($[3] !== t1 || $[4] !== props.cond) {
52 + t2 = [t1, props.cond];
53 + $[3] = t1;
54 + $[4] = props.cond;
55 + $[5] = t2;
56 + } else {
57 + t2 = $[5];
58 + }
59 + let t3;
60 + if ($[6] !== t2 || $[7] !== data) {
61 + t3 = <ValidateMemoization inputs={t2} output={data} />;
62 + $[6] = t2;
63 + $[7] = data;
64 + $[8] = t3;
65 + } else {
66 + t3 = $[8];
67 + }
68 + return t3;
69 +}
70 +
71 +```
72 +
73 +### Eval output
74 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-with-conditional-optional.js new
+15
@@ -0,0 +1,15 @@
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
2 +import {ValidateMemoization} from 'shared-runtime';
3 +function Component(props) {
4 + const data = useMemo(() => {
5 + const x = [];
6 + x.push(props?.items);
7 + if (props.cond) {
8 + x.push(props?.items);
9 + }
10 + return x;
11 + }, [props?.items, props.cond]);
12 + return (
13 + <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
14 + );
15 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-with-conditional.expect.md new
+74
@@ -0,0 +1,74 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
6 +import {ValidateMemoization} from 'shared-runtime';
7 +function Component(props) {
8 + const data = useMemo(() => {
9 + const x = [];
10 + x.push(props?.items);
11 + if (props.cond) {
12 + x.push(props.items);
13 + }
14 + return x;
15 + }, [props?.items, props.cond]);
16 + return (
17 + <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
18 + );
19 +}
20 +
21 +```
22 +
23 +## Code
24 +
25 +```javascript
26 +import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
27 +import { ValidateMemoization } from "shared-runtime";
28 +function Component(props) {
29 + const $ = _c(9);
30 +
31 + props?.items;
32 + let t0;
33 + let x;
34 + if ($[0] !== props?.items || $[1] !== props.cond) {
35 + x = [];
36 + x.push(props?.items);
37 + if (props.cond) {
38 + x.push(props.items);
39 + }
40 + $[0] = props?.items;
41 + $[1] = props.cond;
42 + $[2] = x;
43 + } else {
44 + x = $[2];
45 + }
46 + t0 = x;
47 + const data = t0;
48 +
49 + const t1 = props?.items;
50 + let t2;
51 + if ($[3] !== t1 || $[4] !== props.cond) {
52 + t2 = [t1, props.cond];
53 + $[3] = t1;
54 + $[4] = props.cond;
55 + $[5] = t2;
56 + } else {
57 + t2 = $[5];
58 + }
59 + let t3;
60 + if ($[6] !== t2 || $[7] !== data) {
61 + t3 = <ValidateMemoization inputs={t2} output={data} />;
62 + $[6] = t2;
63 + $[7] = data;
64 + $[8] = t3;
65 + } else {
66 + t3 = $[8];
67 + }
68 + return t3;
69 +}
70 +
71 +```
72 +
73 +### Eval output
74 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/optional-member-expression-with-conditional.js new
+15
@@ -0,0 +1,15 @@
1 +// @validatePreserveExistingMemoizationGuarantees @enableOptionalDependencies @enablePropagateDepsInHIR
2 +import {ValidateMemoization} from 'shared-runtime';
3 +function Component(props) {
4 + const data = useMemo(() => {
5 + const x = [];
6 + x.push(props?.items);
7 + if (props.cond) {
8 + x.push(props.items);
9 + }
10 + return x;
11 + }, [props?.items, props.cond]);
12 + return (
13 + <ValidateMemoization inputs={[props?.items, props.cond]} output={data} />
14 + );
15 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.expect.md new
+53
@@ -0,0 +1,53 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +// To preserve the nullthrows behavior and reactive deps of this code,
7 +// Forget needs to add `props.a` as a dependency (since `props.a.b` is
8 +// a conditional dependency, i.e. gated behind control flow)
9 +
10 +function Component(props) {
11 + let x = [];
12 + x.push(props.a?.b);
13 + return x;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: Component,
18 + params: [{a: null}],
19 +};
20 +
21 +```
22 +
23 +## Code
24 +
25 +```javascript
26 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
27 +// To preserve the nullthrows behavior and reactive deps of this code,
28 +// Forget needs to add `props.a` as a dependency (since `props.a.b` is
29 +// a conditional dependency, i.e. gated behind control flow)
30 +
31 +function Component(props) {
32 + const $ = _c(2);
33 + let x;
34 + if ($[0] !== props.a?.b) {
35 + x = [];
36 + x.push(props.a?.b);
37 + $[0] = props.a?.b;
38 + $[1] = x;
39 + } else {
40 + x = $[1];
41 + }
42 + return x;
43 +}
44 +
45 +export const FIXTURE_ENTRYPOINT = {
46 + fn: Component,
47 + params: [{ a: null }],
48 +};
49 +
50 +```
51 +
52 +### Eval output
53 +(kind: ok) [null]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/conditional-member-expr.js new
+15
@@ -0,0 +1,15 @@
1 +// @enablePropagateDepsInHIR
2 +// To preserve the nullthrows behavior and reactive deps of this code,
3 +// Forget needs to add `props.a` as a dependency (since `props.a.b` is
4 +// a conditional dependency, i.e. gated behind control flow)
5 +
6 +function Component(props) {
7 + let x = [];
8 + x.push(props.a?.b);
9 + return x;
10 +}
11 +
12 +export const FIXTURE_ENTRYPOINT = {
13 + fn: Component,
14 + params: [{a: null}],
15 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.expect.md new
+100
@@ -0,0 +1,100 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +// This tests an optimization, NOT a correctness property.
7 +// When propagating reactive dependencies of an inner scope up to its parent,
8 +// we prefer to retain granularity.
9 +//
10 +// In this test, we check that Forget propagates the inner scope's conditional
11 +// dependencies (e.g. props.a.b) instead of only its derived minimal
12 +// unconditional dependencies (e.g. props).
13 +// ```javascript
14 +// scope @0 (deps=[???] decls=[x, y]) {
15 +// let y = {};
16 +// scope @1 (deps=[props] decls=[x]) {
17 +// let x = {};
18 +// if (foo) mutate1(x, props.a.b);
19 +// }
20 +// mutate2(y, props.a.b);
21 +// }
22 +
23 +import {CONST_TRUE, setProperty} from 'shared-runtime';
24 +
25 +function useJoinCondDepsInUncondScopes(props) {
26 + let y = {};
27 + let x = {};
28 + if (CONST_TRUE) {
29 + setProperty(x, props.a.b);
30 + }
31 + setProperty(y, props.a.b);
32 + return [x, y];
33 +}
34 +
35 +export const FIXTURE_ENTRYPOINT = {
36 + fn: useJoinCondDepsInUncondScopes,
37 + params: [{a: {b: 3}}],
38 +};
39 +
40 +```
41 +
42 +## Code
43 +
44 +```javascript
45 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
46 +// This tests an optimization, NOT a correctness property.
47 +// When propagating reactive dependencies of an inner scope up to its parent,
48 +// we prefer to retain granularity.
49 +//
50 +// In this test, we check that Forget propagates the inner scope's conditional
51 +// dependencies (e.g. props.a.b) instead of only its derived minimal
52 +// unconditional dependencies (e.g. props).
53 +// ```javascript
54 +// scope @0 (deps=[???] decls=[x, y]) {
55 +// let y = {};
56 +// scope @1 (deps=[props] decls=[x]) {
57 +// let x = {};
58 +// if (foo) mutate1(x, props.a.b);
59 +// }
60 +// mutate2(y, props.a.b);
61 +// }
62 +
63 +import { CONST_TRUE, setProperty } from "shared-runtime";
64 +
65 +function useJoinCondDepsInUncondScopes(props) {
66 + const $ = _c(4);
67 + let t0;
68 + if ($[0] !== props.a.b) {
69 + const y = {};
70 + let x;
71 + if ($[2] !== props) {
72 + x = {};
73 + if (CONST_TRUE) {
74 + setProperty(x, props.a.b);
75 + }
76 + $[2] = props;
77 + $[3] = x;
78 + } else {
79 + x = $[3];
80 + }
81 +
82 + setProperty(y, props.a.b);
83 + t0 = [x, y];
84 + $[0] = props.a.b;
85 + $[1] = t0;
86 + } else {
87 + t0 = $[1];
88 + }
89 + return t0;
90 +}
91 +
92 +export const FIXTURE_ENTRYPOINT = {
93 + fn: useJoinCondDepsInUncondScopes,
94 + params: [{ a: { b: 3 } }],
95 +};
96 +
97 +```
98 +
99 +### Eval output
100 +(kind: ok) [{"wat0":3},{"wat0":3}]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/join-uncond-scopes-cond-deps.js new
+34
@@ -0,0 +1,34 @@
1 +// @enablePropagateDepsInHIR
2 +// This tests an optimization, NOT a correctness property.
3 +// When propagating reactive dependencies of an inner scope up to its parent,
4 +// we prefer to retain granularity.
5 +//
6 +// In this test, we check that Forget propagates the inner scope's conditional
7 +// dependencies (e.g. props.a.b) instead of only its derived minimal
8 +// unconditional dependencies (e.g. props).
9 +// ```javascript
10 +// scope @0 (deps=[???] decls=[x, y]) {
11 +// let y = {};
12 +// scope @1 (deps=[props] decls=[x]) {
13 +// let x = {};
14 +// if (foo) mutate1(x, props.a.b);
15 +// }
16 +// mutate2(y, props.a.b);
17 +// }
18 +
19 +import {CONST_TRUE, setProperty} from 'shared-runtime';
20 +
21 +function useJoinCondDepsInUncondScopes(props) {
22 + let y = {};
23 + let x = {};
24 + if (CONST_TRUE) {
25 + setProperty(x, props.a.b);
26 + }
27 + setProperty(y, props.a.b);
28 + return [x, y];
29 +}
30 +
31 +export const FIXTURE_ENTRYPOINT = {
32 + fn: useJoinCondDepsInUncondScopes,
33 + params: [{a: {b: 3}}],
34 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.expect.md new
+69
@@ -0,0 +1,69 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +// To preserve the nullthrows behavior and reactive deps of this code,
7 +// Forget needs to add `props.a.b` or a subpath as a dependency.
8 +//
9 +// (1) Since the reactive block producing x unconditionally read props.a.<...>,
10 +// reading `props.a.b` outside of the block would still preserve nullthrows
11 +// semantics of source code
12 +// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
13 +// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
14 +// not its actual value. Since we already preserve nullthrows on `props.a`,
15 +// we technically do not need to add `props.a` as a dependency.
16 +
17 +function Component(props) {
18 + let x = [];
19 + x.push(props.a?.b);
20 + x.push(props.a.b.c);
21 + return x;
22 +}
23 +
24 +export const FIXTURE_ENTRYPOINT = {
25 + fn: Component,
26 + params: [{a: {b: {c: 1}}}],
27 +};
28 +
29 +```
30 +
31 +## Code
32 +
33 +```javascript
34 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
35 +// To preserve the nullthrows behavior and reactive deps of this code,
36 +// Forget needs to add `props.a.b` or a subpath as a dependency.
37 +//
38 +// (1) Since the reactive block producing x unconditionally read props.a.<...>,
39 +// reading `props.a.b` outside of the block would still preserve nullthrows
40 +// semantics of source code
41 +// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
42 +// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
43 +// not its actual value. Since we already preserve nullthrows on `props.a`,
44 +// we technically do not need to add `props.a` as a dependency.
45 +
46 +function Component(props) {
47 + const $ = _c(2);
48 + let x;
49 + if ($[0] !== props.a.b) {
50 + x = [];
51 + x.push(props.a?.b);
52 + x.push(props.a.b.c);
53 + $[0] = props.a.b;
54 + $[1] = x;
55 + } else {
56 + x = $[1];
57 + }
58 + return x;
59 +}
60 +
61 +export const FIXTURE_ENTRYPOINT = {
62 + fn: Component,
63 + params: [{ a: { b: { c: 1 } } }],
64 +};
65 +
66 +```
67 +
68 +### Eval output
69 +(kind: ok) [{"c":1},1]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain.ts new
+23
@@ -0,0 +1,23 @@
1 +// @enablePropagateDepsInHIR
2 +// To preserve the nullthrows behavior and reactive deps of this code,
3 +// Forget needs to add `props.a.b` or a subpath as a dependency.
4 +//
5 +// (1) Since the reactive block producing x unconditionally read props.a.<...>,
6 +// reading `props.a.b` outside of the block would still preserve nullthrows
7 +// semantics of source code
8 +// (2) Technically, props.a, props.a.b, and props.a.b.c are all reactive deps.
9 +// However, `props.a?.b` is only dependent on whether `props.a` is nullish,
10 +// not its actual value. Since we already preserve nullthrows on `props.a`,
11 +// we technically do not need to add `props.a` as a dependency.
12 +
13 +function Component(props) {
14 + let x = [];
15 + x.push(props.a?.b);
16 + x.push(props.a.b.c);
17 + return x;
18 +}
19 +
20 +export const FIXTURE_ENTRYPOINT = {
21 + fn: Component,
22 + params: [{a: {b: {c: 1}}}],
23 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.expect.md new
+56
@@ -0,0 +1,56 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function Component(props) {
7 + const x = [];
8 + x.push(props.items?.length);
9 + x.push(props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? []);
10 + return x;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: Component,
15 + params: [{items: {edges: null, length: 0}}],
16 +};
17 +
18 +```
19 +
20 +## Code
21 +
22 +```javascript
23 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
24 +function Component(props) {
25 + const $ = _c(5);
26 + let x;
27 + if ($[0] !== props.items?.length || $[1] !== props.items?.edges) {
28 + x = [];
29 + x.push(props.items?.length);
30 + let t0;
31 + if ($[3] !== props.items?.edges) {
32 + t0 = props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? [];
33 + $[3] = props.items?.edges;
34 + $[4] = t0;
35 + } else {
36 + t0 = $[4];
37 + }
38 + x.push(t0);
39 + $[0] = props.items?.length;
40 + $[1] = props.items?.edges;
41 + $[2] = x;
42 + } else {
43 + x = $[2];
44 + }
45 + return x;
46 +}
47 +
48 +export const FIXTURE_ENTRYPOINT = {
49 + fn: Component,
50 + params: [{ items: { edges: null, length: 0 } }],
51 +};
52 +
53 +```
54 +
55 +### Eval output
56 +(kind: ok) [0,[]]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/memberexpr-join-optional-chain2.ts new
+12
@@ -0,0 +1,12 @@
1 +// @enablePropagateDepsInHIR
2 +function Component(props) {
3 + const x = [];
4 + x.push(props.items?.length);
5 + x.push(props.items?.edges?.map?.(render)?.filter?.(Boolean) ?? []);
6 + return x;
7 +}
8 +
9 +export const FIXTURE_ENTRYPOINT = {
10 + fn: Component,
11 + params: [{items: {edges: null, length: 0}}],
12 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.expect.md new
+64
@@ -0,0 +1,64 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +// When a conditional dependency `props.a.b.c` has no unconditional dependency
7 +// in its subpath or superpath, we should find the nearest unconditional access
8 +
9 +import {identity} from 'shared-runtime';
10 +
11 +// and promote it to an unconditional dependency.
12 +function usePromoteUnconditionalAccessToDependency(props, other) {
13 + const x = {};
14 + x.a = props.a.a.a;
15 + if (identity(other)) {
16 + x.c = props.a.b.c;
17 + }
18 + return x;
19 +}
20 +
21 +export const FIXTURE_ENTRYPOINT = {
22 + fn: usePromoteUnconditionalAccessToDependency,
23 + params: [{a: {a: {a: 3}}}, false],
24 +};
25 +
26 +```
27 +
28 +## Code
29 +
30 +```javascript
31 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
32 +// When a conditional dependency `props.a.b.c` has no unconditional dependency
33 +// in its subpath or superpath, we should find the nearest unconditional access
34 +
35 +import { identity } from "shared-runtime";
36 +
37 +// and promote it to an unconditional dependency.
38 +function usePromoteUnconditionalAccessToDependency(props, other) {
39 + const $ = _c(3);
40 + let x;
41 + if ($[0] !== props.a || $[1] !== other) {
42 + x = {};
43 + x.a = props.a.a.a;
44 + if (identity(other)) {
45 + x.c = props.a.b.c;
46 + }
47 + $[0] = props.a;
48 + $[1] = other;
49 + $[2] = x;
50 + } else {
51 + x = $[2];
52 + }
53 + return x;
54 +}
55 +
56 +export const FIXTURE_ENTRYPOINT = {
57 + fn: usePromoteUnconditionalAccessToDependency,
58 + params: [{ a: { a: { a: 3 } } }, false],
59 +};
60 +
61 +```
62 +
63 +### Eval output
64 +(kind: ok) {"a":3}
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/reduce-reactive-deps/promote-uncond.js new
+20
@@ -0,0 +1,20 @@
1 +// @enablePropagateDepsInHIR
2 +// When a conditional dependency `props.a.b.c` has no unconditional dependency
3 +// in its subpath or superpath, we should find the nearest unconditional access
4 +
5 +import {identity} from 'shared-runtime';
6 +
7 +// and promote it to an unconditional dependency.
8 +function usePromoteUnconditionalAccessToDependency(props, other) {
9 + const x = {};
10 + x.a = props.a.a.a;
11 + if (identity(other)) {
12 + x.c = props.a.b.c;
13 + }
14 + return x;
15 +}
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: usePromoteUnconditionalAccessToDependency,
19 + params: [{a: {a: {a: 3}}}, false],
20 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.expect.md new
+55
@@ -0,0 +1,55 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function HomeDiscoStoreItemTileRating(props) {
7 + const item = useFragment();
8 + let count = 0;
9 + const aggregates = item?.aggregates || [];
10 + aggregates.forEach(aggregate => {
11 + count += aggregate.count || 0;
12 + });
13 +
14 + return <Text>{count}</Text>;
15 +}
16 +
17 +```
18 +
19 +## Code
20 +
21 +```javascript
22 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
23 +function HomeDiscoStoreItemTileRating(props) {
24 + const $ = _c(4);
25 + const item = useFragment();
26 + let count;
27 + if ($[0] !== item?.aggregates) {
28 + count = 0;
29 + const aggregates = item?.aggregates || [];
30 + aggregates.forEach((aggregate) => {
31 + count = count + (aggregate.count || 0);
32 + count;
33 + });
34 + $[0] = item?.aggregates;
35 + $[1] = count;
36 + } else {
37 + count = $[1];
38 + }
39 +
40 + const t0 = count;
41 + let t1;
42 + if ($[2] !== t0) {
43 + t1 = <Text>{t0}</Text>;
44 + $[2] = t0;
45 + $[3] = t1;
46 + } else {
47 + t1 = $[3];
48 + }
49 + return t1;
50 +}
51 +
52 +```
53 +
54 +### Eval output
55 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/repro-scope-missing-mutable-range.js new
+11
@@ -0,0 +1,11 @@
1 +// @enablePropagateDepsInHIR
2 +function HomeDiscoStoreItemTileRating(props) {
3 + const item = useFragment();
4 + let count = 0;
5 + const aggregates = item?.aggregates || [];
6 + aggregates.forEach(aggregate => {
7 + count += aggregate.count || 0;
8 + });
9 +
10 + return <Text>{count}</Text>;
11 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.expect.md new
+85
@@ -0,0 +1,85 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function Component(props) {
7 + let x = 0;
8 + const values = [];
9 + const y = props.a || props.b;
10 + values.push(y);
11 + if (props.c) {
12 + x = 1;
13 + }
14 + values.push(x);
15 + if (props.d) {
16 + x = 2;
17 + }
18 + values.push(x);
19 + return values;
20 +}
21 +
22 +export const FIXTURE_ENTRYPOINT = {
23 + fn: Component,
24 + params: [{a: 0, b: 1, c: true, d: true}],
25 + sequentialRenders: [
26 + {a: 0, b: 1, c: true, d: true},
27 + {a: 4, b: 1, c: true, d: true},
28 + {a: 4, b: 1, c: false, d: true},
29 + {a: 4, b: 1, c: false, d: false},
30 + ],
31 +};
32 +
33 +```
34 +
35 +## Code
36 +
37 +```javascript
38 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
39 +function Component(props) {
40 + const $ = _c(4);
41 + let x = 0;
42 + let values;
43 + if ($[0] !== props || $[1] !== x) {
44 + values = [];
45 + const y = props.a || props.b;
46 + values.push(y);
47 + if (props.c) {
48 + x = 1;
49 + }
50 +
51 + values.push(x);
52 + if (props.d) {
53 + x = 2;
54 + }
55 +
56 + values.push(x);
57 + $[0] = props;
58 + $[1] = x;
59 + $[2] = values;
60 + $[3] = x;
61 + } else {
62 + values = $[2];
63 + x = $[3];
64 + }
65 + return values;
66 +}
67 +
68 +export const FIXTURE_ENTRYPOINT = {
69 + fn: Component,
70 + params: [{ a: 0, b: 1, c: true, d: true }],
71 + sequentialRenders: [
72 + { a: 0, b: 1, c: true, d: true },
73 + { a: 4, b: 1, c: true, d: true },
74 + { a: 4, b: 1, c: false, d: true },
75 + { a: 4, b: 1, c: false, d: false },
76 + ],
77 +};
78 +
79 +```
80 +
81 +### Eval output
82 +(kind: ok) [1,1,2]
83 +[4,1,2]
84 +[4,0,2]
85 +[4,0,0]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-cascading-eliminated-phis.js new
+27
@@ -0,0 +1,27 @@
1 +// @enablePropagateDepsInHIR
2 +function Component(props) {
3 + let x = 0;
4 + const values = [];
5 + const y = props.a || props.b;
6 + values.push(y);
7 + if (props.c) {
8 + x = 1;
9 + }
10 + values.push(x);
11 + if (props.d) {
12 + x = 2;
13 + }
14 + values.push(x);
15 + return values;
16 +}
17 +
18 +export const FIXTURE_ENTRYPOINT = {
19 + fn: Component,
20 + params: [{a: 0, b: 1, c: true, d: true}],
21 + sequentialRenders: [
22 + {a: 0, b: 1, c: true, d: true},
23 + {a: 4, b: 1, c: true, d: true},
24 + {a: 4, b: 1, c: false, d: true},
25 + {a: 4, b: 1, c: false, d: false},
26 + ],
27 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.expect.md new
+84
@@ -0,0 +1,84 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {Stringify} from 'shared-runtime';
7 +
8 +function Component(props) {
9 + let x = [];
10 + let y;
11 + if (props.p0) {
12 + x.push(props.p1);
13 + y = x;
14 + }
15 + return (
16 + <Stringify>
17 + {x}
18 + {y}
19 + </Stringify>
20 + );
21 +}
22 +
23 +export const FIXTURE_ENTRYPOINT = {
24 + fn: Component,
25 + params: [{p0: false, p1: 2}],
26 + sequentialRenders: [
27 + {p0: false, p1: 2},
28 + {p0: false, p1: 2},
29 + {p0: true, p1: 2},
30 + {p0: true, p1: 3},
31 + ],
32 +};
33 +
34 +```
35 +
36 +## Code
37 +
38 +```javascript
39 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
40 +import { Stringify } from "shared-runtime";
41 +
42 +function Component(props) {
43 + const $ = _c(2);
44 + let t0;
45 + if ($[0] !== props) {
46 + const x = [];
47 + let y;
48 + if (props.p0) {
49 + x.push(props.p1);
50 + y = x;
51 + }
52 +
53 + t0 = (
54 + <Stringify>
55 + {x}
56 + {y}
57 + </Stringify>
58 + );
59 + $[0] = props;
60 + $[1] = t0;
61 + } else {
62 + t0 = $[1];
63 + }
64 + return t0;
65 +}
66 +
67 +export const FIXTURE_ENTRYPOINT = {
68 + fn: Component,
69 + params: [{ p0: false, p1: 2 }],
70 + sequentialRenders: [
71 + { p0: false, p1: 2 },
72 + { p0: false, p1: 2 },
73 + { p0: true, p1: 2 },
74 + { p0: true, p1: 3 },
75 + ],
76 +};
77 +
78 +```
79 +
80 +### Eval output
81 +(kind: ok) <div>{"children":[[],null]}</div>
82 +<div>{"children":[[],null]}</div>
83 +<div>{"children":[[2],"[[ cyclic ref *2 ]]"]}</div>
84 +<div>{"children":[[3],"[[ cyclic ref *2 ]]"]}</div>
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-leave-case.js new
+28
@@ -0,0 +1,28 @@
1 +// @enablePropagateDepsInHIR
2 +import {Stringify} from 'shared-runtime';
3 +
4 +function Component(props) {
5 + let x = [];
6 + let y;
7 + if (props.p0) {
8 + x.push(props.p1);
9 + y = x;
10 + }
11 + return (
12 + <Stringify>
13 + {x}
14 + {y}
15 + </Stringify>
16 + );
17 +}
18 +
19 +export const FIXTURE_ENTRYPOINT = {
20 + fn: Component,
21 + params: [{p0: false, p1: 2}],
22 + sequentialRenders: [
23 + {p0: false, p1: 2},
24 + {p0: false, p1: 2},
25 + {p0: true, p1: 2},
26 + {p0: true, p1: 3},
27 + ],
28 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.expect.md new
+65
@@ -0,0 +1,65 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {mutate} from 'shared-runtime';
7 +
8 +function useFoo(props) {
9 + let x = [];
10 + x.push(props.bar);
11 + props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
12 + mutate(x);
13 + return x;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: useFoo,
18 + params: [{cond: false, foo: 2, bar: 55}],
19 + sequentialRenders: [
20 + {cond: false, foo: 2, bar: 55},
21 + {cond: false, foo: 3, bar: 55},
22 + {cond: true, foo: 3, bar: 55},
23 + ],
24 +};
25 +
26 +```
27 +
28 +## Code
29 +
30 +```javascript
31 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
32 +import { mutate } from "shared-runtime";
33 +
34 +function useFoo(props) {
35 + const $ = _c(2);
36 + let x;
37 + if ($[0] !== props) {
38 + x = [];
39 + x.push(props.bar);
40 + props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
41 + mutate(x);
42 + $[0] = props;
43 + $[1] = x;
44 + } else {
45 + x = $[1];
46 + }
47 + return x;
48 +}
49 +
50 +export const FIXTURE_ENTRYPOINT = {
51 + fn: useFoo,
52 + params: [{ cond: false, foo: 2, bar: 55 }],
53 + sequentialRenders: [
54 + { cond: false, foo: 2, bar: 55 },
55 + { cond: false, foo: 3, bar: 55 },
56 + { cond: true, foo: 3, bar: 55 },
57 + ],
58 +};
59 +
60 +```
61 +
62 +### Eval output
63 +(kind: ok) [55,"joe"]
64 +[55,"joe"]
65 +[3,"joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction-with-mutation.js new
+20
@@ -0,0 +1,20 @@
1 +// @enablePropagateDepsInHIR
2 +import {mutate} from 'shared-runtime';
3 +
4 +function useFoo(props) {
5 + let x = [];
6 + x.push(props.bar);
7 + props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
8 + mutate(x);
9 + return x;
10 +}
11 +
12 +export const FIXTURE_ENTRYPOINT = {
13 + fn: useFoo,
14 + params: [{cond: false, foo: 2, bar: 55}],
15 + sequentialRenders: [
16 + {cond: false, foo: 2, bar: 55},
17 + {cond: false, foo: 3, bar: 55},
18 + {cond: true, foo: 3, bar: 55},
19 + ],
20 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.expect.md new
+65
@@ -0,0 +1,65 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function useFoo(props) {
7 + let x = [];
8 + x.push(props.bar);
9 + props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
10 + return x;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: useFoo,
15 + params: [{cond: false, foo: 2, bar: 55}],
16 + sequentialRenders: [
17 + {cond: false, foo: 2, bar: 55},
18 + {cond: false, foo: 3, bar: 55},
19 + {cond: true, foo: 3, bar: 55},
20 + ],
21 +};
22 +
23 +```
24 +
25 +## Code
26 +
27 +```javascript
28 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
29 +function useFoo(props) {
30 + const $ = _c(4);
31 + let x;
32 + if ($[0] !== props.bar) {
33 + x = [];
34 + x.push(props.bar);
35 + $[0] = props.bar;
36 + $[1] = x;
37 + } else {
38 + x = $[1];
39 + }
40 + if ($[2] !== props) {
41 + props.cond ? (([x] = [[]]), x.push(props.foo)) : null;
42 + $[2] = props;
43 + $[3] = x;
44 + } else {
45 + x = $[3];
46 + }
47 + return x;
48 +}
49 +
50 +export const FIXTURE_ENTRYPOINT = {
51 + fn: useFoo,
52 + params: [{ cond: false, foo: 2, bar: 55 }],
53 + sequentialRenders: [
54 + { cond: false, foo: 2, bar: 55 },
55 + { cond: false, foo: 3, bar: 55 },
56 + { cond: true, foo: 3, bar: 55 },
57 + ],
58 +};
59 +
60 +```
61 +
62 +### Eval output
63 +(kind: ok) [55]
64 +[55]
65 +[3]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-destruction.js new
+17
@@ -0,0 +1,17 @@
1 +// @enablePropagateDepsInHIR
2 +function useFoo(props) {
3 + let x = [];
4 + x.push(props.bar);
5 + props.cond ? (({x} = {x: {}}), ([x] = [[]]), x.push(props.foo)) : null;
6 + return x;
7 +}
8 +
9 +export const FIXTURE_ENTRYPOINT = {
10 + fn: useFoo,
11 + params: [{cond: false, foo: 2, bar: 55}],
12 + sequentialRenders: [
13 + {cond: false, foo: 2, bar: 55},
14 + {cond: false, foo: 3, bar: 55},
15 + {cond: true, foo: 3, bar: 55},
16 + ],
17 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.expect.md new
+65
@@ -0,0 +1,65 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {mutate} from 'shared-runtime';
7 +
8 +function useFoo(props) {
9 + let x = [];
10 + x.push(props.bar);
11 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
12 + mutate(x);
13 + return x;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: useFoo,
18 + params: [{cond: false, foo: 2, bar: 55}],
19 + sequentialRenders: [
20 + {cond: false, foo: 2, bar: 55},
21 + {cond: false, foo: 3, bar: 55},
22 + {cond: true, foo: 3, bar: 55},
23 + ],
24 +};
25 +
26 +```
27 +
28 +## Code
29 +
30 +```javascript
31 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
32 +import { mutate } from "shared-runtime";
33 +
34 +function useFoo(props) {
35 + const $ = _c(2);
36 + let x;
37 + if ($[0] !== props) {
38 + x = [];
39 + x.push(props.bar);
40 + props.cond ? ((x = []), x.push(props.foo)) : null;
41 + mutate(x);
42 + $[0] = props;
43 + $[1] = x;
44 + } else {
45 + x = $[1];
46 + }
47 + return x;
48 +}
49 +
50 +export const FIXTURE_ENTRYPOINT = {
51 + fn: useFoo,
52 + params: [{ cond: false, foo: 2, bar: 55 }],
53 + sequentialRenders: [
54 + { cond: false, foo: 2, bar: 55 },
55 + { cond: false, foo: 3, bar: 55 },
56 + { cond: true, foo: 3, bar: 55 },
57 + ],
58 +};
59 +
60 +```
61 +
62 +### Eval output
63 +(kind: ok) [55,"joe"]
64 +[55,"joe"]
65 +[3,"joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary-with-mutation.js new
+20
@@ -0,0 +1,20 @@
1 +// @enablePropagateDepsInHIR
2 +import {mutate} from 'shared-runtime';
3 +
4 +function useFoo(props) {
5 + let x = [];
6 + x.push(props.bar);
7 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
8 + mutate(x);
9 + return x;
10 +}
11 +
12 +export const FIXTURE_ENTRYPOINT = {
13 + fn: useFoo,
14 + params: [{cond: false, foo: 2, bar: 55}],
15 + sequentialRenders: [
16 + {cond: false, foo: 2, bar: 55},
17 + {cond: false, foo: 3, bar: 55},
18 + {cond: true, foo: 3, bar: 55},
19 + ],
20 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.expect.md new
+65
@@ -0,0 +1,65 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function useFoo(props) {
7 + let x = [];
8 + x.push(props.bar);
9 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
10 + return x;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: useFoo,
15 + params: [{cond: false, foo: 2, bar: 55}],
16 + sequentialRenders: [
17 + {cond: false, foo: 2, bar: 55},
18 + {cond: false, foo: 3, bar: 55},
19 + {cond: true, foo: 3, bar: 55},
20 + ],
21 +};
22 +
23 +```
24 +
25 +## Code
26 +
27 +```javascript
28 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
29 +function useFoo(props) {
30 + const $ = _c(4);
31 + let x;
32 + if ($[0] !== props.bar) {
33 + x = [];
34 + x.push(props.bar);
35 + $[0] = props.bar;
36 + $[1] = x;
37 + } else {
38 + x = $[1];
39 + }
40 + if ($[2] !== props) {
41 + props.cond ? ((x = []), x.push(props.foo)) : null;
42 + $[2] = props;
43 + $[3] = x;
44 + } else {
45 + x = $[3];
46 + }
47 + return x;
48 +}
49 +
50 +export const FIXTURE_ENTRYPOINT = {
51 + fn: useFoo,
52 + params: [{ cond: false, foo: 2, bar: 55 }],
53 + sequentialRenders: [
54 + { cond: false, foo: 2, bar: 55 },
55 + { cond: false, foo: 3, bar: 55 },
56 + { cond: true, foo: 3, bar: 55 },
57 + ],
58 +};
59 +
60 +```
61 +
62 +### Eval output
63 +(kind: ok) [55]
64 +[55]
65 +[3]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-ternary.js new
+17
@@ -0,0 +1,17 @@
1 +// @enablePropagateDepsInHIR
2 +function useFoo(props) {
3 + let x = [];
4 + x.push(props.bar);
5 + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null;
6 + return x;
7 +}
8 +
9 +export const FIXTURE_ENTRYPOINT = {
10 + fn: useFoo,
11 + params: [{cond: false, foo: 2, bar: 55}],
12 + sequentialRenders: [
13 + {cond: false, foo: 2, bar: 55},
14 + {cond: false, foo: 3, bar: 55},
15 + {cond: true, foo: 3, bar: 55},
16 + ],
17 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.expect.md new
+65
@@ -0,0 +1,65 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {arrayPush} from 'shared-runtime';
7 +function useFoo(props) {
8 + let x = [];
9 + x.push(props.bar);
10 + props.cond
11 + ? ((x = {}), (x = []), x.push(props.foo))
12 + : ((x = []), (x = []), x.push(props.bar));
13 + arrayPush(x, 4);
14 + return x;
15 +}
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: useFoo,
19 + params: [{cond: false, foo: 2, bar: 55}],
20 + sequentialRenders: [
21 + {cond: false, foo: 2, bar: 55},
22 + {cond: false, foo: 3, bar: 55},
23 + {cond: true, foo: 3, bar: 55},
24 + ],
25 +};
26 +
27 +```
28 +
29 +## Code
30 +
31 +```javascript
32 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
33 +import { arrayPush } from "shared-runtime";
34 +function useFoo(props) {
35 + const $ = _c(2);
36 + let x;
37 + if ($[0] !== props) {
38 + x = [];
39 + x.push(props.bar);
40 + props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar));
41 + arrayPush(x, 4);
42 + $[0] = props;
43 + $[1] = x;
44 + } else {
45 + x = $[1];
46 + }
47 + return x;
48 +}
49 +
50 +export const FIXTURE_ENTRYPOINT = {
51 + fn: useFoo,
52 + params: [{ cond: false, foo: 2, bar: 55 }],
53 + sequentialRenders: [
54 + { cond: false, foo: 2, bar: 55 },
55 + { cond: false, foo: 3, bar: 55 },
56 + { cond: true, foo: 3, bar: 55 },
57 + ],
58 +};
59 +
60 +```
61 +
62 +### Eval output
63 +(kind: ok) [55,4]
64 +[55,4]
65 +[3,4]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary-with-mutation.js new
+21
@@ -0,0 +1,21 @@
1 +// @enablePropagateDepsInHIR
2 +import {arrayPush} from 'shared-runtime';
3 +function useFoo(props) {
4 + let x = [];
5 + x.push(props.bar);
6 + props.cond
7 + ? ((x = {}), (x = []), x.push(props.foo))
8 + : ((x = []), (x = []), x.push(props.bar));
9 + arrayPush(x, 4);
10 + return x;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: useFoo,
15 + params: [{cond: false, foo: 2, bar: 55}],
16 + sequentialRenders: [
17 + {cond: false, foo: 2, bar: 55},
18 + {cond: false, foo: 3, bar: 55},
19 + {cond: true, foo: 3, bar: 55},
20 + ],
21 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.expect.md new
+67
@@ -0,0 +1,67 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function useFoo(props) {
7 + let x = [];
8 + x.push(props.bar);
9 + props.cond
10 + ? ((x = {}), (x = []), x.push(props.foo))
11 + : ((x = []), (x = []), x.push(props.bar));
12 + return x;
13 +}
14 +
15 +export const FIXTURE_ENTRYPOINT = {
16 + fn: useFoo,
17 + params: [{cond: false, foo: 2, bar: 55}],
18 + sequentialRenders: [
19 + {cond: false, foo: 2, bar: 55},
20 + {cond: false, foo: 3, bar: 55},
21 + {cond: true, foo: 3, bar: 55},
22 + ],
23 +};
24 +
25 +```
26 +
27 +## Code
28 +
29 +```javascript
30 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
31 +function useFoo(props) {
32 + const $ = _c(4);
33 + let x;
34 + if ($[0] !== props.bar) {
35 + x = [];
36 + x.push(props.bar);
37 + $[0] = props.bar;
38 + $[1] = x;
39 + } else {
40 + x = $[1];
41 + }
42 + if ($[2] !== props) {
43 + props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar));
44 + $[2] = props;
45 + $[3] = x;
46 + } else {
47 + x = $[3];
48 + }
49 + return x;
50 +}
51 +
52 +export const FIXTURE_ENTRYPOINT = {
53 + fn: useFoo,
54 + params: [{ cond: false, foo: 2, bar: 55 }],
55 + sequentialRenders: [
56 + { cond: false, foo: 2, bar: 55 },
57 + { cond: false, foo: 3, bar: 55 },
58 + { cond: true, foo: 3, bar: 55 },
59 + ],
60 +};
61 +
62 +```
63 +
64 +### Eval output
65 +(kind: ok) [55]
66 +[55]
67 +[3]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-unconditional-ternary.js new
+19
@@ -0,0 +1,19 @@
1 +// @enablePropagateDepsInHIR
2 +function useFoo(props) {
3 + let x = [];
4 + x.push(props.bar);
5 + props.cond
6 + ? ((x = {}), (x = []), x.push(props.foo))
7 + : ((x = []), (x = []), x.push(props.bar));
8 + return x;
9 +}
10 +
11 +export const FIXTURE_ENTRYPOINT = {
12 + fn: useFoo,
13 + params: [{cond: false, foo: 2, bar: 55}],
14 + sequentialRenders: [
15 + {cond: false, foo: 2, bar: 55},
16 + {cond: false, foo: 3, bar: 55},
17 + {cond: true, foo: 3, bar: 55},
18 + ],
19 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.expect.md new
+73
@@ -0,0 +1,73 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {mutate} from 'shared-runtime';
7 +
8 +function useFoo(props) {
9 + let {x} = {x: []};
10 + x.push(props.bar);
11 + if (props.cond) {
12 + ({x} = {x: {}});
13 + ({x} = {x: []});
14 + x.push(props.foo);
15 + }
16 + mutate(x);
17 + return x;
18 +}
19 +
20 +export const FIXTURE_ENTRYPOINT = {
21 + fn: useFoo,
22 + params: [{bar: 'bar', foo: 'foo', cond: true}],
23 + sequentialRenders: [
24 + {bar: 'bar', foo: 'foo', cond: true},
25 + {bar: 'bar', foo: 'foo', cond: true},
26 + {bar: 'bar', foo: 'foo', cond: false},
27 + ],
28 +};
29 +
30 +```
31 +
32 +## Code
33 +
34 +```javascript
35 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
36 +import { mutate } from "shared-runtime";
37 +
38 +function useFoo(props) {
39 + const $ = _c(2);
40 + let x;
41 + if ($[0] !== props) {
42 + ({ x } = { x: [] });
43 + x.push(props.bar);
44 + if (props.cond) {
45 + ({ x } = { x: [] });
46 + x.push(props.foo);
47 + }
48 +
49 + mutate(x);
50 + $[0] = props;
51 + $[1] = x;
52 + } else {
53 + x = $[1];
54 + }
55 + return x;
56 +}
57 +
58 +export const FIXTURE_ENTRYPOINT = {
59 + fn: useFoo,
60 + params: [{ bar: "bar", foo: "foo", cond: true }],
61 + sequentialRenders: [
62 + { bar: "bar", foo: "foo", cond: true },
63 + { bar: "bar", foo: "foo", cond: true },
64 + { bar: "bar", foo: "foo", cond: false },
65 + ],
66 +};
67 +
68 +```
69 +
70 +### Eval output
71 +(kind: ok) ["foo","joe"]
72 +["foo","joe"]
73 +["bar","joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-via-destructuring-with-mutation.js new
+24
@@ -0,0 +1,24 @@
1 +// @enablePropagateDepsInHIR
2 +import {mutate} from 'shared-runtime';
3 +
4 +function useFoo(props) {
5 + let {x} = {x: []};
6 + x.push(props.bar);
7 + if (props.cond) {
8 + ({x} = {x: {}});
9 + ({x} = {x: []});
10 + x.push(props.foo);
11 + }
12 + mutate(x);
13 + return x;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: useFoo,
18 + params: [{bar: 'bar', foo: 'foo', cond: true}],
19 + sequentialRenders: [
20 + {bar: 'bar', foo: 'foo', cond: true},
21 + {bar: 'bar', foo: 'foo', cond: true},
22 + {bar: 'bar', foo: 'foo', cond: false},
23 + ],
24 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.expect.md new
+73
@@ -0,0 +1,73 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {mutate} from 'shared-runtime';
7 +
8 +function useFoo(props) {
9 + let x = [];
10 + x.push(props.bar);
11 + if (props.cond) {
12 + x = {};
13 + x = [];
14 + x.push(props.foo);
15 + }
16 + mutate(x);
17 + return x;
18 +}
19 +
20 +export const FIXTURE_ENTRYPOINT = {
21 + fn: useFoo,
22 + params: [{bar: 'bar', foo: 'foo', cond: true}],
23 + sequentialRenders: [
24 + {bar: 'bar', foo: 'foo', cond: true},
25 + {bar: 'bar', foo: 'foo', cond: true},
26 + {bar: 'bar', foo: 'foo', cond: false},
27 + ],
28 +};
29 +
30 +```
31 +
32 +## Code
33 +
34 +```javascript
35 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
36 +import { mutate } from "shared-runtime";
37 +
38 +function useFoo(props) {
39 + const $ = _c(2);
40 + let x;
41 + if ($[0] !== props) {
42 + x = [];
43 + x.push(props.bar);
44 + if (props.cond) {
45 + x = [];
46 + x.push(props.foo);
47 + }
48 +
49 + mutate(x);
50 + $[0] = props;
51 + $[1] = x;
52 + } else {
53 + x = $[1];
54 + }
55 + return x;
56 +}
57 +
58 +export const FIXTURE_ENTRYPOINT = {
59 + fn: useFoo,
60 + params: [{ bar: "bar", foo: "foo", cond: true }],
61 + sequentialRenders: [
62 + { bar: "bar", foo: "foo", cond: true },
63 + { bar: "bar", foo: "foo", cond: true },
64 + { bar: "bar", foo: "foo", cond: false },
65 + ],
66 +};
67 +
68 +```
69 +
70 +### Eval output
71 +(kind: ok) ["foo","joe"]
72 +["foo","joe"]
73 +["bar","joe"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/ssa-renaming-with-mutation.js new
+24
@@ -0,0 +1,24 @@
1 +// @enablePropagateDepsInHIR
2 +import {mutate} from 'shared-runtime';
3 +
4 +function useFoo(props) {
5 + let x = [];
6 + x.push(props.bar);
7 + if (props.cond) {
8 + x = {};
9 + x = [];
10 + x.push(props.foo);
11 + }
12 + mutate(x);
13 + return x;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: useFoo,
18 + params: [{bar: 'bar', foo: 'foo', cond: true}],
19 + sequentialRenders: [
20 + {bar: 'bar', foo: 'foo', cond: true},
21 + {bar: 'bar', foo: 'foo', cond: true},
22 + {bar: 'bar', foo: 'foo', cond: false},
23 + ],
24 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.expect.md new
+90
@@ -0,0 +1,90 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function Component(props) {
7 + let x = [];
8 + let y;
9 + switch (props.p0) {
10 + case 1: {
11 + break;
12 + }
13 + case true: {
14 + x.push(props.p2);
15 + y = [];
16 + }
17 + default: {
18 + break;
19 + }
20 + case false: {
21 + y = x;
22 + break;
23 + }
24 + }
25 + const child = <Component data={x} />;
26 + y.push(props.p4);
27 + return <Component data={y}>{child}</Component>;
28 +}
29 +
30 +```
31 +
32 +## Code
33 +
34 +```javascript
35 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
36 +function Component(props) {
37 + const $ = _c(7);
38 + let y;
39 + let t0;
40 + if ($[0] !== props) {
41 + const x = [];
42 + bb0: switch (props.p0) {
43 + case 1: {
44 + break bb0;
45 + }
46 + case true: {
47 + x.push(props.p2);
48 + let t1;
49 + if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
50 + t1 = [];
51 + $[3] = t1;
52 + } else {
53 + t1 = $[3];
54 + }
55 + y = t1;
56 + }
57 + default: {
58 + break bb0;
59 + }
60 + case false: {
61 + y = x;
62 + }
63 + }
64 +
65 + t0 = <Component data={x} />;
66 + $[0] = props;
67 + $[1] = y;
68 + $[2] = t0;
69 + } else {
70 + y = $[1];
71 + t0 = $[2];
72 + }
73 + const child = t0;
74 + y.push(props.p4);
75 + let t1;
76 + if ($[4] !== y || $[5] !== child) {
77 + t1 = <Component data={y}>{child}</Component>;
78 + $[4] = y;
79 + $[5] = child;
80 + $[6] = t1;
81 + } else {
82 + t1 = $[6];
83 + }
84 + return t1;
85 +}
86 +
87 +```
88 +
89 +### Eval output
90 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch-non-final-default.js new
+24
@@ -0,0 +1,24 @@
1 +// @enablePropagateDepsInHIR
2 +function Component(props) {
3 + let x = [];
4 + let y;
5 + switch (props.p0) {
6 + case 1: {
7 + break;
8 + }
9 + case true: {
10 + x.push(props.p2);
11 + y = [];
12 + }
13 + default: {
14 + break;
15 + }
16 + case false: {
17 + y = x;
18 + break;
19 + }
20 + }
21 + const child = <Component data={x} />;
22 + y.push(props.p4);
23 + return <Component data={y}>{child}</Component>;
24 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.expect.md new
+72
@@ -0,0 +1,72 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +function Component(props) {
7 + let x = [];
8 + let y;
9 + switch (props.p0) {
10 + case true: {
11 + x.push(props.p2);
12 + x.push(props.p3);
13 + y = [];
14 + }
15 + case false: {
16 + y = x;
17 + break;
18 + }
19 + }
20 + const child = <Component data={x} />;
21 + y.push(props.p4);
22 + return <Component data={y}>{child}</Component>;
23 +}
24 +
25 +```
26 +
27 +## Code
28 +
29 +```javascript
30 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
31 +function Component(props) {
32 + const $ = _c(6);
33 + let y;
34 + let t0;
35 + if ($[0] !== props) {
36 + const x = [];
37 + switch (props.p0) {
38 + case true: {
39 + x.push(props.p2);
40 + x.push(props.p3);
41 + }
42 + case false: {
43 + y = x;
44 + }
45 + }
46 +
47 + t0 = <Component data={x} />;
48 + $[0] = props;
49 + $[1] = y;
50 + $[2] = t0;
51 + } else {
52 + y = $[1];
53 + t0 = $[2];
54 + }
55 + const child = t0;
56 + y.push(props.p4);
57 + let t1;
58 + if ($[3] !== y || $[4] !== child) {
59 + t1 = <Component data={y}>{child}</Component>;
60 + $[3] = y;
61 + $[4] = child;
62 + $[5] = t1;
63 + } else {
64 + t1 = $[5];
65 + }
66 + return t1;
67 +}
68 +
69 +```
70 +
71 +### Eval output
72 +(kind: exception) Fixture not implemented
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/switch.js new
+19
@@ -0,0 +1,19 @@
1 +// @enablePropagateDepsInHIR
2 +function Component(props) {
3 + let x = [];
4 + let y;
5 + switch (props.p0) {
6 + case true: {
7 + x.push(props.p2);
8 + x.push(props.p3);
9 + y = [];
10 + }
11 + case false: {
12 + y = x;
13 + break;
14 + }
15 + }
16 + const child = <Component data={x} />;
17 + y.push(props.p4);
18 + return <Component data={y}>{child}</Component>;
19 +}
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.expect.md new
+64
@@ -0,0 +1,64 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +const {shallowCopy, throwErrorWithMessage} = require('shared-runtime');
7 +
8 +function Component(props) {
9 + const x = [];
10 + try {
11 + x.push(throwErrorWithMessage('oops'));
12 + } catch {
13 + x.push(shallowCopy({a: props.a}));
14 + }
15 + return x;
16 +}
17 +
18 +export const FIXTURE_ENTRYPOINT = {
19 + fn: Component,
20 + params: [{a: 1}],
21 +};
22 +
23 +```
24 +
25 +## Code
26 +
27 +```javascript
28 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
29 +const { shallowCopy, throwErrorWithMessage } = require("shared-runtime");
30 +
31 +function Component(props) {
32 + const $ = _c(3);
33 + let x;
34 + if ($[0] !== props.a) {
35 + x = [];
36 + try {
37 + let t0;
38 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
39 + t0 = throwErrorWithMessage("oops");
40 + $[2] = t0;
41 + } else {
42 + t0 = $[2];
43 + }
44 + x.push(t0);
45 + } catch {
46 + x.push(shallowCopy({ a: props.a }));
47 + }
48 + $[0] = props.a;
49 + $[1] = x;
50 + } else {
51 + x = $[1];
52 + }
53 + return x;
54 +}
55 +
56 +export const FIXTURE_ENTRYPOINT = {
57 + fn: Component,
58 + params: [{ a: 1 }],
59 +};
60 +
61 +```
62 +
63 +### Eval output
64 +(kind: ok) [{"a":1}]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-mutate-outer-value.js new
+17
@@ -0,0 +1,17 @@
1 +// @enablePropagateDepsInHIR
2 +const {shallowCopy, throwErrorWithMessage} = require('shared-runtime');
3 +
4 +function Component(props) {
5 + const x = [];
6 + try {
7 + x.push(throwErrorWithMessage('oops'));
8 + } catch {
9 + x.push(shallowCopy({a: props.a}));
10 + }
11 + return x;
12 +}
13 +
14 +export const FIXTURE_ENTRYPOINT = {
15 + fn: Component,
16 + params: [{a: 1}],
17 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.expect.md new
+64
@@ -0,0 +1,64 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +const {throwInput} = require('shared-runtime');
7 +
8 +function Component(props) {
9 + let x;
10 + try {
11 + const y = [];
12 + y.push(props.y);
13 + throwInput(y);
14 + } catch (e) {
15 + e.push(props.e);
16 + x = e;
17 + }
18 + return x;
19 +}
20 +
21 +export const FIXTURE_ENTRYPOINT = {
22 + fn: Component,
23 + params: [{y: 'foo', e: 'bar'}],
24 +};
25 +
26 +```
27 +
28 +## Code
29 +
30 +```javascript
31 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
32 +const { throwInput } = require("shared-runtime");
33 +
34 +function Component(props) {
35 + const $ = _c(3);
36 + let x;
37 + if ($[0] !== props.y || $[1] !== props.e) {
38 + try {
39 + const y = [];
40 + y.push(props.y);
41 + throwInput(y);
42 + } catch (t0) {
43 + const e = t0;
44 + e.push(props.e);
45 + x = e;
46 + }
47 + $[0] = props.y;
48 + $[1] = props.e;
49 + $[2] = x;
50 + } else {
51 + x = $[2];
52 + }
53 + return x;
54 +}
55 +
56 +export const FIXTURE_ENTRYPOINT = {
57 + fn: Component,
58 + params: [{ y: "foo", e: "bar" }],
59 +};
60 +
61 +```
62 +
63 +### Eval output
64 +(kind: ok) ["foo","bar"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch-escaping.js new
+20
@@ -0,0 +1,20 @@
1 +// @enablePropagateDepsInHIR
2 +const {throwInput} = require('shared-runtime');
3 +
4 +function Component(props) {
5 + let x;
6 + try {
7 + const y = [];
8 + y.push(props.y);
9 + throwInput(y);
10 + } catch (e) {
11 + e.push(props.e);
12 + x = e;
13 + }
14 + return x;
15 +}
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: Component,
19 + params: [{y: 'foo', e: 'bar'}],
20 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.expect.md new
+70
@@ -0,0 +1,70 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +const {throwInput} = require('shared-runtime');
7 +
8 +function Component(props) {
9 + try {
10 + const y = [];
11 + y.push(props.y);
12 + throwInput(y);
13 + } catch (e) {
14 + e.push(props.e);
15 + return e;
16 + }
17 + return null;
18 +}
19 +
20 +export const FIXTURE_ENTRYPOINT = {
21 + fn: Component,
22 + params: [{y: 'foo', e: 'bar'}],
23 +};
24 +
25 +```
26 +
27 +## Code
28 +
29 +```javascript
30 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
31 +const { throwInput } = require("shared-runtime");
32 +
33 +function Component(props) {
34 + const $ = _c(3);
35 + let t0;
36 + if ($[0] !== props.y || $[1] !== props.e) {
37 + t0 = Symbol.for("react.early_return_sentinel");
38 + bb0: {
39 + try {
40 + const y = [];
41 + y.push(props.y);
42 + throwInput(y);
43 + } catch (t1) {
44 + const e = t1;
45 + e.push(props.e);
46 + t0 = e;
47 + break bb0;
48 + }
49 + }
50 + $[0] = props.y;
51 + $[1] = props.e;
52 + $[2] = t0;
53 + } else {
54 + t0 = $[2];
55 + }
56 + if (t0 !== Symbol.for("react.early_return_sentinel")) {
57 + return t0;
58 + }
59 + return null;
60 +}
61 +
62 +export const FIXTURE_ENTRYPOINT = {
63 + fn: Component,
64 + params: [{ y: "foo", e: "bar" }],
65 +};
66 +
67 +```
68 +
69 +### Eval output
70 +(kind: ok) ["foo","bar"]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/try-catch-try-value-modified-in-catch.js new
+19
@@ -0,0 +1,19 @@
1 +// @enablePropagateDepsInHIR
2 +const {throwInput} = require('shared-runtime');
3 +
4 +function Component(props) {
5 + try {
6 + const y = [];
7 + y.push(props.y);
8 + throwInput(y);
9 + } catch (e) {
10 + e.push(props.e);
11 + return e;
12 + }
13 + return null;
14 +}
15 +
16 +export const FIXTURE_ENTRYPOINT = {
17 + fn: Component,
18 + params: [{y: 'foo', e: 'bar'}],
19 +};
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.expect.md new
+73
@@ -0,0 +1,73 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// @enablePropagateDepsInHIR
6 +import {useMemo} from 'react';
7 +
8 +function Component(props) {
9 + const x = useMemo(() => {
10 + let y = [];
11 + if (props.cond) {
12 + y.push(props.a);
13 + }
14 + if (props.cond2) {
15 + return y;
16 + }
17 + y.push(props.b);
18 + return y;
19 + });
20 + return x;
21 +}
22 +
23 +export const FIXTURE_ENTRYPOINT = {
24 + fn: Component,
25 + params: [{a: 1, b: 2, cond2: false}],
26 +};
27 +
28 +```
29 +
30 +## Code
31 +
32 +```javascript
33 +import { c as _c } from "react/compiler-runtime"; // @enablePropagateDepsInHIR
34 +import { useMemo } from "react";
35 +
36 +function Component(props) {
37 + const $ = _c(3);
38 + let t0;
39 + bb0: {
40 + let y;
41 + if ($[0] !== props) {
42 + y = [];
43 + if (props.cond) {
44 + y.push(props.a);
45 + }
46 + if (props.cond2) {
47 + t0 = y;
48 + break bb0;
49 + }
50 +
51 + y.push(props.b);
52 + $[0] = props;
53 + $[1] = y;
54 + $[2] = t0;
55 + } else {
56 + y = $[1];
57 + t0 = $[2];
58 + }
59 + t0 = y;
60 + }
61 + const x = t0;
62 + return x;
63 +}
64 +
65 +export const FIXTURE_ENTRYPOINT = {
66 + fn: Component,
67 + params: [{ a: 1, b: 2, cond2: false }],
68 +};
69 +
70 +```
71 +
72 +### Eval output
73 +(kind: ok) [2]
\ No newline at end of file
compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/propagate-scope-deps-hir-fork/useMemo-multiple-if-else.js new
+22
@@ -0,0 +1,22 @@
1 +// @enablePropagateDepsInHIR
2 +import {useMemo} from 'react';
3 +
4 +function Component(props) {
5 + const x = useMemo(() => {
6 + let y = [];
7 + if (props.cond) {
8 + y.push(props.a);
9 + }
10 + if (props.cond2) {
11 + return y;
12 + }
13 + y.push(props.b);
14 + return y;
15 + });
16 + return x;
17 +}
18 +
19 +export const FIXTURE_ENTRYPOINT = {
20 + fn: Component,
21 + params: [{a: 1, b: 2, cond2: false}],
22 +};