@samitouri / QOS-React-2 / commits / 32dccd48d2

[hir] Remove flag for inlineUseMemo

Joe Savona committed Apr 21, 2023 at 13:43 UTC 32dccd48d2c326a235e8af3cfbab949c1a13860c
29 files changed +17 -54
compiler/forget/src/CompilerPipeline.ts
+2 -4
@@ -61,10 +61,8 @@ export function* run(
61 const hir = lower(func, env).unwrap();
62 yield log({ kind: "hir", name: "HIR", value: hir });
63
64 - if (config?.inlineUseMemo) {
65 - inlineUseMemo(hir);
66 - yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
67 - }
64 + inlineUseMemo(hir);
65 + yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
66
67 mergeConsecutiveBlocks(hir);
68 yield log({ kind: "hir", name: "MergeConsecutiveBlocks", value: hir });
compiler/forget/src/HIR/Environment.ts
-1
@@ -40,7 +40,6 @@ const HOOK_PATTERN = /^_?use/;
40 export type EnvironmentConfig = Partial<{
41 customHooks: Map<string, Hook>;
42 memoizeJsxElements: boolean;
43 - inlineUseMemo: boolean;
43 }>;
44
45 export class Environment {
compiler/forget/src/__tests__/compiler-test.ts
-1
@@ -55,7 +55,6 @@ describe("React Forget", () => {
55 },
56 ],
57 ]),
58 - inlineUseMemo: options.environment?.inlineUseMemo ?? false,
58 },
59 logger: null,
60 gating: options.gating,
compiler/forget/src/__tests__/disableMemoizeJsxElements-test.ts
-1
@@ -50,7 +50,6 @@ describe("React Forget (Disable memoization of JSX elements)", () => {
50 },
51 ],
52 ]),
53 - inlineUseMemo: options.environment?.inlineUseMemo ?? false,
53 },
54 logger: null,
55 gating: options.gating,
compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-async-callback.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function component(a, b) {
6 let x = useMemo(async () => {
7 await a;
@@ -16,7 +15,7 @@ function component(a, b) {
15 ## Error
16
17 ```
19 -[ReactForget] Invariant: Did not expect useMemo callback to be async or a generator (3:5)
18 +[ReactForget] Invariant: Did not expect useMemo callback to be async or a generator (2:4)
19 ```
20
21
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-async-callback.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function component(a, b) {
2 let x = useMemo(async () => {
3 await a;
compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function component(a, b) {
6 let x = useMemo((c) => a, []);
7 return x;
@@ -14,7 +13,7 @@ function component(a, b) {
13 ## Error
14
15 ```
17 -[ReactForget] Invariant: Did not expect any arguments to useMemo callback (3:3)
16 +[ReactForget] Invariant: Did not expect any arguments to useMemo callback (2:2)
17 ```
18
19
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-args.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function component(a, b) {
2 let x = useMemo((c) => a, []);
3 return x;
compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-generator.expect.md
+7 -8
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function component(a, b) {
6 // we don't handle generators at all so this test isn't
7 // useful for now, but adding this test in case we do
@@ -20,13 +19,13 @@ function component(a, b) {
19
20 ```
21 [ReactForget] TodoError: (BuildHIR::lowerExpression) Handle YieldExpression expressions
23 - 5 | // add support for generators in the future.
24 - 6 | let x = useMemo(function* () {
25 -> 7 | yield a;
26 - | ^^^^^^^
27 - 8 | }, []);
28 - 9 | return x;
29 - 10 | }
22 + 4 | // add support for generators in the future.
23 + 5 | let x = useMemo(function* () {
24 +> 6 | yield a;
25 + | ^^^^^^^
26 + 7 | }, []);
27 + 8 | return x;
28 + 9 | }
29 ```
30
31
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/error.useMemo-callback-generator.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function component(a, b) {
2 // we don't handle generators at all so this test isn't
3 // useful for now, but adding this test in case we do
compiler/forget/src/__tests__/fixtures/compiler/useMemo-if-else-multiple-return.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function Component(props) {
6 const x = useMemo(() => {
7 if (props.cond) {
@@ -18,7 +17,7 @@ function Component(props) {
17 ## Code
18
19 ```javascript
21 -import * as React from "react"; // @inlineUseMemo
20 +import * as React from "react";
21 function Component(props) {
22 const $ = React.unstable_useMemoCache(4);
23 let t17 = undefined;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-if-else-multiple-return.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function Component(props) {
2 const x = useMemo(() => {
3 if (props.cond) {
compiler/forget/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function Component(props) {
6 const [a, b] = useMemo(() => {
7 const items = [];
@@ -18,7 +17,7 @@ function Component(props) {
17 ## Code
18
19 ```javascript
21 -import * as React from "react"; // @inlineUseMemo
20 +import * as React from "react";
21 function Component(props) {
22 const $ = React.unstable_useMemoCache(10);
23 const c_0 = $[0] !== props.a;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function Component(props) {
2 const [a, b] = useMemo(() => {
3 const items = [];
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function component(a, b) {
6 let x = useMemo(() => {
7 if (a) {
@@ -17,7 +16,7 @@ function component(a, b) {
16 ## Code
17
18 ```javascript
20 -import * as React from "react"; // @inlineUseMemo
19 +import * as React from "react";
20 function component(a, b) {
21 const $ = React.unstable_useMemoCache(2);
22 let t14 = undefined;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function component(a, b) {
2 let x = useMemo(() => {
3 if (a) {
compiler/forget/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.expect.md
-2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function Component(props) {
6 const x = useMemo(() => {
7 label: {
@@ -17,7 +16,6 @@ function Component(props) {
16 ## Code
17
18 ```javascript
20 -// @inlineUseMemo
19 function Component(props) {
20 const t9 = props.value;
21 const x = t9;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function Component(props) {
2 const x = useMemo(() => {
3 label: {
compiler/forget/src/__tests__/fixtures/compiler/useMemo-logical.expect.md
-2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function Component(props) {
6 const x = useMemo(() => props.a && props.b);
7 return x;
@@ -13,7 +12,6 @@ function Component(props) {
12 ## Code
13
14 ```javascript
16 -// @inlineUseMemo
15 function Component(props) {
16 const t15 = props.a && props.b;
17 const x = t15;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-logical.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function Component(props) {
2 const x = useMemo(() => props.a && props.b);
3 return x;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function Component(props) {
6 const x = useMemo(() => {
7 let y = [];
@@ -23,7 +22,7 @@ function Component(props) {
22 ## Code
23
24 ```javascript
26 -import * as React from "react"; // @inlineUseMemo
25 +import * as React from "react";
26 function Component(props) {
27 const $ = React.unstable_useMemoCache(2);
28 const c_0 = $[0] !== props;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function Component(props) {
2 const x = useMemo(() => {
3 let y = [];
compiler/forget/src/__tests__/fixtures/compiler/useMemo-return-empty.expect.md
-2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function component(a) {
6 let x = useMemo(() => {
7 mutate(a);
@@ -15,7 +14,6 @@ function component(a) {
14 ## Code
15
16 ```javascript
18 -// @inlineUseMemo
17 function component(a) {
18 mutate(a);
19 }
compiler/forget/src/__tests__/fixtures/compiler/useMemo-return-empty.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function component(a) {
2 let x = useMemo(() => {
3 mutate(a);
compiler/forget/src/__tests__/fixtures/compiler/useMemo-simple.expect.md
+1 -2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function component(a) {
6 let x = useMemo(() => [a], [a]);
7 return <Foo x={x}></Foo>;
@@ -13,7 +12,7 @@ function component(a) {
12 ## Code
13
14 ```javascript
16 -import * as React from "react"; // @inlineUseMemo
15 +import * as React from "react";
16 function component(a) {
17 const $ = React.unstable_useMemoCache(4);
18 const c_0 = $[0] !== a;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-simple.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function component(a) {
2 let x = useMemo(() => [a], [a]);
3 return <Foo x={x}></Foo>;
compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md
-2
@@ -2,7 +2,6 @@
2 ## Input
3
4 ```javascript
5 -// @inlineUseMemo
5 function Component(props) {
6 const x = useMemo(() => {
7 switch (props.key) {
@@ -22,7 +21,6 @@ function Component(props) {
21 ## Code
22
23 ```javascript
25 -// @inlineUseMemo
24 function Component(props) {
25 let t14 = undefined;
26 bb8: switch (props.key) {
compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.js
-1
@@ -1,4 +1,3 @@
1 -// @inlineUseMemo
1 function Component(props) {
2 const x = useMemo(() => {
3 switch (props.key) {
compiler/forget/src/__tests__/test-utils/generateTestsFromFixtures.ts
+1 -5
@@ -91,7 +91,6 @@ export default function generateTestsFromFixtures(
91 let debug = false;
92 let enableOnlyOnUseForgetDirective = false;
93 let gating: GatingOptions | null = null;
94 - let inlineUseMemo = true;
94 let panicOnBailout = true;
95
96 if (inputFile != null) {
@@ -113,9 +112,6 @@ export default function generateTestsFromFixtures(
112 importSpecifierName: "isForgetEnabled_Fixtures",
113 };
114 }
116 - if (lines[0]!.indexOf("@inlineUseMemo") !== -1) {
117 - inlineUseMemo = true;
118 - }
115 if (lines[0]!.indexOf("@panicOnBailout false") !== -1) {
116 panicOnBailout = false;
117 }
@@ -125,7 +121,7 @@ export default function generateTestsFromFixtures(
121 let receivedOutput;
122 if (input !== null) {
123 receivedOutput = transform(input, basename, {
128 - environment: { inlineUseMemo },
124 + environment: {},
125 logger: null,
126 debug,
127 enableOnlyOnUseForgetDirective,