[compiler] Receiver is mutate? for functions wo signatures

[ghstack-poisoned]
This commit is contained in:
Joe Savona
2025-05-29 17:30:51 -07:00
parent 126541bca8
commit 148aa1901f
3 changed files with 80 additions and 2 deletions
@@ -519,6 +519,9 @@ function applyEffect(
)
: null;
if (signatureEffects != null) {
if (DEBUG) {
console.log('apply aliasing signature effects');
}
for (const signatureEffect of signatureEffects) {
applyEffect(
state,
@@ -530,6 +533,9 @@ function applyEffect(
);
}
} else if (effect.signature != null) {
if (DEBUG) {
console.log('apply legacy signature effects');
}
const legacyEffects = computeEffectsForLegacySignature(
state,
effect.signature,
@@ -548,6 +554,9 @@ function applyEffect(
);
}
} else {
if (DEBUG) {
console.log('default effects');
}
applyEffect(
state,
{
@@ -567,7 +576,7 @@ function applyEffect(
* - All operands are captured into (but not directly aliased as)
* every other argument.
*/
for (const arg of [effect.function, ...effect.args]) {
for (const arg of [effect.receiver, effect.function, ...effect.args]) {
const operand = arg.kind === 'Identifier' ? arg : arg.place;
if (operand !== effect.function || effect.mutatesFunction) {
applyEffect(
@@ -599,7 +608,11 @@ function applyEffect(
aliased,
effects,
);
for (const otherArg of [effect.function, ...effect.args]) {
for (const otherArg of [
effect.receiver,
effect.function,
...effect.args,
]) {
const other =
otherArg.kind === 'Identifier' ? otherArg : otherArg.place;
if (other === arg) {
@@ -0,0 +1,54 @@
## Input
```javascript
// @enableNewMutationAliasingModel
function useHook({el1, el2}) {
const s = new Set();
const arr = makeArray(el1);
s.add(arr);
// Mutate after store
arr.push(el2);
s.add(makeArray(el2));
return s.size;
}
```
## Code
```javascript
import { c as _c } from "react/compiler-runtime"; // @enableNewMutationAliasingModel
function useHook(t0) {
const $ = _c(5);
const { el1, el2 } = t0;
let s;
if ($[0] !== el1 || $[1] !== el2) {
s = new Set();
const arr = makeArray(el1);
s.add(arr);
arr.push(el2);
let t1;
if ($[3] !== el2) {
t1 = makeArray(el2);
$[3] = el2;
$[4] = t1;
} else {
t1 = $[4];
}
s.add(t1);
$[0] = el1;
$[1] = el2;
$[2] = s;
} else {
s = $[2];
}
return s.size;
}
```
### Eval output
(kind: exception) Fixture not implemented
@@ -0,0 +1,11 @@
// @enableNewMutationAliasingModel
function useHook({el1, el2}) {
const s = new Set();
const arr = makeArray(el1);
s.add(arr);
// Mutate after store
arr.push(el2);
s.add(makeArray(el2));
return s.size;
}