mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Rename feature flag for function expr optimization
This got lost in a rebase, just renaming for clarity.
This commit is contained in:
@@ -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<t.Identifier>;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)!;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// @enableCodegenLoweredFunctionExpressions
|
||||
// @enableOptimizeFunctionExpressions
|
||||
function Component(props) {
|
||||
const x = 42;
|
||||
const onEvent = () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user