Refactor reactive scope representation
Joe Savona committed
Dec 14, 2022 at 12:07 UTC
459263b76320dabcc21cd6b523ea5b2440ba4e0b
4 files changed
+9
-13
compiler/forget/src/HIR/BuildReactiveFunction.ts
+3
-5
@@ -68,9 +68,7 @@ class Builder {
68
startScope(scope: ReactiveScope): void {
69
const block: ReactiveBlock = {
70
kind: "block",
71
- id: scope.id,
72
- range: scope.range,
73
- dependencies: scope.dependencies,
71
+ scope,
72
instructions: [],
73
};
74
this.append(block, undefined);
@@ -80,8 +78,8 @@ class Builder {
78
79
visitId(id: InstructionId): void {
80
for (let i = 0; i < this.#stack.length; i++) {
83
- const scope = this.#stack[i]!;
84
- if (scope.kind === "scope" && id >= scope.block.range.end) {
81
+ const entry = this.#stack[i]!;
82
+ if (entry.kind === "scope" && id >= entry.block.scope.range.end) {
83
this.#stack.length = i;
84
break;
85
}
compiler/forget/src/HIR/HIR.ts
+1
-3
@@ -52,9 +52,7 @@ export type ReactiveFunction = {
52
53
export type ReactiveBlock = {
54
kind: "block";
55
- id: ScopeId;
56
- range: MutableRange;
57
- dependencies: Set<Place>;
55
+ scope: ReactiveScope;
56
instructions: ReactiveBasicBlock;
57
};
58
compiler/forget/src/HIR/PrintReactiveFunction.ts
+3
-3
@@ -36,9 +36,9 @@ export function printReactiveFunction(fn: ReactiveFunction): string {
36
37
export function printReactiveBlock(writer: Writer, block: ReactiveBlock): void {
38
writer.writeLine(
39
- `scope @${block.id} [${block.range.start}:${
40
- block.range.end
41
- }] deps=[${Array.from(block.dependencies)
39
+ `scope @${block.scope.id} [${block.scope.range.start}:${
40
+ block.scope.range.end
41
+ }] deps=[${Array.from(block.scope.dependencies)
42
.map((dep) => printPlace(dep))
43
.join(", ")}] {`
44
);
compiler/forget/src/HIR/PropagateScopeDependencies.ts
+2
-2
@@ -64,9 +64,9 @@ function visit(
64
item.instructions,
65
scopeDependencies,
66
scopeDeclarations,
67
- item.range.start
67
+ item.scope.range.start
68
);
69
- item.dependencies = scopeDependencies;
69
+ item.scope.dependencies = scopeDependencies;
70
for (const dep of scopeDependencies) {
71
// propagate dependencies upward using the same rules as
72
// normal dependency collection. child scopes may have dependencies