Skip to content

Commit 0e7cdeb

Browse files
authored
[compiler] Repro for case of lost precision in new inference (#33522)
In comparing compilation output of the old/new inference models I found this case (heavily distilled into a fixture). Roughly speaking the scenario is: * Create a mutable object `x` * Extract part of that object and pass it to a hook/jsx so that _part_ becomes frozen * Mutate `x`, even indirectly. In the old model we can still independently memoize the value from the middle step, since we assume that part of the larger value is not changing. In the new model, the mutation from the later step effectively overrides the freeze effect in step 2, and considers the value to have changed later anyway. We've already rolled out and vetted the previous behavior, confirming that the heuristic of "that part of the mutable object is fozen now" is generally safe. I'll fix in a follow-up. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33522). * #33571 * #33558 * #33547 * #33543 * #33533 * #33532 * #33530 * #33526 * __->__ #33522 * #33518
1 parent 81d8115 commit 0e7cdeb

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
## Input
3+
4+
```javascript
5+
// @flow @enableNewMutationAliasingModel
6+
7+
import {identity, Stringify, useFragment} from 'shared-runtime';
8+
9+
component Example() {
10+
const data = useFragment();
11+
12+
const {a, b} = identity(data);
13+
14+
const el = <Stringify tooltip={b} />;
15+
16+
identity(a.at(0));
17+
18+
return <Stringify icon={el} />;
19+
}
20+
21+
```
22+
23+
## Code
24+
25+
```javascript
26+
import { c as _c } from "react/compiler-runtime";
27+
28+
import { identity, Stringify, useFragment } from "shared-runtime";
29+
30+
function Example() {
31+
const $ = _c(2);
32+
const data = useFragment();
33+
let t0;
34+
if ($[0] !== data) {
35+
const { a, b } = identity(data);
36+
37+
const el = <Stringify tooltip={b} />;
38+
39+
identity(a.at(0));
40+
41+
t0 = <Stringify icon={el} />;
42+
$[0] = data;
43+
$[1] = t0;
44+
} else {
45+
t0 = $[1];
46+
}
47+
return t0;
48+
}
49+
50+
```
51+
52+
### Eval output
53+
(kind: exception) Fixture not implemented
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @flow @enableNewMutationAliasingModel
2+
3+
import {identity, Stringify, useFragment} from 'shared-runtime';
4+
5+
component Example() {
6+
const data = useFragment();
7+
8+
const {a, b} = identity(data);
9+
10+
const el = <Stringify tooltip={b} />;
11+
12+
identity(a.at(0));
13+
14+
return <Stringify icon={el} />;
15+
}

0 commit comments

Comments
 (0)