[hir] Store env in HIRFunction

The env is specific to the HIR function anwyays. It's not very useful outside 
the HIRFunction.
This commit is contained in:
Sathya Gunasekaran
2023-01-19 18:39:19 +00:00
parent 0a60bf2071
commit da6d372c3a
4 changed files with 9 additions and 8 deletions
+2 -4
View File
@@ -42,9 +42,7 @@ export type CompilerPipelineValue =
export function* run(
func: NodePath<t.FunctionDeclaration>
): Generator<CompilerPipelineValue, t.Function> {
const env = new Environment();
const lowering = lower(func, env).orElse((errors) => {
const lowering = lower(func).orElse((errors) => {
const msg = errors.map((error) => error.toString()).join("\n\n");
throw new Error(msg);
});
@@ -55,7 +53,7 @@ export function* run(
mergeConsecutiveBlocks(hir);
yield log({ kind: "hir", name: "MergeConsecutiveBlocks", value: hir });
enterSSA(hir, env);
enterSSA(hir);
yield log({ kind: "hir", name: "SSA", value: hir });
eliminateRedundantPhi(hir);
+3 -2
View File
@@ -48,9 +48,9 @@ import HIRBuilder, { Environment } from "./HIRBuilder";
* grained reactivity.
*/
export function lower(
func: NodePath<t.Function>,
env: Environment
func: NodePath<t.Function>
): Result<HIRFunction, CompilerError[]> {
const env = new Environment();
const builder = new HIRBuilder(env);
const id =
@@ -106,6 +106,7 @@ export function lower(
generator: func.node.generator === true,
async: func.node.async === true,
loc: func.node.loc ?? GeneratedSource,
env,
});
}
+2
View File
@@ -7,6 +7,7 @@
import * as t from "@babel/types";
import invariant from "invariant";
import { Environment } from "./HIRBuilder";
// *******************************************************************************************
// *******************************************************************************************
@@ -161,6 +162,7 @@ export type ReactiveIfTerminal = {
export type HIRFunction = {
loc: SourceLocation;
id: Identifier | null;
env: Environment;
params: Array<Place>;
body: HIR;
generator: boolean;
+2 -2
View File
@@ -182,9 +182,9 @@ class SSABuilder {
}
}
export default function enterSSA(func: HIRFunction, env: Environment) {
export default function enterSSA(func: HIRFunction) {
const visitedBlocks: Set<BasicBlock> = new Set();
const builder = new SSABuilder(env, func.body.blocks);
const builder = new SSABuilder(func.env, func.body.blocks);
for (const [blockId, block] of func.body.blocks) {
invariant(
!visitedBlocks.has(block),