[be] Access all features flags through Environment

Most of our feature flags are accessed via the `Environment`, but a few cases 
have slipped in where we look at the `config` object directly. The problem is 
that the config object doesn't set defaults, so the check is effectively 
encoding what the default is. 

This PR moves to always accessing flags off of the environment, and adds a few 
flags that weren't yet defined there.
This commit is contained in:
Joe Savona
2023-10-03 11:46:33 -07:00
parent 0f97ea4c71
commit 9fc5e55b56
2 changed files with 22 additions and 4 deletions
@@ -86,13 +86,27 @@ export function* run(
): Generator<CompilerPipelineValue, CodegenFunction> {
const contextIdentifiers = findContextIdentifiers(func);
const env = new Environment(config ?? null, contextIdentifiers);
const ast = yield* runWithEnvironment(func, env);
return ast;
}
/**
* Note: this is split from run() to make `config` out of scope, so that all
* access to feature flags has to be through the Environment for consistency.
*/
function* runWithEnvironment(
func: NodePath<
t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
>,
env: Environment
): Generator<CompilerPipelineValue, CodegenFunction> {
const hir = lower(func, env).unwrap();
yield log({ kind: "hir", name: "HIR", value: hir });
pruneMaybeThrows(hir);
yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
if (config?.inlineUseMemo) {
if (env.inlineUseMemo) {
inlineUseMemo(hir);
yield log({ kind: "hir", name: "RewriteUseMemo", value: hir });
}
@@ -245,8 +259,8 @@ export function* run(
value: reactiveFunction,
});
let memoizeJsxElements = config?.memoizeJsxElements ?? true;
if (config?.enableForest) {
let memoizeJsxElements = env.memoizeJsxElements;
if (env.enableForest) {
memoizeJsxElements = false;
}
pruneNonEscapingScopes(reactiveFunction, { memoizeJsxElements });
@@ -279,7 +293,7 @@ export function* run(
});
}
if (config?.enableForest) {
if (env.enableForest) {
yield* lowerToForest(reactiveFunction);
}
@@ -258,6 +258,8 @@ export class Environment {
enableAssumeHooksFollowRulesOfReact: boolean;
enableTreatHooksAsFunctions: boolean;
enableNoAliasOptimizations: boolean;
inlineUseMemo: boolean;
memoizeJsxElements: boolean;
disableAllMemoization: boolean;
enableEmitFreeze: ExternalFunction | null;
enableMergeConsecutiveScopes: boolean;
@@ -320,6 +322,8 @@ export class Environment {
this.assertValidMutableRanges = config?.assertValidMutableRanges ?? false;
this.validateNoSetStateInRender =
config?.validateNoSetStateInRender ?? false;
this.inlineUseMemo = config?.inlineUseMemo ?? false;
this.memoizeJsxElements = config?.memoizeJsxElements ?? true;
this.bailoutOnHoleyArrays = config?.bailoutOnHoleyArrays ?? false;
this.enableForest = config?.enableForest ?? false;