Rename feature flag for function expr optimization
This got lost in a rebase, just renaming for clarity.
Joe Savona committed
Jun 12, 2023 at 15:56 UTC
8fcceb715ce1dbbf4ef9a11e84972d449fc5545c
11 files changed
+21
-21
compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+4
-4
@@ -158,7 +158,7 @@ export type EnvironmentConfig = Partial<{
158
*
159
* Defaults to false (use the un-transformed function body).
160
*/
161
- enableCodegenLoweredFunctionExpressions: boolean;
161
+ enableOptimizeFunctionExpressions: boolean;
162
}>;
163
164
export class Environment {
@@ -174,7 +174,7 @@ export class Environment {
174
enableTreatHooksAsFunctions: boolean;
175
disableAllMemoization: boolean;
176
enableEmitFreeze: ExternalFunction | null;
177
- enableCodegenLoweredFunctionExpressions: boolean;
177
+ enableOptimizeFunctionExpressions: boolean;
178
179
#contextIdentifiers: Set<t.Identifier>;
180
@@ -218,8 +218,8 @@ export class Environment {
218
config?.enableTreatHooksAsFunctions ?? true;
219
this.disableAllMemoization = config?.disableAllMemoization ?? false;
220
this.enableEmitFreeze = config?.enableEmitFreeze ?? null;
221
- this.enableCodegenLoweredFunctionExpressions =
222
- config?.enableCodegenLoweredFunctionExpressions ?? false;
221
+ this.enableOptimizeFunctionExpressions =
222
+ config?.enableOptimizeFunctionExpressions ?? false;
223
224
this.#contextIdentifiers = contextIdentifiers;
225
}
compiler/forget/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts
+1
-1
@@ -31,7 +31,7 @@ import { mapOptionalFallthroughs } from "./visitors";
31
export function mergeConsecutiveBlocks(fn: HIRFunction): void {
32
const merged = new MergedBlocks();
33
for (const [, block] of fn.body.blocks) {
34
- if (fn.env.enableCodegenLoweredFunctionExpressions) {
34
+ if (fn.env.enableOptimizeFunctionExpressions) {
35
for (const instr of block.instructions) {
36
if (instr.value.kind === "FunctionExpression") {
37
mergeConsecutiveBlocks(instr.value.loweredFunc);
compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts
+1
-1
@@ -90,7 +90,7 @@ export default function analyseFunctions(func: HIRFunction): void {
90
}
91
92
function lower(func: HIRFunction): void {
93
- if (!func.env.enableCodegenLoweredFunctionExpressions) {
93
+ if (!func.env.enableOptimizeFunctionExpressions) {
94
mergeConsecutiveBlocks(func);
95
enterSSA(func);
96
eliminateRedundantPhi(func);
compiler/forget/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts
+2
-2
@@ -144,7 +144,7 @@ function applyConstantPropagation(
144
continue;
145
}
146
const instr = block.instructions[i]!;
147
- if (!fn.env.enableCodegenLoweredFunctionExpressions) {
147
+ if (!fn.env.enableOptimizeFunctionExpressions) {
148
// Don't propagate constants used as function expression dependencies
149
if (functionDependencies.has(instr.lvalue.identifier.id)) {
150
continue;
@@ -360,7 +360,7 @@ function evaluateInstruction(
360
return placeValue;
361
}
362
case "FunctionExpression": {
363
- if (env.enableCodegenLoweredFunctionExpressions) {
363
+ if (env.enableOptimizeFunctionExpressions) {
364
constantPropagationImpl(value.loweredFunc, constants);
365
}
366
return null;
compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts
+1
-1
@@ -960,7 +960,7 @@ function codegenInstructionValue(
960
break;
961
}
962
case "FunctionExpression": {
963
- if (cx.env.enableCodegenLoweredFunctionExpressions) {
963
+ if (cx.env.enableOptimizeFunctionExpressions) {
964
const loweredFunc = instrValue.loweredFunc;
965
deadCodeElimination(loweredFunc);
966
const reactiveFunction = buildReactiveFunction(loweredFunc);
compiler/forget/packages/babel-plugin-react-forget/src/SSA/EliminateRedundantPhi.ts
+1
-1
@@ -102,7 +102,7 @@ export function eliminateRedundantPhi(fn: HIRFunction): void {
102
if (
103
!hasBackEdge &&
104
instr.value.kind === "FunctionExpression" &&
105
- fn.env.enableCodegenLoweredFunctionExpressions
105
+ fn.env.enableOptimizeFunctionExpressions
106
) {
107
eliminateRedundantPhi(instr.value.loweredFunc);
108
}
compiler/forget/packages/babel-plugin-react-forget/src/SSA/EnterSSA.ts
+2
-2
@@ -248,7 +248,7 @@ function enterSSAImpl(
248
249
if (blockId === rootEntry) {
250
// NOTE: func.context should be empty for the root function
251
- if (func.env.enableCodegenLoweredFunctionExpressions) {
251
+ if (func.env.enableOptimizeFunctionExpressions) {
252
if (func.context.length !== 0) {
253
CompilerError.invariant(
254
`Expected function context to be empty for outer function declarations`,
@@ -267,7 +267,7 @@ function enterSSAImpl(
267
268
if (
269
instr.value.kind === "FunctionExpression" &&
270
- func.env.enableCodegenLoweredFunctionExpressions
270
+ func.env.enableOptimizeFunctionExpressions
271
) {
272
const loweredFunc = instr.value.loweredFunc;
273
const entry = loweredFunc.body.blocks.get(loweredFunc.body.entry)!;
compiler/forget/packages/babel-plugin-react-forget/src/TypeInference/InferTypes.ts
+2
-2
@@ -70,7 +70,7 @@ function apply(func: HIRFunction, unifier: Unifier): void {
70
71
if (
72
value.kind === "FunctionExpression" &&
73
- func.env.enableCodegenLoweredFunctionExpressions
73
+ func.env.enableOptimizeFunctionExpressions
74
) {
75
apply(value.loweredFunc, unifier);
76
}
@@ -251,7 +251,7 @@ function* generateInstructionTypes(
251
}
252
253
case "FunctionExpression": {
254
- if (env.enableCodegenLoweredFunctionExpressions) {
254
+ if (env.enableOptimizeFunctionExpressions) {
255
yield* generate(value.loweredFunc);
256
}
257
break;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md
+2
-2
@@ -2,7 +2,7 @@
2
## Input
3
4
```javascript
5
-// @enableCodegenLoweredFunctionExpressions
5
+// @enableOptimizeFunctionExpressions
6
function Component(props) {
7
const x = 42;
8
const onEvent = () => {
@@ -16,7 +16,7 @@ function Component(props) {
16
## Code
17
18
```javascript
19
-import { unstable_useMemoCache as useMemoCache } from "react"; // @enableCodegenLoweredFunctionExpressions
19
+import { unstable_useMemoCache as useMemoCache } from "react"; // @enableOptimizeFunctionExpressions
20
function Component(props) {
21
const $ = useMemoCache(2);
22
let t0;
compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js
+1
-1
@@ -1,4 +1,4 @@
1
-// @enableCodegenLoweredFunctionExpressions
1
+// @enableOptimizeFunctionExpressions
2
function Component(props) {
3
const x = 42;
4
const onEvent = () => {
compiler/forget/packages/snap/src/compiler-worker.ts
+4
-4
@@ -98,7 +98,7 @@ export async function compile(
98
let disableAllMemoization = false;
99
let validateRefAccessDuringRender = true;
100
let enableEmitFreeze = null;
101
- let enableCodegenLoweredFunctionExpressions = false;
101
+ let enableOptimizeFunctionExpressions = false;
102
if (firstLine.indexOf("@forgetDirective") !== -1) {
103
enableOnlyOnUseForgetDirective = true;
104
}
@@ -132,8 +132,8 @@ export async function compile(
132
if (firstLine.includes("@validateRefAccessDuringRender false")) {
133
validateRefAccessDuringRender = false;
134
}
135
- if (firstLine.includes("@enableCodegenLoweredFunctionExpressions")) {
136
- enableCodegenLoweredFunctionExpressions = true;
135
+ if (firstLine.includes("@enableOptimizeFunctionExpressions")) {
136
+ enableOptimizeFunctionExpressions = true;
137
}
138
if (firstLine.includes("@enableEmitFreeze")) {
139
enableEmitFreeze = {
@@ -166,7 +166,7 @@ export async function compile(
166
validateRefAccessDuringRender,
167
validateFrozenLambdas: true,
168
enableEmitFreeze,
169
- enableCodegenLoweredFunctionExpressions,
169
+ enableOptimizeFunctionExpressions,
170
},
171
logger: null,
172
gating,