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:
Lauren Tan
2022-12-20 11:42:51 -05:00
parent 7cf8e9ac42
commit 2721d2a0d9
4 changed files with 33 additions and 91 deletions
@@ -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"),
{
+1 -11
View File
@@ -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);
},
+30 -58
View File
@@ -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,
};
}
+1 -11
View File
@@ -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");