mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Remove compiler flags
Remove our existing compiler flags since they were only being used for enabling/disabling passes to aid debugging and to simplify in preparation for the upcoming work on diagnostics and bailouts. Additionally with the new playground tabs disabling passes has become less necessary. In the future when we have actual compiler flags (eg tweaking optimization levels) we can add this back. I opted to keep the existing `CompilerResult` return value instead of just returning the optimized AST as we're still using `scopes` in our test fixtures.
This commit is contained in:
@@ -17,17 +17,7 @@ module.exports = (test) => {
|
||||
traverse(sourceAst, {
|
||||
FunctionDeclaration: {
|
||||
enter(nodePath) {
|
||||
const { ast } = run(nodePath, {
|
||||
eliminateRedundantPhi: true,
|
||||
inferReferenceEffects: true,
|
||||
inferTypes: true,
|
||||
inferMutableRanges: true,
|
||||
inferReactiveScopeVariables: true,
|
||||
inferReactiveScopes: true,
|
||||
inferReactiveScopeDependencies: true,
|
||||
leaveSSA: true,
|
||||
codegen: true,
|
||||
});
|
||||
const { ast } = run(nodePath);
|
||||
codegenText = prettier.format(
|
||||
generate(ast).code.replace("\n\n", "\n"),
|
||||
{
|
||||
|
||||
@@ -25,17 +25,7 @@ export default function (babel: typeof BabelCore): PluginObj {
|
||||
visitor: {
|
||||
FunctionDeclaration: {
|
||||
enter(fn, pass) {
|
||||
const { ast } = Pipeline(fn, {
|
||||
eliminateRedundantPhi: true,
|
||||
inferReferenceEffects: true,
|
||||
inferTypes: true,
|
||||
inferMutableRanges: true,
|
||||
inferReactiveScopeVariables: true,
|
||||
inferReactiveScopes: true,
|
||||
inferReactiveScopeDependencies: true,
|
||||
leaveSSA: true,
|
||||
codegen: true,
|
||||
});
|
||||
const { ast } = Pipeline(fn);
|
||||
invariant(ast !== null, "Expected ast to be present");
|
||||
fn.replaceWith(ast);
|
||||
},
|
||||
|
||||
@@ -27,27 +27,14 @@ import {
|
||||
import { eliminateRedundantPhi, enterSSA, leaveSSA } from "./SSA";
|
||||
import { logHIRFunction } from "./Utils/logger";
|
||||
|
||||
export type CompilerFlags = {
|
||||
eliminateRedundantPhi: boolean;
|
||||
inferReferenceEffects: boolean;
|
||||
inferTypes: boolean;
|
||||
inferMutableRanges: boolean;
|
||||
inferReactiveScopeVariables: boolean;
|
||||
inferReactiveScopes: boolean;
|
||||
inferReactiveScopeDependencies: boolean;
|
||||
leaveSSA: boolean;
|
||||
codegen: boolean;
|
||||
};
|
||||
|
||||
export type CompilerResult = {
|
||||
ir: HIRFunction;
|
||||
ast: t.Function | null;
|
||||
scopes: string | null;
|
||||
ast: t.Function;
|
||||
scopes: string;
|
||||
};
|
||||
|
||||
export default function (
|
||||
func: NodePath<t.FunctionDeclaration>,
|
||||
flags: CompilerFlags
|
||||
func: NodePath<t.FunctionDeclaration>
|
||||
): CompilerResult {
|
||||
const env = new Environment();
|
||||
|
||||
@@ -57,52 +44,37 @@ export default function (
|
||||
enterSSA(ir, env);
|
||||
logHIRFunction("SSA", ir);
|
||||
|
||||
if (flags.eliminateRedundantPhi) {
|
||||
eliminateRedundantPhi(ir);
|
||||
logHIRFunction("eliminateRedundantPhi", ir);
|
||||
}
|
||||
if (flags.inferTypes) {
|
||||
inferTypes(ir);
|
||||
logHIRFunction("inferTypes", ir);
|
||||
}
|
||||
if (flags.inferReferenceEffects) {
|
||||
inferReferenceEffects(ir);
|
||||
logHIRFunction("inferReferenceEffects", ir);
|
||||
}
|
||||
eliminateRedundantPhi(ir);
|
||||
logHIRFunction("eliminateRedundantPhi", ir);
|
||||
|
||||
if (flags.inferMutableRanges) {
|
||||
inferMutableRanges(ir);
|
||||
logHIRFunction("inferMutableRanges", ir);
|
||||
}
|
||||
inferTypes(ir);
|
||||
logHIRFunction("inferTypes", ir);
|
||||
|
||||
if (flags.leaveSSA) {
|
||||
leaveSSA(ir);
|
||||
logHIRFunction("leaveSSA", ir);
|
||||
}
|
||||
inferReferenceEffects(ir);
|
||||
logHIRFunction("inferReferenceEffects", ir);
|
||||
|
||||
if (flags.inferReactiveScopeVariables) {
|
||||
inferReactiveScopeVariables(ir);
|
||||
logHIRFunction("inferReactiveScopeVariables", ir);
|
||||
}
|
||||
inferMutableRanges(ir);
|
||||
logHIRFunction("inferMutableRanges", ir);
|
||||
|
||||
if (flags.inferReactiveScopes) {
|
||||
inferReactiveScopes(ir);
|
||||
logHIRFunction("inferReactiveScopes", ir);
|
||||
}
|
||||
leaveSSA(ir);
|
||||
logHIRFunction("leaveSSA", ir);
|
||||
|
||||
if (flags.codegen) {
|
||||
const reactiveFunction = buildReactiveFunction(ir);
|
||||
pruneUnusedLabels(reactiveFunction);
|
||||
flattenReactiveLoops(reactiveFunction);
|
||||
propagateScopeDependencies(reactiveFunction);
|
||||
const scopes = printReactiveFunction(reactiveFunction);
|
||||
const ast = codegenReactiveFunction(reactiveFunction);
|
||||
return {
|
||||
ast,
|
||||
ir,
|
||||
scopes,
|
||||
};
|
||||
}
|
||||
inferReactiveScopeVariables(ir);
|
||||
logHIRFunction("inferReactiveScopeVariables", ir);
|
||||
|
||||
return { ast: null, scopes: null, ir: ir };
|
||||
inferReactiveScopes(ir);
|
||||
logHIRFunction("inferReactiveScopes", ir);
|
||||
|
||||
const reactiveFunction = buildReactiveFunction(ir);
|
||||
pruneUnusedLabels(reactiveFunction);
|
||||
flattenReactiveLoops(reactiveFunction);
|
||||
propagateScopeDependencies(reactiveFunction);
|
||||
const scopes = printReactiveFunction(reactiveFunction);
|
||||
const ast = codegenReactiveFunction(reactiveFunction);
|
||||
|
||||
return {
|
||||
ast,
|
||||
ir,
|
||||
scopes,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -133,17 +133,7 @@ function transform(text: string, file: string): Array<TestOutput> {
|
||||
traverse(ast, {
|
||||
FunctionDeclaration: {
|
||||
enter(nodePath) {
|
||||
const { ir, scopes, ast } = run(nodePath, {
|
||||
eliminateRedundantPhi: true,
|
||||
inferReferenceEffects: true,
|
||||
inferTypes: true,
|
||||
inferMutableRanges: true,
|
||||
inferReactiveScopeVariables: true,
|
||||
inferReactiveScopes: true,
|
||||
inferReactiveScopeDependencies: true,
|
||||
leaveSSA: true,
|
||||
codegen: true,
|
||||
});
|
||||
const { ir, scopes, ast } = run(nodePath);
|
||||
|
||||
const textHIR = printFunction(ir);
|
||||
invariant(ast, "Expected an ast");
|
||||
|
||||
Reference in New Issue
Block a user