Skip to content

[compiler] Receiver is mutate? for functions wo signatures #33380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
148aa19
[compiler] Receiver is mutate? for functions wo signatures
josephsavona May 30, 2025
68fd43a
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona May 30, 2025
dbeedaf
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona May 30, 2025
a728be0
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona May 30, 2025
168b98d
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 2, 2025
79d60b2
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 3, 2025
393ce8e
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 3, 2025
2cd7013
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 4, 2025
5b31203
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 4, 2025
6099a7f
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 5, 2025
55760a9
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 5, 2025
e381b14
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 5, 2025
4ad0a4a
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 6, 2025
b3b15f4
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 6, 2025
5dd8204
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 6, 2025
b84e3de
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 6, 2025
060a264
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 7, 2025
8179b6b
Update on "[compiler] Receiver is mutate? for functions wo signatures"
josephsavona Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -548,6 +554,9 @@ function applyEffect(
);
}
} else {
if (DEBUG) {
console.log('default effects');
}
applyEffect(
state,
{
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
Loading