From 45216dc3d9112251feeaa1e981fe887156d5f83d Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Tue, 27 Feb 2024 11:39:22 -0800 Subject: [PATCH] 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. --- .../babel-plugin-react-forget/src/HIR/Environment.ts | 7 +++++++ .../src/ReactiveScopes/InferReactiveScopeVariables.ts | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts b/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts index bed0c5be76..e50486d2f4 100644 --- a/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts +++ b/compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts @@ -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; @@ -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); } diff --git a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts index c03dd726ae..436d3b48bf 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts @@ -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(),