@samitouri / QOS-React / commits / 8bf1ec97a4

Add flag back for inlineUseMemo

Reverts #1502, but flips test flags (e.g. `inlineUseMemo` by default, unless a test specifies `@inlineUseMemo false`. I figured this add less thrash for test fixtures, but happy to just do a clean revert (or remove the pragma altogether and always pass `inlineUseMemo: true`)

mofeiZ committed May 15, 2023 at 14:27 UTC 8bf1ec97a40e04a95dcc9bb1a576e707d8c585db
5 files changed +12 -3
compiler/forget/src/CompilerPipeline.ts
+4 -2
@@ -66,8 +66,10 @@ export function* run(
66 const hir = lower(func, env).unwrap();
67 yield log({ kind: "hir", name: "HIR", value: hir });
68
69 - inlineUseMemo(hir);
70 - yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
69 + if (config?.inlineUseMemo) {
70 + inlineUseMemo(hir);
71 + yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
72 + }
73
74 mergeConsecutiveBlocks(hir);
75 yield log({ kind: "hir", name: "MergeConsecutiveBlocks", value: hir });
compiler/forget/src/HIR/Environment.ts
+1
@@ -40,6 +40,7 @@ export type EnvironmentConfig = Partial<{
40 customHooks: Map<string, Hook>;
41 memoizeJsxElements: boolean;
42 validateHooksUsage: boolean;
43 + inlineUseMemo: boolean;
44 }>;
45
46 export class Environment {
compiler/forget/src/__tests__/compiler-test.ts
+1
@@ -56,6 +56,7 @@ describe("React Forget", () => {
56 ],
57 ]),
58 validateHooksUsage: true,
59 + inlineUseMemo: options.environment?.inlineUseMemo ?? false,
60 },
61 logger: null,
62 gating: options.gating,
compiler/forget/src/__tests__/disableMemoizeJsxElements-test.ts
+1
@@ -50,6 +50,7 @@ describe("React Forget (Disable memoization of JSX elements)", () => {
50 },
51 ],
52 ]),
53 + inlineUseMemo: options.environment?.inlineUseMemo ?? false,
54 },
55 logger: null,
56 gating: options.gating,
compiler/forget/src/__tests__/test-utils/generateTestsFromFixtures.ts
+5 -1
@@ -94,6 +94,7 @@ export default function generateTestsFromFixtures(
94 let debug = false;
95 let enableOnlyOnUseForgetDirective = false;
96 let gating: GatingOptions | null = null;
97 + let inlineUseMemo = true;
98 let panicOnBailout = true;
99
100 if (inputFile != null) {
@@ -117,6 +118,9 @@ export default function generateTestsFromFixtures(
118 importSpecifierName: "isForgetEnabled_Fixtures",
119 };
120 }
121 + if (lines[0]!.indexOf("@inlineUseMemo false") !== -1) {
122 + inlineUseMemo = false;
123 + }
124 if (lines[0]!.indexOf("@panicOnBailout false") !== -1) {
125 panicOnBailout = false;
126 }
@@ -126,7 +130,7 @@ export default function generateTestsFromFixtures(
130 let receivedOutput;
131 if (input !== null) {
132 receivedOutput = transform(input, basename, {
129 - environment: {},
133 + environment: { inlineUseMemo },
134 logger: null,
135 debug,
136 enableOnlyOnUseForgetDirective,