@samitouri / QOS-React / commits / 5e1929c002

[aliasing] Alias ComputedStore operands

Sathya Gunasekaran committed Feb 2, 2023 at 15:45 UTC 5e1929c0022e8cab4a366545b64f3d1a0206f67b
3 files changed +47
compiler/forget/src/Inference/InferAliasForStores.ts
+1
@@ -42,6 +42,7 @@ export function inferAliasForStores(
42 }
43 break;
44 }
45 + case "ComputedStore":
46 case "PropertyStore": {
47 maybeAlias(aliases, value.object, value.value, instr.id);
48 break;
compiler/forget/src/__tests__/fixtures/hir/computed-store-alias.expect.md new
+39
@@ -0,0 +1,39 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(a, b) {
6 + let y = { a };
7 + let x = { b };
8 + x["y"] = y;
9 + mutate(x);
10 + return x;
11 +}
12 +
13 +```
14 +
15 +## Code
16 +
17 +```javascript
18 +function component(a, b) {
19 + const $ = React.useMemoCache();
20 + const c_0 = $[0] !== a;
21 + const c_1 = $[1] !== b;
22 + let x;
23 + if (c_0 || c_1) {
24 + const y = { a: a };
25 + x = { b: b };
26 + x["y"] = y;
27 +
28 + mutate(x);
29 + $[0] = a;
30 + $[1] = b;
31 + $[2] = x;
32 + } else {
33 + x = $[2];
34 + }
35 + return x;
36 +}
37 +
38 +```
39 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/computed-store-alias.js new
+7
@@ -0,0 +1,7 @@
1 +function component(a, b) {
2 + let y = { a };
3 + let x = { b };
4 + x["y"] = y;
5 + mutate(x);
6 + return x;
7 +}