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.
This commit is contained in:
Joe Savona
2024-02-27 11:39:22 -08:00
parent 130b809ac2
commit 45216dc3d9
2 changed files with 8 additions and 2 deletions
@@ -24,10 +24,12 @@ import {
FunctionType,
IdentifierId,
PolyType,
ScopeId,
Type,
ValueKind,
makeBlockId,
makeIdentifierId,
makeScopeId,
} from "./HIR";
import {
BuiltInMixedReadonlyId,
@@ -412,6 +414,7 @@ export class Environment {
#shapes: ShapeRegistry;
#nextIdentifer: number = 0;
#nextBlock: number = 0;
#nextScope: number = 0;
config: EnvironmentConfig;
#contextIdentifiers: Set<t.Identifier>;
@@ -460,6 +463,10 @@ export class Environment {
return makeBlockId(this.#nextBlock++);
}
get nextScopeId(): ScopeId {
return makeScopeId(this.#nextScope++);
}
isContextIdentifier(node: t.Identifier): boolean {
return this.#contextIdentifiers.has(node);
}
@@ -12,7 +12,6 @@ import {
IdentifierId,
Instruction,
makeInstructionId,
makeScopeId,
Place,
ReactiveScope,
} from "../HIR/HIR";
@@ -102,7 +101,7 @@ export function inferReactiveScopeVariables(fn: HIRFunction): void {
let scope = scopes.get(groupIdentifier);
if (scope === undefined) {
scope = {
id: makeScopeId(scopes.size),
id: fn.env.nextScopeId,
range: identifier.mutableRange,
dependencies: new Set(),
declarations: new Map(),