From 1df89e992a7260d4690c3c82437d6d0ddd992d90 Mon Sep 17 00:00:00 2001 From: Joe Savona Date: Thu, 27 Apr 2023 10:43:43 -0700 Subject: [PATCH] Remove unnecessary temporary in tests We previously didn't support ternaries whose value was unused, so we had an extraneous temporary and console.log call to ensure the value counted as used. We now special-case ternary/conditional expressions which are in an ExpressionStatement to not prune them, so the temporary and log are now unnecessary. --- ...-renaming-ternary-destruction-with-mutation.expect.md | 9 ++------- .../ssa-renaming-ternary-destruction-with-mutation.js | 5 +---- .../compiler/ssa-renaming-ternary-destruction.expect.md | 9 ++------- .../compiler/ssa-renaming-ternary-destruction.js | 5 +---- .../ssa-renaming-ternary-with-mutation.expect.md | 6 ++---- .../compiler/ssa-renaming-ternary-with-mutation.js | 3 +-- .../fixtures/compiler/ssa-renaming-ternary.expect.md | 6 ++---- .../__tests__/fixtures/compiler/ssa-renaming-ternary.js | 3 +-- ...enaming-unconditional-ternary-with-mutation.expect.md | 8 ++------ .../ssa-renaming-unconditional-ternary-with-mutation.js | 3 +-- .../ssa-renaming-unconditional-ternary.expect.md | 6 ++---- .../compiler/ssa-renaming-unconditional-ternary.js | 3 +-- 12 files changed, 18 insertions(+), 48 deletions(-) diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md index a477588511..c0fc088d24 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.expect.md @@ -5,10 +5,7 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) - : null; - console.log(_); + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null; mut(x); return x; } @@ -26,9 +23,7 @@ function foo(props) { if (c_0) { x = []; x.push(props.bar); - const _ = props.cond ? (([x] = [[]]), x.push(props.foo)) : null; - - console.log(_); + props.cond ? (([x] = [[]]), x.push(props.foo)) : null; mut(x); $[0] = props; $[1] = x; diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js index e227256a9f..71ebbc8147 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction-with-mutation.js @@ -1,10 +1,7 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) - : null; - console.log(_); + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null; mut(x); return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md index 38a7dd0086..cd1ec07da8 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.expect.md @@ -5,10 +5,7 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) - : null; - console.log(_); + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null; return x; } @@ -41,9 +38,7 @@ function foo(props) { t0 = $[3]; x = $[4]; } - const _ = t0; - - console.log(_); + t0; return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js index f1db380d55..8ef976554f 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-destruction.js @@ -1,9 +1,6 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond - ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) - : null; - console.log(_); + props.cond ? (({ x } = { x: {} }), ([x] = [[]]), x.push(props.foo)) : null; return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md index 513f81aab6..913d51ce0a 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.expect.md @@ -5,8 +5,7 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; - console.log(_); + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; mut(x); return x; } @@ -24,8 +23,7 @@ function foo(props) { if (c_0) { x = []; x.push(props.bar); - const _ = props.cond ? ((x = []), x.push(props.foo)) : null; - console.log(_); + props.cond ? ((x = []), x.push(props.foo)) : null; mut(x); $[0] = props; $[1] = x; diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js index fdfe6a91bd..5dde2fea8c 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary-with-mutation.js @@ -1,8 +1,7 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; - console.log(_); + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; mut(x); return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md index 86250c8e68..ef0a68f04b 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.expect.md @@ -5,8 +5,7 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; - console.log(_); + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; return x; } @@ -39,8 +38,7 @@ function foo(props) { t0 = $[3]; x = $[4]; } - const _ = t0; - console.log(_); + t0; return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js index e80445a006..64872130b7 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-ternary.js @@ -1,7 +1,6 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; - console.log(_); + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : null; return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md index f3537e619a..e6ea666e07 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.expect.md @@ -5,10 +5,9 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : ((x = []), (x = []), x.push(props.bar)); - console.log(_); mut(x); return x; } @@ -26,10 +25,7 @@ function foo(props) { if (c_0) { x = []; x.push(props.bar); - const _ = props.cond - ? ((x = []), x.push(props.foo)) - : ((x = []), x.push(props.bar)); - console.log(_); + props.cond ? ((x = []), x.push(props.foo)) : ((x = []), x.push(props.bar)); mut(x); $[0] = props; $[1] = x; diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js index 19eda5a564..5877120405 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary-with-mutation.js @@ -1,10 +1,9 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : ((x = []), (x = []), x.push(props.bar)); - console.log(_); mut(x); return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md index 3c01da132c..9a7dd78e7c 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.expect.md @@ -5,10 +5,9 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : ((x = []), (x = []), x.push(props.bar)); - console.log(_); return x; } @@ -43,8 +42,7 @@ function foo(props) { t0 = $[3]; x = $[4]; } - const _ = t0; - console.log(_); + t0; return x; } diff --git a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js index 140005d820..236d489e1d 100644 --- a/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js +++ b/compiler/forget/src/__tests__/fixtures/compiler/ssa-renaming-unconditional-ternary.js @@ -1,9 +1,8 @@ function foo(props) { let x = []; x.push(props.bar); - const _ = props.cond + props.cond ? ((x = {}), (x = []), x.push(props.foo)) : ((x = []), (x = []), x.push(props.bar)); - console.log(_); return x; }