[compiler] Fix for PropertyStore object effect

Fix for the issue in the previous PR. Long-term the ideal thing would be to make InferMutableRanges smarter about Store effects, and recognize that they are also transitive mutations of whatever was captured into the object. So in the following:

```
const x = {y: {z: {}}};
x.y.z.key = value;
```

That the `PropertyStore z . 'key' = value` is a transitive mutation of x and all three object expressions (x, x.y, x.y.z).

But for now it's simpler to stick to the original idea of Store only counting if we know that the type is an object.

ghstack-source-id: fef41edcc5
Pull Request resolved: https://github.com/facebook/react/pull/33164
This commit is contained in:
Joe Savona committed 2025-06-09 11:10:18 -07:00
1 parent ac2c71e44d
commit 741854820f
3 files changed
+16 -35

No files matched your search

@@ -85,13 +85,13 @@ function inferAliasesForCapturing(
for (const block of fn.body.blocks.values()) {
for (const instr of block.instructions) {
const {lvalue, value} = instr;
const hasStore =
const hasCapture =
lvalue.effect === Effect.Store ||
Iterable_some(
eachInstructionValueOperand(value),
operand => operand.effect === Effect.Store,
operand => operand.effect === Effect.Capture,
);
if (!hasStore) {
if (!hasCapture) {
continue;
}
const operands: Array<Identifier> = [];
@@ -101,6 +101,7 @@ function inferAliasesForCapturing(
for (const operand of eachInstructionValueOperand(instr.value)) {
if (
operand.effect === Effect.Store ||
operand.effect === Effect.Mutate ||
operand.effect === Effect.Capture
) {
operands.push(operand.identifier);
@@ -32,6 +32,7 @@ import {
isMapType,
isMutableEffect,
isSetType,
isObjectType,
} from '../HIR/HIR';
import {FunctionSignature} from '../HIR/ObjectShape';
import {
@@ -1313,7 +1314,7 @@ function inferBlock(
state.referenceAndRecordEffects(
freezeActions,
instrValue.object,
typeof instrValue.property === 'string'
isObjectType(instrValue.object.identifier)
? Effect.Store
: Effect.Mutate,
ValueReason.Other,
@@ -1342,25 +1343,21 @@ function inferBlock(
state.referenceAndRecordEffects(
freezeActions,
instrValue.object,
Effect.Read,
Effect.Capture,
ValueReason.Other,
);
const lvalue = instr.lvalue;
lvalue.effect = Effect.ConditionallyMutate;
lvalue.effect = Effect.Store;
state.initialize(instrValue, state.kind(instrValue.object));
state.define(lvalue, instrValue);
continuation = {kind: 'funeffects'};
break;
}
case 'ComputedStore': {
const effect =
state.kind(instrValue.object).kind === ValueKind.Context
? Effect.ConditionallyMutate
: Effect.Capture;
state.referenceAndRecordEffects(
freezeActions,
instrValue.value,
effect,
Effect.Capture,
ValueReason.Other,
);
state.referenceAndRecordEffects(
@@ -1372,7 +1369,9 @@ function inferBlock(
state.referenceAndRecordEffects(
freezeActions,
instrValue.object,
Effect.Store,
isObjectType(instrValue.object.identifier)
? Effect.Store
: Effect.Mutate,
ValueReason.Other,
);
@@ -1409,7 +1408,7 @@ function inferBlock(
state.referenceAndRecordEffects(
freezeActions,
instrValue.object,
Effect.Read,
Effect.Capture,
ValueReason.Other,
);
state.referenceAndRecordEffects(
@@ -1419,7 +1418,7 @@ function inferBlock(
ValueReason.Other,
);
const lvalue = instr.lvalue;
lvalue.effect = Effect.ConditionallyMutate;
lvalue.effect = Effect.Store;
state.initialize(instrValue, state.kind(instrValue.object));
state.define(lvalue, instrValue);
continuation = {kind: 'funeffects'};
@@ -33,7 +33,7 @@ export const FIXTURE_ENTRYPOINT = {
```javascript
import { c as _c } from "react/compiler-runtime";
function Component(t0) {
const $ = _c(10);
const $ = _c(6);
const { a, b, c } = t0;
let t1;
if ($[0] !== a || $[1] !== b || $[2] !== c) {
@@ -47,26 +47,7 @@ function Component(t0) {
t2 = $[5];
}
const y = t2;
let t3;
let t4;
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
t3 = {};
t4 = {};
$[6] = t3;
$[7] = t4;
} else {
t3 = $[6];
t4 = $[7];
}
let t5;
if ($[8] !== c) {
t5 = { zero: c };
$[8] = c;
$[9] = t5;
} else {
t5 = $[9];
}
const z = { zero: t3, one: t4, two: t5 };
const z = { zero: {}, one: {}, two: { zero: c } };
x.zero = y.one;
z.zero.zero = x.zero;
t1 = { zero: x, one: z };