[aliasing] Alias ComputedLoad operands
Sathya Gunasekaran committed
Feb 2, 2023 at 15:45 UTC
98f67c407b390c7c581063c3336bf18a2a7503ac
3 files changed
+47
compiler/forget/src/Inference/InferAlias.ts
+1
@@ -40,6 +40,7 @@ function inferInstr(instr: Instruction, state: AliasAnalyser) {
40
alias = instrValue;
41
break;
42
}
43
+ case "ComputedLoad":
44
case "PropertyLoad": {
45
alias = instrValue.object;
46
break;
compiler/forget/src/__tests__/fixtures/hir/alias-computed-load.expect.md
new
+38
@@ -0,0 +1,38 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+function component(a) {
6
+ let x = { a };
7
+ let y = {};
8
+
9
+ y.x = x["a"];
10
+ mutate(y);
11
+ return x;
12
+}
13
+
14
+```
15
+
16
+## Code
17
+
18
+```javascript
19
+function component(a) {
20
+ const $ = React.useMemoCache();
21
+ const c_0 = $[0] !== a;
22
+ let x;
23
+ if (c_0) {
24
+ x = { a: a };
25
+ const y = {};
26
+ y.x = x["a"];
27
+
28
+ mutate(y);
29
+ $[0] = a;
30
+ $[1] = x;
31
+ } else {
32
+ x = $[1];
33
+ }
34
+ return x;
35
+}
36
+
37
+```
38
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/alias-computed-load.js
new
+8
@@ -0,0 +1,8 @@
1
+function component(a) {
2
+ let x = { a };
3
+ let y = {};
4
+
5
+ y.x = x["a"];
6
+ mutate(y);
7
+ return x;
8
+}