@samitouri / QOS-React-2 / commits / 0c8f11e13f

[test][ssa] Add todo test for reassigning in rval

From my understanding, `LeaveSSA` is not currently handling reassignment in rvals. Source code ```js let x = foo(); x(x = bar()); ``` Simplified HIR (from EnterSSA) ``` [1] $1 = StoreLocal Let x$0 = [[ foo() ]] // x$1 = foo() [2] $2 = LoadLocal x$1 // t0 = x$1 [3] $4 = StoreLocal Reassign x$3 = [[ bar() ]] // t1 = x$3 = bar() [4] $5 = CallExpression $2 ($4) // t0(t1) ``` codegen: ```js let x; x = foo(); x = bar(); x(x); ```

mofeiZ committed Mar 17, 2023 at 20:08 UTC 0c8f11e13fe545b9bfb240bee6a97382c45355d8
2 files changed +50
compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.expect.md new
+44
@@ -0,0 +1,44 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +// Forget should call the original x (x = foo()) to compute result
6 +function Component() {
7 + let x = foo();
8 + let result = x((x = bar()), 5);
9 + return [result, x];
10 +}
11 +
12 +```
13 +
14 +## Code
15 +
16 +```javascript
17 +// Forget should call the original x (x = foo()) to compute result
18 +function Component() {
19 + const $ = React.unstable_useMemoCache(3);
20 + let t0;
21 + let x;
22 + if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
23 + x = foo();
24 + x = bar();
25 + t0 = x(x, 5);
26 + $[0] = t0;
27 + $[1] = x;
28 + } else {
29 + t0 = $[0];
30 + x = $[1];
31 + }
32 + const result = t0;
33 + let t1;
34 + if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
35 + t1 = [result, x];
36 + $[2] = t1;
37 + } else {
38 + t1 = $[2];
39 + }
40 + return t1;
41 +}
42 +
43 +```
44 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.js new
+6
@@ -0,0 +1,6 @@
1 +// Forget should call the original x (x = foo()) to compute result
2 +function Component() {
3 + let x = foo();
4 + let result = x((x = bar()), 5);
5 + return [result, x];
6 +}