@samitouri / QOS-React-2 / commits / 2721d2a0d9

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.

Lauren Tan committed Dec 20, 2022 at 11:42 UTC 2721d2a0d975324a560230b97c7adf34f7e917bf
4 files changed +33 -91
compiler/forget/scripts/test262-preprocessor.js
+1 -11
@@ -17,17 +17,7 @@ module.exports = (test) => {
17 traverse(sourceAst, {
18 FunctionDeclaration: {
19 enter(nodePath) {
20 - const { ast } = run(nodePath, {
21 - eliminateRedundantPhi: true,
22 - inferReferenceEffects: true,
23 - inferTypes: true,
24 - inferMutableRanges: true,
25 - inferReactiveScopeVariables: true,
26 - inferReactiveScopes: true,
27 - inferReactiveScopeDependencies: true,
28 - leaveSSA: true,
29 - codegen: true,
30 - });
20 + const { ast } = run(nodePath);
21 codegenText = prettier.format(
22 generate(ast).code.replace("\n\n", "\n"),
23 {
compiler/forget/src/Babel/BabelPlugin.ts
+1 -11
@@ -25,17 +25,7 @@ export default function (babel: typeof BabelCore): PluginObj {
25 visitor: {
26 FunctionDeclaration: {
27 enter(fn, pass) {
28 - const { ast } = Pipeline(fn, {
29 - eliminateRedundantPhi: true,
30 - inferReferenceEffects: true,
31 - inferTypes: true,
32 - inferMutableRanges: true,
33 - inferReactiveScopeVariables: true,
34 - inferReactiveScopes: true,
35 - inferReactiveScopeDependencies: true,
36 - leaveSSA: true,
37 - codegen: true,
38 - });
28 + const { ast } = Pipeline(fn);
29 invariant(ast !== null, "Expected ast to be present");
30 fn.replaceWith(ast);
31 },
compiler/forget/src/CompilerPipeline.ts
+30 -58
@@ -27,27 +27,14 @@ import {
27 import { eliminateRedundantPhi, enterSSA, leaveSSA } from "./SSA";
28 import { logHIRFunction } from "./Utils/logger";
29
30 -export type CompilerFlags = {
31 - eliminateRedundantPhi: boolean;
32 - inferReferenceEffects: boolean;
33 - inferTypes: boolean;
34 - inferMutableRanges: boolean;
35 - inferReactiveScopeVariables: boolean;
36 - inferReactiveScopes: boolean;
37 - inferReactiveScopeDependencies: boolean;
38 - leaveSSA: boolean;
39 - codegen: boolean;
40 -};
41 -
30 export type CompilerResult = {
31 ir: HIRFunction;
44 - ast: t.Function | null;
45 - scopes: string | null;
32 + ast: t.Function;
33 + scopes: string;
34 };
35
36 export default function (
49 - func: NodePath<t.FunctionDeclaration>,
50 - flags: CompilerFlags
37 + func: NodePath<t.FunctionDeclaration>
38 ): CompilerResult {
39 const env = new Environment();
40
@@ -57,52 +44,37 @@ export default function (
44 enterSSA(ir, env);
45 logHIRFunction("SSA", ir);
46
60 - if (flags.eliminateRedundantPhi) {
61 - eliminateRedundantPhi(ir);
62 - logHIRFunction("eliminateRedundantPhi", ir);
63 - }
64 - if (flags.inferTypes) {
65 - inferTypes(ir);
66 - logHIRFunction("inferTypes", ir);
67 - }
68 - if (flags.inferReferenceEffects) {
69 - inferReferenceEffects(ir);
70 - logHIRFunction("inferReferenceEffects", ir);
71 - }
47 + eliminateRedundantPhi(ir);
48 + logHIRFunction("eliminateRedundantPhi", ir);
49 +
50 + inferTypes(ir);
51 + logHIRFunction("inferTypes", ir);
52 +
53 + inferReferenceEffects(ir);
54 + logHIRFunction("inferReferenceEffects", ir);
55
73 - if (flags.inferMutableRanges) {
74 - inferMutableRanges(ir);
75 - logHIRFunction("inferMutableRanges", ir);
76 - }
56 + inferMutableRanges(ir);
57 + logHIRFunction("inferMutableRanges", ir);
58
78 - if (flags.leaveSSA) {
79 - leaveSSA(ir);
80 - logHIRFunction("leaveSSA", ir);
81 - }
59 + leaveSSA(ir);
60 + logHIRFunction("leaveSSA", ir);
61
83 - if (flags.inferReactiveScopeVariables) {
84 - inferReactiveScopeVariables(ir);
85 - logHIRFunction("inferReactiveScopeVariables", ir);
86 - }
62 + inferReactiveScopeVariables(ir);
63 + logHIRFunction("inferReactiveScopeVariables", ir);
64
88 - if (flags.inferReactiveScopes) {
89 - inferReactiveScopes(ir);
90 - logHIRFunction("inferReactiveScopes", ir);
91 - }
65 + inferReactiveScopes(ir);
66 + logHIRFunction("inferReactiveScopes", ir);
67
93 - if (flags.codegen) {
94 - const reactiveFunction = buildReactiveFunction(ir);
95 - pruneUnusedLabels(reactiveFunction);
96 - flattenReactiveLoops(reactiveFunction);
97 - propagateScopeDependencies(reactiveFunction);
98 - const scopes = printReactiveFunction(reactiveFunction);
99 - const ast = codegenReactiveFunction(reactiveFunction);
100 - return {
101 - ast,
102 - ir,
103 - scopes,
104 - };
105 - }
68 + const reactiveFunction = buildReactiveFunction(ir);
69 + pruneUnusedLabels(reactiveFunction);
70 + flattenReactiveLoops(reactiveFunction);
71 + propagateScopeDependencies(reactiveFunction);
72 + const scopes = printReactiveFunction(reactiveFunction);
73 + const ast = codegenReactiveFunction(reactiveFunction);
74
107 - return { ast: null, scopes: null, ir: ir };
75 + return {
76 + ast,
77 + ir,
78 + scopes,
79 + };
80 }
compiler/forget/src/__tests__/hir-test.ts
+1 -11
@@ -133,17 +133,7 @@ function transform(text: string, file: string): Array<TestOutput> {
133 traverse(ast, {
134 FunctionDeclaration: {
135 enter(nodePath) {
136 - const { ir, scopes, ast } = run(nodePath, {
137 - eliminateRedundantPhi: true,
138 - inferReferenceEffects: true,
139 - inferTypes: true,
140 - inferMutableRanges: true,
141 - inferReactiveScopeVariables: true,
142 - inferReactiveScopes: true,
143 - inferReactiveScopeDependencies: true,
144 - leaveSSA: true,
145 - codegen: true,
146 - });
136 + const { ir, scopes, ast } = run(nodePath);
137
138 const textHIR = printFunction(ir);
139 invariant(ast, "Expected an ast");