Handle scopes with reassignment (by expanding scopes to avoid it)
Joe Savona committed
Feb 23, 2024 at 14:41 UTC
d3589367b03356b1032679a3331343cc7c49323c
2 files changed
+23
-1
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/InferReactiveScopeVariables.ts
+21
-1
@@ -9,6 +9,7 @@ import { Environment } from "../HIR";
9
import {
10
HIRFunction,
11
Identifier,
12
+ IdentifierId,
13
Instruction,
14
makeInstructionId,
15
makeScopeId,
@@ -190,6 +191,10 @@ export function findDisjointMutableValues(
191
fn: HIRFunction
192
): DisjointSet<Identifier> {
193
const scopeIdentifiers = new DisjointSet<Identifier>();
194
+ const declarations: Map<IdentifierId, Place> | null = fn.env.config
195
+ .enableForest
196
+ ? new Map()
197
+ : null;
198
for (const [_, block] of fn.body.blocks) {
199
/*
200
* 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(
223
if (range.end > range.start + 1 || mayAllocate(fn.env, instr)) {
224
operands.push(instr.lvalue!.identifier);
225
}
221
- if (
226
+ if (instr.value.kind === "DeclareLocal") {
227
+ if (declarations !== null) {
228
+ declarations.set(
229
+ instr.value.lvalue.place.identifier.id,
230
+ instr.value.lvalue.place
231
+ );
232
+ }
233
+ } else if (
234
instr.value.kind === "StoreLocal" ||
235
instr.value.kind === "StoreContext"
236
) {
@@ -234,6 +246,14 @@ export function findDisjointMutableValues(
246
) {
247
operands.push(instr.value.value.identifier);
248
}
249
+ if (declarations !== null) {
250
+ const declaration = declarations.get(
251
+ instr.value.lvalue.place.identifier.id
252
+ );
253
+ if (declaration !== undefined) {
254
+ operands.push(declaration.identifier);
255
+ }
256
+ }
257
} else if (instr.value.kind === "Destructure") {
258
for (const place of eachPatternOperand(instr.value.lvalue.pattern)) {
259
if (
compiler/packages/sprout/src/SproutTodoFilter.ts
+2
@@ -440,6 +440,8 @@ const skipFilter = new Set([
440
"forest/forest-hook.flow",
441
"forest/access-property-of-non-escaping-value",
442
"forest/forest-TasksApp.flow",
443
+ "forest/forest-overwritten-let-binding-type-annotation.flow",
444
+ "forest/forest-phi-type-unused-initializer.flow",
445
446
// TODO: we probably want to always skip these
447
"rules-of-hooks/rules-of-hooks-0592bd574811",