From 2721d2a0d975324a560230b97c7adf34f7e917bf Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Tue, 20 Dec 2022 11:42:51 -0500 Subject: [PATCH] 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. --- .../forget/scripts/test262-preprocessor.js | 12 +-- compiler/forget/src/Babel/BabelPlugin.ts | 12 +-- compiler/forget/src/CompilerPipeline.ts | 88 +++++++------------ compiler/forget/src/__tests__/hir-test.ts | 12 +-- 4 files changed, 33 insertions(+), 91 deletions(-) diff --git a/compiler/forget/scripts/test262-preprocessor.js b/compiler/forget/scripts/test262-preprocessor.js index 4028b8b8af..7b77b9012e 100644 --- a/compiler/forget/scripts/test262-preprocessor.js +++ b/compiler/forget/scripts/test262-preprocessor.js @@ -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"), { diff --git a/compiler/forget/src/Babel/BabelPlugin.ts b/compiler/forget/src/Babel/BabelPlugin.ts index 4ee836e403..1b13a6cb00 100644 --- a/compiler/forget/src/Babel/BabelPlugin.ts +++ b/compiler/forget/src/Babel/BabelPlugin.ts @@ -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); }, diff --git a/compiler/forget/src/CompilerPipeline.ts b/compiler/forget/src/CompilerPipeline.ts index 9203f5f420..75c1381aaa 100644 --- a/compiler/forget/src/CompilerPipeline.ts +++ b/compiler/forget/src/CompilerPipeline.ts @@ -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, - flags: CompilerFlags + func: NodePath ): 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, + }; } diff --git a/compiler/forget/src/__tests__/hir-test.ts b/compiler/forget/src/__tests__/hir-test.ts index 9778bc0ffe..a4cfd1e9a8 100644 --- a/compiler/forget/src/__tests__/hir-test.ts +++ b/compiler/forget/src/__tests__/hir-test.ts @@ -133,17 +133,7 @@ function transform(text: string, file: string): Array { 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");