From 311e5fdf69d563e70e51f8cc3d7f2e49061a29f1 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 22 Dec 2022 16:16:16 -0500 Subject: [PATCH] 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. --- ...ue933-disjoint-set-infinite-loop.expect.md | 64 +++++++++++++++++++ .../issue933-disjoint-set-infinite-loop.js | 8 +++ 2 files changed, 72 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.js diff --git a/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md b/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md new file mode 100644 index 0000000000..0350ec3cf1 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.expect.md @@ -0,0 +1,64 @@ + +## Input + +```javascript +// This causes an infinite loop in the compiler +function MyApp(props) { + const y = makeObj(); + const tmp = y.a; + const tmp2 = tmp.b; + y.push(tmp2); + return y; +} + +``` + +## HIR + +``` +bb0: + [1] Const mutate y$7_@0[1:5] = Call mutate makeObj$2:TFunction() + [2] Const mutate tmp$8_@0[1:5] = read y$7_@0.a + [3] Const mutate tmp2$9_@0[1:5] = read tmp$8_@0.b + [4] Call mutate y$7_@0.push(mutate tmp2$9_@0) + [5] Return freeze y$7_@0 +``` + +## Reactive Scopes + +``` +function MyApp( + props, +) { + scope @0 [1:5] deps=[] out=[y$7_@0] { + [1] Const mutate y$7_@0[1:5] = Call mutate makeObj$2:TFunction() + [2] Const mutate tmp$8_@0[1:5] = read y$7_@0.a + [3] Const mutate tmp2$9_@0[1:5] = read tmp$8_@0.b + [4] Call mutate y$7_@0.push(mutate tmp2$9_@0) + } + return freeze y$7_@0 +} + +``` + +## Code + +```javascript +function MyApp$0(props$6) { + const $ = React.useMemoCache(); + let y$7; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + y$7 = makeObj$2(); + const tmp$8 = y$7.a; + const tmp2$9 = tmp$8.b; + y$7.push(tmp2$9); + $[0] = y$7; + } else { + y$7 = $[0]; + } + + return y$7; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.js b/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.js new file mode 100644 index 0000000000..43d343bb1c --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/issue933-disjoint-set-infinite-loop.js @@ -0,0 +1,8 @@ +// This caused an infinite loop in the compiler +function MyApp(props) { + const y = makeObj(); + const tmp = y.a; + const tmp2 = tmp.b; + y.push(tmp2); + return y; +}