@samitouri / QOS-React-2 / commits / 1607fb39c3

Repro for incorrect memoization of iife

We construct invalid mutable ranges in these cases because the range starts within a labeled block. We need to run merge consecutive scopes and EnterSSA after inlining so that the code is lifted out of the labeled block to the correct scope, and so that we create phis for reassignments within the IIFE.

Joe Savona committed Nov 6, 2023 at 08:33 UTC 1607fb39c3148eb1dc31005af4b07a7024954de3
4 files changed +126
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug.iife-return-modified-later-phi.expect.md new
+53
@@ -0,0 +1,53 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + const items = (() => {
7 + if (props.cond) {
8 + return [];
9 + } else {
10 + return null;
11 + }
12 + })();
13 + items.push(props.a);
14 + return items;
15 +}
16 +
17 +export const FIXTURE_ENTRYPOINT = {
18 + fn: Component,
19 + params: [{ a: {} }],
20 +};
21 +
22 +```
23 +
24 +## Code
25 +
26 +```javascript
27 +import { unstable_useMemoCache as useMemoCache } from "react";
28 +function Component(props) {
29 + const $ = useMemoCache(1);
30 + let t27;
31 + if (props.cond) {
32 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
33 + t27 = [];
34 + $[0] = t27;
35 + } else {
36 + t27 = $[0];
37 + }
38 + } else {
39 + t27 = null;
40 + }
41 + const items = t27;
42 +
43 + items.push(props.a);
44 + return items;
45 +}
46 +
47 +export const FIXTURE_ENTRYPOINT = {
48 + fn: Component,
49 + params: [{ a: {} }],
50 +};
51 +
52 +```
53 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug.iife-return-modified-later-phi.js new
+16
@@ -0,0 +1,16 @@
1 +function Component(props) {
2 + const items = (() => {
3 + if (props.cond) {
4 + return [];
5 + } else {
6 + return null;
7 + }
8 + })();
9 + items.push(props.a);
10 + return items;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: Component,
15 + params: [{ a: {} }],
16 +};
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug.iife-return-modified-later.expect.md new
+45
@@ -0,0 +1,45 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function Component(props) {
6 + const items = (() => {
7 + return [];
8 + })();
9 + items.push(props.a);
10 + return items;
11 +}
12 +
13 +export const FIXTURE_ENTRYPOINT = {
14 + fn: Component,
15 + params: [{ a: {} }],
16 +};
17 +
18 +```
19 +
20 +## Code
21 +
22 +```javascript
23 +import { unstable_useMemoCache as useMemoCache } from "react";
24 +function Component(props) {
25 + const $ = useMemoCache(1);
26 + let t17;
27 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
28 + t17 = [];
29 + $[0] = t17;
30 + } else {
31 + t17 = $[0];
32 + }
33 + const items = t17;
34 +
35 + items.push(props.a);
36 + return items;
37 +}
38 +
39 +export const FIXTURE_ENTRYPOINT = {
40 + fn: Component,
41 + params: [{ a: {} }],
42 +};
43 +
44 +```
45 +
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/bug.iife-return-modified-later.js new
+12
@@ -0,0 +1,12 @@
1 +function Component(props) {
2 + const items = (() => {
3 + return [];
4 + })();
5 + items.push(props.a);
6 + return items;
7 +}
8 +
9 +export const FIXTURE_ENTRYPOINT = {
10 + fn: Component,
11 + params: [{ a: {} }],
12 +};