Skip to content

[compiler] Correctly infer context mutation places as outer (context) places #33114

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 12 commits into
base: gh/josephsavona/80/base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -36,23 +36,13 @@ function Component() {
## Error

```
18 | );
19 | const ref = useRef(null);
> 20 | useEffect(() => {
| ^^^^^^^
> 21 | if (ref.current === null) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 22 | update();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 23 | }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 24 | }, [update]);
| ^^^^ InvalidReact: This argument is a function which modifies local variables when called, which can bypass memoization and cause the UI not to update. Functions that are returned from hooks, passed as arguments to hooks, or passed as props to components may not mutate local variables (20:24)

InvalidReact: The function modifies a local variable here (14:14)
25 |
26 | return 'ok';
27 | }
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]
```


Loading