diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts index e050182745..ce3e0fe515 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/Environment.ts @@ -158,7 +158,7 @@ export type EnvironmentConfig = Partial<{ * * Defaults to false (use the un-transformed function body). */ - enableCodegenLoweredFunctionExpressions: boolean; + enableOptimizeFunctionExpressions: boolean; }>; export class Environment { @@ -174,7 +174,7 @@ export class Environment { enableTreatHooksAsFunctions: boolean; disableAllMemoization: boolean; enableEmitFreeze: ExternalFunction | null; - enableCodegenLoweredFunctionExpressions: boolean; + enableOptimizeFunctionExpressions: boolean; #contextIdentifiers: Set; @@ -218,8 +218,8 @@ export class Environment { config?.enableTreatHooksAsFunctions ?? true; this.disableAllMemoization = config?.disableAllMemoization ?? false; this.enableEmitFreeze = config?.enableEmitFreeze ?? null; - this.enableCodegenLoweredFunctionExpressions = - config?.enableCodegenLoweredFunctionExpressions ?? false; + this.enableOptimizeFunctionExpressions = + config?.enableOptimizeFunctionExpressions ?? false; this.#contextIdentifiers = contextIdentifiers; } diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts index 75523b39f7..2c9a58106d 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/HIR/MergeConsecutiveBlocks.ts @@ -31,7 +31,7 @@ import { mapOptionalFallthroughs } from "./visitors"; export function mergeConsecutiveBlocks(fn: HIRFunction): void { const merged = new MergedBlocks(); for (const [, block] of fn.body.blocks) { - if (fn.env.enableCodegenLoweredFunctionExpressions) { + if (fn.env.enableOptimizeFunctionExpressions) { for (const instr of block.instructions) { if (instr.value.kind === "FunctionExpression") { mergeConsecutiveBlocks(instr.value.loweredFunc); diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts index e1693a89de..c1ffe8a9e5 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts @@ -90,7 +90,7 @@ export default function analyseFunctions(func: HIRFunction): void { } function lower(func: HIRFunction): void { - if (!func.env.enableCodegenLoweredFunctionExpressions) { + if (!func.env.enableOptimizeFunctionExpressions) { mergeConsecutiveBlocks(func); enterSSA(func); eliminateRedundantPhi(func); diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts b/compiler/forget/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts index c45b06b4fc..ecd9a548f1 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/Optimization/ConstantPropagation.ts @@ -144,7 +144,7 @@ function applyConstantPropagation( continue; } const instr = block.instructions[i]!; - if (!fn.env.enableCodegenLoweredFunctionExpressions) { + if (!fn.env.enableOptimizeFunctionExpressions) { // Don't propagate constants used as function expression dependencies if (functionDependencies.has(instr.lvalue.identifier.id)) { continue; @@ -360,7 +360,7 @@ function evaluateInstruction( return placeValue; } case "FunctionExpression": { - if (env.enableCodegenLoweredFunctionExpressions) { + if (env.enableOptimizeFunctionExpressions) { constantPropagationImpl(value.loweredFunc, constants); } return null; diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts b/compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts index 2a2c59ba64..a9a495d780 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/ReactiveScopes/CodegenReactiveFunction.ts @@ -960,7 +960,7 @@ function codegenInstructionValue( break; } case "FunctionExpression": { - if (cx.env.enableCodegenLoweredFunctionExpressions) { + if (cx.env.enableOptimizeFunctionExpressions) { const loweredFunc = instrValue.loweredFunc; deadCodeElimination(loweredFunc); const reactiveFunction = buildReactiveFunction(loweredFunc); diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EliminateRedundantPhi.ts b/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EliminateRedundantPhi.ts index a333ad7f4c..fc5c969c1e 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EliminateRedundantPhi.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EliminateRedundantPhi.ts @@ -102,7 +102,7 @@ export function eliminateRedundantPhi(fn: HIRFunction): void { if ( !hasBackEdge && instr.value.kind === "FunctionExpression" && - fn.env.enableCodegenLoweredFunctionExpressions + fn.env.enableOptimizeFunctionExpressions ) { eliminateRedundantPhi(instr.value.loweredFunc); } diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EnterSSA.ts b/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EnterSSA.ts index 679f854f7c..a89f7c089a 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EnterSSA.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/SSA/EnterSSA.ts @@ -248,7 +248,7 @@ function enterSSAImpl( if (blockId === rootEntry) { // NOTE: func.context should be empty for the root function - if (func.env.enableCodegenLoweredFunctionExpressions) { + if (func.env.enableOptimizeFunctionExpressions) { if (func.context.length !== 0) { CompilerError.invariant( `Expected function context to be empty for outer function declarations`, @@ -267,7 +267,7 @@ function enterSSAImpl( if ( instr.value.kind === "FunctionExpression" && - func.env.enableCodegenLoweredFunctionExpressions + func.env.enableOptimizeFunctionExpressions ) { const loweredFunc = instr.value.loweredFunc; const entry = loweredFunc.body.blocks.get(loweredFunc.body.entry)!; diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/TypeInference/InferTypes.ts b/compiler/forget/packages/babel-plugin-react-forget/src/TypeInference/InferTypes.ts index 29cbd7ed36..978cfba043 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/TypeInference/InferTypes.ts +++ b/compiler/forget/packages/babel-plugin-react-forget/src/TypeInference/InferTypes.ts @@ -70,7 +70,7 @@ function apply(func: HIRFunction, unifier: Unifier): void { if ( value.kind === "FunctionExpression" && - func.env.enableCodegenLoweredFunctionExpressions + func.env.enableOptimizeFunctionExpressions ) { apply(value.loweredFunc, unifier); } @@ -251,7 +251,7 @@ function* generateInstructionTypes( } case "FunctionExpression": { - if (env.enableCodegenLoweredFunctionExpressions) { + if (env.enableOptimizeFunctionExpressions) { yield* generate(value.loweredFunc); } break; diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md index 33e55ab569..edf5e08baa 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md +++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.expect.md @@ -2,7 +2,7 @@ ## Input ```javascript -// @enableCodegenLoweredFunctionExpressions +// @enableOptimizeFunctionExpressions function Component(props) { const x = 42; const onEvent = () => { @@ -16,7 +16,7 @@ function Component(props) { ## Code ```javascript -import { unstable_useMemoCache as useMemoCache } from "react"; // @enableCodegenLoweredFunctionExpressions +import { unstable_useMemoCache as useMemoCache } from "react"; // @enableOptimizeFunctionExpressions function Component(props) { const $ = useMemoCache(2); let t0; diff --git a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js index 3688a9c681..69de68c13f 100644 --- a/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js +++ b/compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/constant-propagation-into-function-expressions.js @@ -1,4 +1,4 @@ -// @enableCodegenLoweredFunctionExpressions +// @enableOptimizeFunctionExpressions function Component(props) { const x = 42; const onEvent = () => { diff --git a/compiler/forget/packages/snap/src/compiler-worker.ts b/compiler/forget/packages/snap/src/compiler-worker.ts index 41dcd97443..47578e4121 100644 --- a/compiler/forget/packages/snap/src/compiler-worker.ts +++ b/compiler/forget/packages/snap/src/compiler-worker.ts @@ -98,7 +98,7 @@ export async function compile( let disableAllMemoization = false; let validateRefAccessDuringRender = true; let enableEmitFreeze = null; - let enableCodegenLoweredFunctionExpressions = false; + let enableOptimizeFunctionExpressions = false; if (firstLine.indexOf("@forgetDirective") !== -1) { enableOnlyOnUseForgetDirective = true; } @@ -132,8 +132,8 @@ export async function compile( if (firstLine.includes("@validateRefAccessDuringRender false")) { validateRefAccessDuringRender = false; } - if (firstLine.includes("@enableCodegenLoweredFunctionExpressions")) { - enableCodegenLoweredFunctionExpressions = true; + if (firstLine.includes("@enableOptimizeFunctionExpressions")) { + enableOptimizeFunctionExpressions = true; } if (firstLine.includes("@enableEmitFreeze")) { enableEmitFreeze = { @@ -166,7 +166,7 @@ export async function compile( validateRefAccessDuringRender, validateFrozenLambdas: true, enableEmitFreeze, - enableCodegenLoweredFunctionExpressions, + enableOptimizeFunctionExpressions, }, logger: null, gating,