diff --git a/compiler/forget/src/CompilerPipeline.ts b/compiler/forget/src/CompilerPipeline.ts index 8d55b61c92..e78516d424 100644 --- a/compiler/forget/src/CompilerPipeline.ts +++ b/compiler/forget/src/CompilerPipeline.ts @@ -42,9 +42,7 @@ export type CompilerPipelineValue = export function* run( func: NodePath ): Generator { - 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); diff --git a/compiler/forget/src/HIR/BuildHIR.ts b/compiler/forget/src/HIR/BuildHIR.ts index b0b051d1a1..e44efa1507 100644 --- a/compiler/forget/src/HIR/BuildHIR.ts +++ b/compiler/forget/src/HIR/BuildHIR.ts @@ -48,9 +48,9 @@ import HIRBuilder, { Environment } from "./HIRBuilder"; * grained reactivity. */ export function lower( - func: NodePath, - env: Environment + func: NodePath ): Result { + 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, }); } diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index 26700e2755..185cc007f6 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -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; body: HIR; generator: boolean; diff --git a/compiler/forget/src/SSA/EnterSSA.ts b/compiler/forget/src/SSA/EnterSSA.ts index 443d802582..e35f3664a4 100644 --- a/compiler/forget/src/SSA/EnterSSA.ts +++ b/compiler/forget/src/SSA/EnterSSA.ts @@ -182,9 +182,9 @@ class SSABuilder { } } -export default function enterSSA(func: HIRFunction, env: Environment) { +export default function enterSSA(func: HIRFunction) { const visitedBlocks: Set = 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),