Refactor reactive scope representation

This commit is contained in:
Joe Savona
2022-12-14 12:07:50 -08:00
parent 552fe1878b
commit 459263b763
4 changed files with 9 additions and 13 deletions
@@ -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;
}
+1 -3
View File
@@ -52,9 +52,7 @@ export type ReactiveFunction = {
export type ReactiveBlock = {
kind: "block";
id: ScopeId;
range: MutableRange;
dependencies: Set<Place>;
scope: ReactiveScope;
instructions: ReactiveBasicBlock;
};
@@ -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(", ")}] {`
);
@@ -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