[test][hir-lower] todo: lower property calls in evaluation order
We currently are not lowering property calls in evaluation order. I wonder if the following lowering for a PropertyCall (with static or computed property) is semantically equivalent to source: 1. eval + resolve receiver (store in t0) 2. eval computed property (if present) 3. resolve t0.property (binding the call to receiver and storing in t1) 4. eval args 5. eval t1(args) Although codegen might then generate something like this (if args are named temporaries) ```js const tmp = receiver.property.bind(receiver); // lower args to temporaries tmp(arg1, arg2); ```
mofeiZ committed
Mar 16, 2023 at 15:48 UTC
2148b4e8cad8669bd066900565c3630270d46c30
4 files changed
+128
compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.expect.md
new
+50
@@ -0,0 +1,50 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// Should print A, B, arg, original
6
+function changeF(o) {
7
+ o.f = () => console.log("new");
8
+}
9
+
10
+function Component() {
11
+ let x = {
12
+ f: () => console.log("original"),
13
+ };
14
+
15
+ (console.log("A"), x)[(console.log("B"), "f")](
16
+ (changeF(x), console.log("arg"), 1)
17
+ );
18
+ return x;
19
+}
20
+
21
+```
22
+
23
+## Code
24
+
25
+```javascript
26
+// Should print A, B, arg, original
27
+function changeF(o) {
28
+ o.f = () => console.log("new");
29
+}
30
+
31
+function Component() {
32
+ const $ = React.unstable_useMemoCache(1);
33
+ let x;
34
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35
+ x = { f: () => console.log("original") };
36
+
37
+ console.log("A");
38
+ console.log("B");
39
+ changeF(x);
40
+ console.log("arg");
41
+ x.f(1);
42
+ $[0] = x;
43
+ } else {
44
+ x = $[0];
45
+ }
46
+ return x;
47
+}
48
+
49
+```
50
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/_bug.computed-call-evaluation-order.js
new
+15
@@ -0,0 +1,15 @@
1
+// Should print A, B, arg, original
2
+function changeF(o) {
3
+ o.f = () => console.log("new");
4
+}
5
+
6
+function Component() {
7
+ let x = {
8
+ f: () => console.log("original"),
9
+ };
10
+
11
+ (console.log("A"), x)[(console.log("B"), "f")](
12
+ (changeF(x), console.log("arg"), 1)
13
+ );
14
+ return x;
15
+}
compiler/forget/src/__tests__/fixtures/compiler/_bug.property-call-evaluation-order.expect.md
new
+49
@@ -0,0 +1,49 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// Should print A, arg, original
6
+
7
+function changeF(o) {
8
+ o.f = () => console.log("new");
9
+}
10
+
11
+function Component() {
12
+ let x = {
13
+ f: () => console.log("original"),
14
+ };
15
+
16
+ (console.log("A"), x).f((changeF(x), console.log("arg"), 1));
17
+ return x;
18
+}
19
+
20
+```
21
+
22
+## Code
23
+
24
+```javascript
25
+// Should print A, arg, original
26
+
27
+function changeF(o) {
28
+ o.f = () => console.log("new");
29
+}
30
+
31
+function Component() {
32
+ const $ = React.unstable_useMemoCache(1);
33
+ let x;
34
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35
+ x = { f: () => console.log("original") };
36
+
37
+ console.log("A");
38
+ changeF(x);
39
+ console.log("arg");
40
+ x.f(1);
41
+ $[0] = x;
42
+ } else {
43
+ x = $[0];
44
+ }
45
+ return x;
46
+}
47
+
48
+```
49
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/_bug.property-call-evaluation-order.js
new
+14
@@ -0,0 +1,14 @@
1
+// Should print A, arg, original
2
+
3
+function changeF(o) {
4
+ o.f = () => console.log("new");
5
+}
6
+
7
+function Component() {
8
+ let x = {
9
+ f: () => console.log("original"),
10
+ };
11
+
12
+ (console.log("A"), x).f((changeF(x), console.log("arg"), 1));
13
+ return x;
14
+}