@samitouri / QOS-React-2 / commits / da6d372c3a

[hir] Store env in HIRFunction

The env is specific to the HIR function anwyays. It's not very useful outside the HIRFunction.

Sathya Gunasekaran committed Jan 19, 2023 at 18:39 UTC da6d372c3a834cb89bb23f31ec655536f4adf23a
4 files changed +9 -8
compiler/forget/src/CompilerPipeline.ts
+2 -4
@@ -42,9 +42,7 @@ export type CompilerPipelineValue =
42 export function* run(
43 func: NodePath<t.FunctionDeclaration>
44 ): Generator<CompilerPipelineValue, t.Function> {
45 - const env = new Environment();
46 -
47 - const lowering = lower(func, env).orElse((errors) => {
45 + const lowering = lower(func).orElse((errors) => {
46 const msg = errors.map((error) => error.toString()).join("\n\n");
47 throw new Error(msg);
48 });
@@ -55,7 +53,7 @@ export function* run(
53 mergeConsecutiveBlocks(hir);
54 yield log({ kind: "hir", name: "MergeConsecutiveBlocks", value: hir });
55
58 - enterSSA(hir, env);
56 + enterSSA(hir);
57 yield log({ kind: "hir", name: "SSA", value: hir });
58
59 eliminateRedundantPhi(hir);
compiler/forget/src/HIR/BuildHIR.ts
+3 -2
@@ -48,9 +48,9 @@ import HIRBuilder, { Environment } from "./HIRBuilder";
48 * grained reactivity.
49 */
50 export function lower(
51 - func: NodePath<t.Function>,
52 - env: Environment
51 + func: NodePath<t.Function>
52 ): Result<HIRFunction, CompilerError[]> {
53 + const env = new Environment();
54 const builder = new HIRBuilder(env);
55
56 const id =
@@ -106,6 +106,7 @@ export function lower(
106 generator: func.node.generator === true,
107 async: func.node.async === true,
108 loc: func.node.loc ?? GeneratedSource,
109 + env,
110 });
111 }
112
compiler/forget/src/HIR/HIR.ts
+2
@@ -7,6 +7,7 @@
7
8 import * as t from "@babel/types";
9 import invariant from "invariant";
10 +import { Environment } from "./HIRBuilder";
11
12 // *******************************************************************************************
13 // *******************************************************************************************
@@ -161,6 +162,7 @@ export type ReactiveIfTerminal = {
162 export type HIRFunction = {
163 loc: SourceLocation;
164 id: Identifier | null;
165 + env: Environment;
166 params: Array<Place>;
167 body: HIR;
168 generator: boolean;
compiler/forget/src/SSA/EnterSSA.ts
+2 -2
@@ -182,9 +182,9 @@ class SSABuilder {
182 }
183 }
184
185 -export default function enterSSA(func: HIRFunction, env: Environment) {
185 +export default function enterSSA(func: HIRFunction) {
186 const visitedBlocks: Set<BasicBlock> = new Set();
187 - const builder = new SSABuilder(env, func.body.blocks);
187 + const builder = new SSABuilder(func.env, func.body.blocks);
188 for (const [blockId, block] of func.body.blocks) {
189 invariant(
190 !visitedBlocks.has(block),