From d3589367b03356b1032679a3331343cc7c49323c Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Fri, 23 Feb 2024 14:41:27 -0800 Subject: [PATCH] Handle scopes with reassignment (by expanding scopes to avoid it) --- .../InferReactiveScopeVariables.ts | 22 ++++++++++++++++++- .../packages/sprout/src/SproutTodoFilter.ts | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 857e262bc7..fef7452cea 100644 --- a/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts +++ b/compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts @@ -9,6 +9,7 @@ import { Environment } from "../HIR"; import { HIRFunction, Identifier, + IdentifierId, Instruction, makeInstructionId, makeScopeId, @@ -190,6 +191,10 @@ export function findDisjointMutableValues( fn: HIRFunction ): DisjointSet { const scopeIdentifiers = new DisjointSet(); + const declarations: Map | null = fn.env.config + .enableForest + ? new Map() + : null; for (const [_, block] of fn.body.blocks) { /* * If a phi is mutated after creation, then we need to alias all of its operands such that they @@ -218,7 +223,14 @@ export function findDisjointMutableValues( if (range.end > range.start + 1 || mayAllocate(fn.env, instr)) { operands.push(instr.lvalue!.identifier); } - if ( + if (instr.value.kind === "DeclareLocal") { + if (declarations !== null) { + declarations.set( + instr.value.lvalue.place.identifier.id, + instr.value.lvalue.place + ); + } + } else if ( instr.value.kind === "StoreLocal" || instr.value.kind === "StoreContext" ) { @@ -234,6 +246,14 @@ export function findDisjointMutableValues( ) { operands.push(instr.value.value.identifier); } + if (declarations !== null) { + const declaration = declarations.get( + instr.value.lvalue.place.identifier.id + ); + if (declaration !== undefined) { + operands.push(declaration.identifier); + } + } } else if (instr.value.kind === "Destructure") { for (const place of eachPatternOperand(instr.value.lvalue.pattern)) { if ( diff --git a/compiler/packages/sprout/src/SproutTodoFilter.ts b/compiler/packages/sprout/src/SproutTodoFilter.ts index f8f6e5d9fb..de8d05cbb6 100644 --- a/compiler/packages/sprout/src/SproutTodoFilter.ts +++ b/compiler/packages/sprout/src/SproutTodoFilter.ts @@ -440,6 +440,8 @@ const skipFilter = new Set([ "forest/forest-hook.flow", "forest/access-property-of-non-escaping-value", "forest/forest-TasksApp.flow", + "forest/forest-overwritten-let-binding-type-annotation.flow", + "forest/forest-phi-type-unused-initializer.flow", // TODO: we probably want to always skip these "rules-of-hooks/rules-of-hooks-0592bd574811",