From 1809ffd06d4b37f1012284c6cc19558e1f74ced5 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Wed, 8 Feb 2023 10:26:26 -0500 Subject: [PATCH] Add new test cases for SSA Add these as a separate commit so we can see how later PRs in the stack change them --- .../fixtures/hir/ssa-leave-case.expect.md | 68 +++++++++++++++++++ .../__tests__/fixtures/hir/ssa-leave-case.js | 14 ++++ .../hir/ssa-renaming-with-mutation.expect.md | 56 +++++++++++++++ .../hir/ssa-renaming-with-mutation.js | 11 +++ .../fixtures/hir/ssa-renaming.expect.md | 61 +++++++++++++++++ .../__tests__/fixtures/hir/ssa-renaming.js | 10 +++ 6 files changed, 220 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.js create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.js create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.js diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.expect.md new file mode 100644 index 0000000000..4c7225c6d8 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.expect.md @@ -0,0 +1,68 @@ + +## Input + +```javascript +function Component(props) { + let x = []; + let y; + if (props.p0) { + x.push(props.p1); + y = x; + } + return ( + + {x} + {y} + + ); +} + +``` + +## Code + +```javascript +function Component(props) { + const $ = React.unstable_useMemoCache(); + const c_0 = $[0] !== props.p0; + const c_1 = $[1] !== props.p1; + let x; + let y$0; + if (c_0 || c_1) { + x = []; + const y = undefined; + y$0 = y; + if (props.p0) { + x.push(props.p1); + const y$1 = x; + y$0 = y$1; + } + $[0] = props.p0; + $[1] = props.p1; + $[2] = x; + $[3] = y$0; + } else { + x = $[2]; + y$0 = $[3]; + } + const c_4 = $[4] !== x; + const c_5 = $[5] !== y$0; + let t0; + if (c_4 || c_5) { + t0 = ( + + {x} + {y$0} + + ); + $[4] = x; + $[5] = y$0; + $[6] = t0; + } else { + t0 = $[6]; + } + return t0; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.js b/compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.js new file mode 100644 index 0000000000..fce3a15209 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-leave-case.js @@ -0,0 +1,14 @@ +function Component(props) { + let x = []; + let y; + if (props.p0) { + x.push(props.p1); + y = x; + } + return ( + + {x} + {y} + + ); +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.expect.md new file mode 100644 index 0000000000..55109504b4 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.expect.md @@ -0,0 +1,56 @@ + +## Input + +```javascript +function foo(props) { + let x = []; + x.push(props.bar); + if (props.cond) { + x = {}; + x = []; + x.push(props.foo); + } + mut(x); + return x; +} + +``` + +## Code + +```javascript +function foo(props) { + const $ = React.unstable_useMemoCache(); + const c_0 = $[0] !== props.bar; + let x; + if (c_0) { + x = []; + x.push(props.bar); + $[0] = props.bar; + $[1] = x; + } else { + x = $[1]; + } + const c_2 = $[2] !== props.cond; + const c_3 = $[3] !== props.foo; + let x$0; + if (c_2 || c_3) { + x$0 = x; + if (props.cond) { + const x$1 = []; + x$1.push(props.foo); + x$0 = x$1; + } + + mut(x$0); + $[2] = props.cond; + $[3] = props.foo; + $[4] = x$0; + } else { + x$0 = $[4]; + } + return x$0; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.js b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.js new file mode 100644 index 0000000000..30f7193353 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming-with-mutation.js @@ -0,0 +1,11 @@ +function foo(props) { + let x = []; + x.push(props.bar); + if (props.cond) { + x = {}; + x = []; + x.push(props.foo); + } + mut(x); + return x; +} diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.expect.md b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.expect.md new file mode 100644 index 0000000000..01f3e8648a --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.expect.md @@ -0,0 +1,61 @@ + +## Input + +```javascript +function foo(props) { + let x = []; + x.push(props.bar); + if (props.cond) { + x = {}; + x = []; + x.push(props.foo); + } + return x; +} + +``` + +## Code + +```javascript +function foo(props) { + const $ = React.unstable_useMemoCache(); + const c_0 = $[0] !== props.bar; + let x; + if (c_0) { + x = []; + x.push(props.bar); + $[0] = props.bar; + $[1] = x; + } else { + x = $[1]; + } + const c_2 = $[2] !== props.cond; + const c_3 = $[3] !== props.foo; + let x$0; + if (c_2 || c_3) { + x$0 = x; + if (props.cond) { + const c_5 = $[5] !== props.foo; + let x$1; + if (c_5) { + x$1 = []; + x$1.push(props.foo); + $[5] = props.foo; + $[6] = x$1; + } else { + x$1 = $[6]; + } + x$0 = x$1; + } + $[2] = props.cond; + $[3] = props.foo; + $[4] = x$0; + } else { + x$0 = $[4]; + } + return x$0; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.js b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.js new file mode 100644 index 0000000000..747199c62d --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/hir/ssa-renaming.js @@ -0,0 +1,10 @@ +function foo(props) { + let x = []; + x.push(props.bar); + if (props.cond) { + x = {}; + x = []; + x.push(props.foo); + } + return x; +}