From 0c8f11e13fe545b9bfb240bee6a97382c45355d8 Mon Sep 17 00:00:00 2001 From: mofeiZ <34200447+mofeiZ@users.noreply.github.com> Date: Fri, 17 Mar 2023 20:08:20 -0400 Subject: [PATCH] [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); ``` --- .../_bug.ssa-reassign-in-rval.expect.md | 44 +++++++++++++++++++ .../compiler/_bug.ssa-reassign-in-rval.js | 6 +++ 2 files changed, 50 insertions(+) create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.expect.md create mode 100644 compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.js diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.expect.md new file mode 100644 index 0000000000..a25e1e4212 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.expect.md @@ -0,0 +1,44 @@ + +## Input + +```javascript +// Forget should call the original x (x = foo()) to compute result +function Component() { + let x = foo(); + let result = x((x = bar()), 5); + return [result, x]; +} + +``` + +## Code + +```javascript +// Forget should call the original x (x = foo()) to compute result +function Component() { + const $ = React.unstable_useMemoCache(3); + let t0; + let x; + if ($[0] === Symbol.for("react.memo_cache_sentinel")) { + x = foo(); + x = bar(); + t0 = x(x, 5); + $[0] = t0; + $[1] = x; + } else { + t0 = $[0]; + x = $[1]; + } + const result = t0; + let t1; + if ($[2] === Symbol.for("react.memo_cache_sentinel")) { + t1 = [result, x]; + $[2] = t1; + } else { + t1 = $[2]; + } + return t1; +} + +``` + \ No newline at end of file diff --git a/compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.js b/compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.js new file mode 100644 index 0000000000..9126165e59 --- /dev/null +++ b/compiler/forget/src/__tests__/fixtures/compiler/_bug.ssa-reassign-in-rval.js @@ -0,0 +1,6 @@ +// Forget should call the original x (x = foo()) to compute result +function Component() { + let x = foo(); + let result = x((x = bar()), 5); + return [result, x]; +}