mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[compiler] Receiver is mutate? for functions wo signatures
[ghstack-poisoned]
This commit is contained in:
+15
-2
@@ -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) {
|
||||
|
||||
+54
@@ -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
|
||||
+11
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user