Track next scope id on Environment
Currently we allocate all reactive scopes during a single pass, InferReactiveScopeVariables, using a local incrementing number to assign ScopeIds. This means we can't easily create additional scopes later since we don't know the next available scope id. Here we add `Environment.nextScopeId` and use that to synthesize scope ids.
Joe Savona committed
Feb 27, 2024 at 11:39 UTC
45216dc3d9112251feeaa1e981fe887156d5f83d
2 files changed
+8
-2
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+7
@@ -24,10 +24,12 @@ import {
24
FunctionType,
25
IdentifierId,
26
PolyType,
27
+ ScopeId,
28
Type,
29
ValueKind,
30
makeBlockId,
31
makeIdentifierId,
32
+ makeScopeId,
33
} from "./HIR";
34
import {
35
BuiltInMixedReadonlyId,
@@ -412,6 +414,7 @@ export class Environment {
414
#shapes: ShapeRegistry;
415
#nextIdentifer: number = 0;
416
#nextBlock: number = 0;
417
+ #nextScope: number = 0;
418
config: EnvironmentConfig;
419
420
#contextIdentifiers: Set<t.Identifier>;
@@ -460,6 +463,10 @@ export class Environment {
463
return makeBlockId(this.#nextBlock++);
464
}
465
466
+ get nextScopeId(): ScopeId {
467
+ return makeScopeId(this.#nextScope++);
468
+ }
469
+
470
isContextIdentifier(node: t.Identifier): boolean {
471
return this.#contextIdentifiers.has(node);
472
}
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts
+1
-2
@@ -12,7 +12,6 @@ import {
12
IdentifierId,
13
Instruction,
14
makeInstructionId,
15
- makeScopeId,
15
Place,
16
ReactiveScope,
17
} from "../HIR/HIR";
@@ -102,7 +101,7 @@ export function inferReactiveScopeVariables(fn: HIRFunction): void {
101
let scope = scopes.get(groupIdentifier);
102
if (scope === undefined) {
103
scope = {
105
- id: makeScopeId(scopes.size),
104
+ id: fn.env.nextScopeId,
105
range: identifier.mutableRange,
106
dependencies: new Set(),
107
declarations: new Map(),