@samitouri / QOS-React / commits / aca0e27012

[valueblocks] split working test and aliasing bug case

Joe Savona committed Jan 31, 2023 at 13:39 UTC aca0e270127347d15230de7344cae06046ac4274
5 files changed +85 -29
compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.expect.md new
+57
@@ -0,0 +1,57 @@
1 +
2 +## Input
3 +
4 +```javascript
5 +function component(props) {
6 + // The mutable range for a extens the entire body.
7 + // commenting out the last line of InferMutableRanges fixes it.
8 + // my guess of what's going on is that a is aliased into the return value object literal,
9 + // and that alias makes it look like the range of a needs to be extended to that point.
10 + // but what's weird is that the end of a's range doesn't quite extend to the object.
11 + let a = props.a || (props.b && props.c && props.d);
12 + let b = (props.a && props.b && props.c) || props.d;
13 + return { a, b };
14 +}
15 +
16 +```
17 +
18 +## Code
19 +
20 +```javascript
21 +function component(props) {
22 + const $ = React.useMemoCache();
23 + const c_0 = $[0] !== props;
24 + let a;
25 + if (c_0) {
26 + a = props.a || (props.b && props.c && props.d);
27 + const c_2 = $[2] !== props;
28 + let t3;
29 + if (c_2) {
30 + t3 = (props.a && props.b && props.c) || props.d;
31 + $[2] = props;
32 + $[3] = t3;
33 + } else {
34 + t3 = $[3];
35 + }
36 + $[0] = props;
37 + $[1] = a;
38 + } else {
39 + a = $[1];
40 + }
41 + const b = t3;
42 + const c_4 = $[4] !== a;
43 + const c_5 = $[5] !== b;
44 + let t6;
45 + if (c_4 || c_5) {
46 + t6 = { a: a, b: b };
47 + $[4] = a;
48 + $[5] = b;
49 + $[6] = t6;
50 + } else {
51 + t6 = $[6];
52 + }
53 + return t6;
54 +}
55 +
56 +```
57 +
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/_bug_logical-expression-object.js new
+10
@@ -0,0 +1,10 @@
1 +function component(props) {
2 + // The mutable range for a extens the entire body.
3 + // commenting out the last line of InferMutableRanges fixes it.
4 + // my guess of what's going on is that a is aliased into the return value object literal,
5 + // and that alias makes it look like the range of a needs to be extended to that point.
6 + // but what's weird is that the end of a's range doesn't quite extend to the object.
7 + let a = props.a || (props.b && props.c && props.d);
8 + let b = (props.a && props.b && props.c) || props.d;
9 + return { a, b };
10 +}
compiler/forget/src/__tests__/fixtures/hir/component.expect.md
+1 -4
@@ -55,10 +55,7 @@ function Component(props) {
55 }
56 for (let i = 0; i < items.length; i = i + 1, i) {
57 const item = items.at(i);
58 - if (item == null) {
59 - } else {
60 - }
61 - if (seen.has(item)) {
58 + if (item == null || seen.has(item)) {
59 continue;
60 }
61
compiler/forget/src/__tests__/fixtures/hir/logical-expression.expect.md
+16 -20
@@ -2,14 +2,10 @@
2 ## Input
3
4 ```javascript
5 -// @only
5 function component(props) {
6 let a = props.a || (props.b && props.c && props.d);
7 let b = (props.a && props.b && props.c) || props.d;
9 - return { a, b };
10 - // let b = props.c || props.d;
11 - // let c = props.e ?? props.f;
12 - // return ((a && b) || c) ?? null;
8 + return a ?? b;
9 }
10
11 ```
@@ -17,33 +13,33 @@ function component(props) {
13 ## Code
14
15 ```javascript
20 -// @only
16 function component(props) {
17 const $ = React.useMemoCache();
18 const c_0 = $[0] !== props;
24 - let a;
19 + let t1;
20 if (c_0) {
26 - a = props.a || (props.b && props.c && props.d);
27 - const c_2 = $[2] !== props;
28 - let t3;
29 - if (c_2) {
30 - t3 = (props.a && props.b && props.c) || props.d;
31 - $[2] = props;
32 - $[3] = t3;
33 - } else {
34 - t3 = $[3];
35 - }
21 + t1 = props.a || (props.b && props.c && props.d);
22 $[0] = props;
37 - $[1] = a;
23 + $[1] = t1;
24 } else {
39 - a = $[1];
25 + t1 = $[1];
26 + }
27 + const a = t1;
28 + const c_2 = $[2] !== props;
29 + let t3;
30 + if (c_2) {
31 + t3 = (props.a && props.b && props.c) || props.d;
32 + $[2] = props;
33 + $[3] = t3;
34 + } else {
35 + t3 = $[3];
36 }
37 const b = t3;
38 const c_4 = $[4] !== a;
39 const c_5 = $[5] !== b;
40 let t6;
41 if (c_4 || c_5) {
46 - t6 = { a: a, b: b };
42 + t6 = a ?? b;
43 $[4] = a;
44 $[5] = b;
45 $[6] = t6;
compiler/forget/src/__tests__/fixtures/hir/logical-expression.js
+1 -5
@@ -1,9 +1,5 @@
1 -// @only
1 function component(props) {
2 let a = props.a || (props.b && props.c && props.d);
3 let b = (props.a && props.b && props.c) || props.d;
5 - return { a, b };
6 - // let b = props.c || props.d;
7 - // let c = props.e ?? props.f;
8 - // return ((a && b) || c) ?? null;
4 + return a ?? b;
5 }