Skip to content

Commit 1df57c8

Browse files
committed
[compiler] Repro for case of lost precision in new inference
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.
1 parent 48fc490 commit 1df57c8

File tree

2 files changed

+84
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)