From 459263b76320dabcc21cd6b523ea5b2440ba4e0b Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Wed, 14 Dec 2022 12:07:50 -0800 Subject: [PATCH] Refactor reactive scope representation --- compiler/forget/src/HIR/BuildReactiveFunction.ts | 8 +++----- compiler/forget/src/HIR/HIR.ts | 4 +--- compiler/forget/src/HIR/PrintReactiveFunction.ts | 6 +++--- compiler/forget/src/HIR/PropagateScopeDependencies.ts | 4 ++-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/compiler/forget/src/HIR/BuildReactiveFunction.ts b/compiler/forget/src/HIR/BuildReactiveFunction.ts index 2f3af91f55..7d30ba3d98 100644 --- a/compiler/forget/src/HIR/BuildReactiveFunction.ts +++ b/compiler/forget/src/HIR/BuildReactiveFunction.ts @@ -68,9 +68,7 @@ class Builder { startScope(scope: ReactiveScope): void { const block: ReactiveBlock = { kind: "block", - id: scope.id, - range: scope.range, - dependencies: scope.dependencies, + scope, instructions: [], }; this.append(block, undefined); @@ -80,8 +78,8 @@ class Builder { visitId(id: InstructionId): void { for (let i = 0; i < this.#stack.length; i++) { - const scope = this.#stack[i]!; - if (scope.kind === "scope" && id >= scope.block.range.end) { + const entry = this.#stack[i]!; + if (entry.kind === "scope" && id >= entry.block.scope.range.end) { this.#stack.length = i; break; } diff --git a/compiler/forget/src/HIR/HIR.ts b/compiler/forget/src/HIR/HIR.ts index a18985a17f..08f769e01f 100644 --- a/compiler/forget/src/HIR/HIR.ts +++ b/compiler/forget/src/HIR/HIR.ts @@ -52,9 +52,7 @@ export type ReactiveFunction = { export type ReactiveBlock = { kind: "block"; - id: ScopeId; - range: MutableRange; - dependencies: Set; + scope: ReactiveScope; instructions: ReactiveBasicBlock; }; diff --git a/compiler/forget/src/HIR/PrintReactiveFunction.ts b/compiler/forget/src/HIR/PrintReactiveFunction.ts index 80bfdd1f49..a51e4bbdc1 100644 --- a/compiler/forget/src/HIR/PrintReactiveFunction.ts +++ b/compiler/forget/src/HIR/PrintReactiveFunction.ts @@ -36,9 +36,9 @@ export function printReactiveFunction(fn: ReactiveFunction): string { export function printReactiveBlock(writer: Writer, block: ReactiveBlock): void { writer.writeLine( - `scope @${block.id} [${block.range.start}:${ - block.range.end - }] deps=[${Array.from(block.dependencies) + `scope @${block.scope.id} [${block.scope.range.start}:${ + block.scope.range.end + }] deps=[${Array.from(block.scope.dependencies) .map((dep) => printPlace(dep)) .join(", ")}] {` ); diff --git a/compiler/forget/src/HIR/PropagateScopeDependencies.ts b/compiler/forget/src/HIR/PropagateScopeDependencies.ts index 8f114bec3e..b96c6f38ff 100644 --- a/compiler/forget/src/HIR/PropagateScopeDependencies.ts +++ b/compiler/forget/src/HIR/PropagateScopeDependencies.ts @@ -64,9 +64,9 @@ function visit( item.instructions, scopeDependencies, scopeDeclarations, - item.range.start + item.scope.range.start ); - item.dependencies = scopeDependencies; + item.scope.dependencies = scopeDependencies; for (const dep of scopeDependencies) { // propagate dependencies upward using the same rules as // normal dependency collection. child scopes may have dependencies