Skip to content

Mirror of upstream PR #33114 #19

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
18e4165
[compiler] Repro for false positive ValidateNoFreezingKnownMutableFun…
josephsavona May 3, 2025
0ee6891
Update on "[compiler] Repro for false positive ValidateNoFreezingKnow…
josephsavona May 3, 2025
e9b19a6
[compiler] Correctly infer context mutation places as outer (context)…
josephsavona May 3, 2025
15307de
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 8, 2025
3d646a8
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 8, 2025
b7e8185
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 8, 2025
e5a4c87
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 8, 2025
04aeca7
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 8, 2025
3f81334
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 8, 2025
480f2cb
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 8, 2025
0a366ed
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 8, 2025
c474155
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 9, 2025
3c7ed29
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 9, 2025
3e69565
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 9, 2025
601c904
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 9, 2025
c27becf
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 9, 2025
b32b3b8
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 9, 2025
52968fa
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 9, 2025
c2c343e
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 9, 2025
d88aa65
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 9, 2025
fbe597d
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 9, 2025
9ca91aa
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 12, 2025
3c0908a
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 12, 2025
8e202cf
Update base for Update on "[compiler] Correctly infer context mutatio…
josephsavona May 13, 2025
dd775b1
Update on "[compiler] Correctly infer context mutation places as oute…
josephsavona May 13, 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 @@ -37,7 +37,7 @@ import {
import {FunctionSignature} from '../HIR/ObjectShape';
import {
printIdentifier,
printMixedHIR,
printInstructionValue,
printPlace,
printSourceLocation,
} from '../HIR/PrintHIR';
Expand Down Expand Up @@ -669,7 +669,14 @@ class InferenceState {
}
for (const [value, kind] of this.#values) {
const id = identify(value);
result.values[id] = {kind, value: printMixedHIR(value)};
result.values[id] = {
abstract: {
kind: kind.kind,
context: [...kind.context].map(printPlace),
reason: [...kind.reason],
},
value: printInstructionValue(value),
};
}
for (const [variable, values] of this.#variables) {
result.variables[`$${variable}`] = [...values].map(identify);
Expand Down Expand Up @@ -1844,11 +1851,11 @@ function getContextRefOperand(
): Array<Place> {
const result = [];
for (const place of eachInstructionValueOperand(instrValue)) {
if (
state.isDefined(place) &&
state.kind(place).kind === ValueKind.Context
) {
result.push(place);
if (state.isDefined(place)) {
const kind = state.kind(place);
if (kind.kind === ValueKind.Context) {
result.push(...kind.context);
}
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

## Input

```javascript
// @validateNoFreezingKnownMutableFunctions

import {useCallback, useEffect, useRef} from 'react';
import {useHook} from 'shared-runtime';

function Component() {
const params = useHook();
const update = useCallback(
partialParams => {
const nextParams = {
...params,
...partialParams,
};
nextParams.param = 'value';
console.log(nextParams);
},
[params]
);
const ref = useRef(null);
useEffect(() => {
if (ref.current === null) {
update();
}
}, [update]);

return 'ok';
}

```


## Error

```
12 | ...partialParams,
13 | };
> 14 | nextParams.param = 'value';
| ^^^^^^^^^^ InvalidReact: Mutating a value returned from a function whose return value should not be mutated. Found mutation of `params` (14:14)
15 | console.log(nextParams);
16 | },
17 | [params]
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @validateNoFreezingKnownMutableFunctions

import {useCallback, useEffect, useRef} from 'react';
import {useHook} from 'shared-runtime';

function Component() {
const params = useHook();
const update = useCallback(
partialParams => {
const nextParams = {
...params,
...partialParams,
};
nextParams.param = 'value';
console.log(nextParams);
},
[params]
);
const ref = useRef(null);
useEffect(() => {
if (ref.current === null) {
update();
}
}, [update]);

return 'ok';
}
Loading