Add infinite loop test case
Discovered this by accident modifying Joe's playground example. This seemed to be triggered in inferReactiveScopeVariables when iterating over the DisjointSet of scopeIdentifiers. In particular this test case contains a cycle and DisjointSet.find would never terminate.
Lauren Tan committed
Dec 22, 2022 at 16:16 UTC
311e5fdf69d563e70e51f8cc3d7f2e49061a29f1
2 files changed
+72
compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md
new
+64
@@ -0,0 +1,64 @@
1
+
2
+## Input
3
+
4
+```javascript
5
+// This causes an infinite loop in the compiler
6
+function MyApp(props) {
7
+ const y = makeObj();
8
+ const tmp = y.a;
9
+ const tmp2 = tmp.b;
10
+ y.push(tmp2);
11
+ return y;
12
+}
13
+
14
+```
15
+
16
+## HIR
17
+
18
+```
19
+bb0:
20
+ [1] Const mutate y$7_@0[1:5] = Call mutate makeObj$2:TFunction()
21
+ [2] Const mutate tmp$8_@0[1:5] = read y$7_@0.a
22
+ [3] Const mutate tmp2$9_@0[1:5] = read tmp$8_@0.b
23
+ [4] Call mutate y$7_@0.push(mutate tmp2$9_@0)
24
+ [5] Return freeze y$7_@0
25
+```
26
+
27
+## Reactive Scopes
28
+
29
+```
30
+function MyApp(
31
+ props,
32
+) {
33
+ scope @0 [1:5] deps=[] out=[y$7_@0] {
34
+ [1] Const mutate y$7_@0[1:5] = Call mutate makeObj$2:TFunction()
35
+ [2] Const mutate tmp$8_@0[1:5] = read y$7_@0.a
36
+ [3] Const mutate tmp2$9_@0[1:5] = read tmp$8_@0.b
37
+ [4] Call mutate y$7_@0.push(mutate tmp2$9_@0)
38
+ }
39
+ return freeze y$7_@0
40
+}
41
+
42
+```
43
+
44
+## Code
45
+
46
+```javascript
47
+function MyApp$0(props$6) {
48
+ const $ = React.useMemoCache();
49
+ let y$7;
50
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
51
+ y$7 = makeObj$2();
52
+ const tmp$8 = y$7.a;
53
+ const tmp2$9 = tmp$8.b;
54
+ y$7.push(tmp2$9);
55
+ $[0] = y$7;
56
+ } else {
57
+ y$7 = $[0];
58
+ }
59
+
60
+ return y$7;
61
+}
62
+
63
+```
64
+
\ No newline at end of file
compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.js
new
+8
@@ -0,0 +1,8 @@
1
+// This caused an infinite loop in the compiler
2
+function MyApp(props) {
3
+ const y = makeObj();
4
+ const tmp = y.a;
5
+ const tmp2 = tmp.b;
6
+ y.push(tmp2);
7
+ return y;
8
+}