Skip to content

Simplfy e?true:false to e #7139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,7 @@ let rec econd ?comment (pred : t) (ifso : t) (ifnot : t) : t =
| (Number _ | Array _ | Caml_block _), _, _ when no_side_effect pred ->
ifso (* a block can not be false in OCAML, CF - relies on flow inference*)
| Bool true, _, _ -> ifso
| _, Bool true, Bool false -> pred
| _, Cond (pred1, ifso1, ifnot1), _
when Js_analyzer.eq_expression ifnot1 ifnot ->
(* {[
Expand Down
6 changes: 1 addition & 5 deletions lib/es6/Belt_Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ function getWithDefault(opt, $$default) {
}

function isOk(x) {
if (x.TAG === "Ok") {
return true;
} else {
return false;
}
return x.TAG === "Ok";
}

function isError(x) {
Expand Down
6 changes: 1 addition & 5 deletions lib/es6/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ function getOr(opt, $$default) {
}

function isOk(x) {
if (x.TAG === "Ok") {
return true;
} else {
return false;
}
return x.TAG === "Ok";
}

function isError(x) {
Expand Down
6 changes: 1 addition & 5 deletions lib/js/Belt_Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ function getWithDefault(opt, $$default) {
}

function isOk(x) {
if (x.TAG === "Ok") {
return true;
} else {
return false;
}
return x.TAG === "Ok";
}

function isError(x) {
Expand Down
6 changes: 1 addition & 5 deletions lib/js/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ function getOr(opt, $$default) {
}

function isOk(x) {
if (x.TAG === "Ok") {
return true;
} else {
return false;
}
return x.TAG === "Ok";
}

function isError(x) {
Expand Down
12 changes: 2 additions & 10 deletions tests/tests/src/bdd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ function $$eval(_bdd, vars) {
while (true) {
let bdd = _bdd;
if (typeof bdd !== "object") {
if (bdd === "One") {
return true;
} else {
return false;
}
return bdd === "One";
}
if (Primitive_array.get(vars, bdd._1)) {
_bdd = bdd._3;
Expand Down Expand Up @@ -366,11 +362,7 @@ function random_vars(n) {

function bool_equal(a, b) {
if (a) {
if (b) {
return true;
} else {
return false;
}
return b;
} else if (b) {
return false;
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/caml_compare_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ try {
function_equal_test = Primitive_object.equal(x => x + 1 | 0, x => x + 2 | 0);
} catch (raw_exn) {
let exn = Primitive_exceptions.internalToException(raw_exn);
function_equal_test = exn.RE_EXN_ID === "Invalid_argument" && exn._1 === "equal: functional value" ? true : false;
function_equal_test = exn.RE_EXN_ID === "Invalid_argument" ? exn._1 === "equal: functional value" : false;
}

let suites = {
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/core/Core_JsonTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function decodeJsonTest() {
decodedCorrectly = false;
} else {
let match$3 = match$1[1];
decodedCorrectly = match$3 === null || !(typeof match$3 === "boolean" && !match$3) ? false : true;
decodedCorrectly = match$3 === null ? false : typeof match$3 === "boolean" && !match$3;
}
} else {
decodedCorrectly = false;
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/src/core/Core_NullableTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function shouldHandleNullableValues() {
let tUndefined = undefined;
let tValue = "hello";
let tmp;
tmp = tNull === null ? true : false;
tmp = tNull === null || tNull === undefined ? tNull === null : false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tNull === undefined was already gone in #7138?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge and rebase directly on #7138

Test.run([
[
"Core_NullableTests.res",
Expand All @@ -18,7 +18,7 @@ function shouldHandleNullableValues() {
"Should handle null"
], tmp, (prim0, prim1) => prim0 === prim1, true);
let tmp$1;
tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null ? true : false;
tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null;
Test.run([
[
"Core_NullableTests.res",
Expand All @@ -29,7 +29,7 @@ function shouldHandleNullableValues() {
"Should handle undefined"
], tmp$1, (prim0, prim1) => prim0 === prim1, true);
let tmp$2;
tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true;
tmp$2 = tValue === null || tValue === undefined ? false : tValue === "hello";
Test.run([
[
"Core_NullableTests.res",
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/core/Core_PromiseTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function testExnThrow() {
Error: new Error()
};
}), e => {
let isTestErr = e.RE_EXN_ID === TestError && e._1 === "Thrown exn" ? true : false;
let isTestErr = e.RE_EXN_ID === TestError ? e._1 === "Thrown exn" : false;
Test.run([
[
"Core_PromiseTest.res",
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/src/gpr496_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function ff(x, y) {
return Primitive_bool.min(x, y());
}

eq("File \"gpr496_test.res\", line 40, characters 12-19", true < false ? true : false, false);
eq("File \"gpr496_test.res\", line 40, characters 12-19", true < false, false);

Mt.from_pair_suites("Gpr496_test", suites.contents);

Expand Down
6 changes: 1 addition & 5 deletions tests/tests/src/gpr_1698_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ function is_number(_expr) {
let expr = _expr;
switch (expr.TAG) {
case "Val" :
if (expr._0.TAG === "Natural") {
return true;
} else {
return false;
}
return expr._0.TAG === "Natural";
case "Neg" :
_expr = expr._0;
continue;
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/src/gpr_4924_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function u(b) {
}

function u1(b) {
if (typeof b !== "object" && b === "A") {
return true;
if (typeof b !== "object") {
return b === "A";
} else {
return false;
}
Expand Down Expand Up @@ -65,8 +65,8 @@ function u5(b) {
}

function u6(b) {
if (typeof b !== "object" && b === "A") {
return true;
if (typeof b !== "object") {
return b === "A";
} else {
return false;
}
Expand Down
38 changes: 6 additions & 32 deletions tests/tests/src/inline_map2_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ function Make(Ord) {
return create(create(l, x, d, rl._0), rl._1, rl._2, create(rl._3, rv, rd, rr));
}
};
let is_empty = x => {
if (typeof x !== "object") {
return true;
} else {
return false;
}
};
let is_empty = x => typeof x !== "object";
let add = (x, data, x_) => {
if (typeof x_ !== "object") {
return {
Expand Down Expand Up @@ -523,11 +517,7 @@ function Make(Ord) {
let e2 = _e2;
let e1 = _e1;
if (typeof e1 !== "object") {
if (typeof e2 !== "object") {
return true;
} else {
return false;
}
return typeof e2 !== "object";
}
if (typeof e2 !== "object") {
return false;
Expand Down Expand Up @@ -688,11 +678,7 @@ function bal(l, x, d, r) {
}

function is_empty(x) {
if (typeof x !== "object") {
return true;
} else {
return false;
}
return typeof x !== "object";
}

function add(x, data, x_) {
Expand Down Expand Up @@ -1154,11 +1140,7 @@ function equal(cmp, m1, m2) {
let e2 = _e2;
let e1 = _e1;
if (typeof e1 !== "object") {
if (typeof e2 !== "object") {
return true;
} else {
return false;
}
return typeof e2 !== "object";
}
if (typeof e2 !== "object") {
return false;
Expand Down Expand Up @@ -1350,11 +1332,7 @@ function bal$1(l, x, d, r) {
}

function is_empty$1(x) {
if (typeof x !== "object") {
return true;
} else {
return false;
}
return typeof x !== "object";
}

function add$1(x, data, x_) {
Expand Down Expand Up @@ -1816,11 +1794,7 @@ function equal$1(cmp, m1, m2) {
let e2 = _e2;
let e1 = _e1;
if (typeof e1 !== "object") {
if (typeof e2 !== "object") {
return true;
} else {
return false;
}
return typeof e2 !== "object";
}
if (typeof e2 !== "object") {
return false;
Expand Down
18 changes: 3 additions & 15 deletions tests/tests/src/js_bool_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,15 @@
import * as Mt from "./mt.mjs";

function f(x) {
if (x) {
return true;
} else {
return false;
}
return x;
}

function f2(x) {
if (x) {
return true;
} else {
return false;
}
return x;
}

function f4(x) {
if (x) {
return true;
} else {
return false;
}
return x;
}

let u = 1;
Expand Down
14 changes: 3 additions & 11 deletions tests/tests/src/mario_game.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -928,19 +928,11 @@ function get_obj(x) {
}

function is_player(x) {
if (x.TAG === "Player") {
return true;
} else {
return false;
}
return x.TAG === "Player";
}

function is_enemy(x) {
if (x.TAG === "Enemy") {
return true;
} else {
return false;
}
return x.TAG === "Enemy";
}

function equals(col1, col2) {
Expand Down Expand Up @@ -1262,7 +1254,7 @@ function col_bypass(c1, c2) {
ctypes = c2.TAG === "Enemy" ? c1._2.invuln > 0 : false;
break;
case "Enemy" :
ctypes = c2.TAG === "Item" ? true : false;
ctypes = c2.TAG === "Item";
break;
case "Item" :
switch (c2.TAG) {
Expand Down
6 changes: 1 addition & 5 deletions tests/tests/src/rbset.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ function blackify(x) {
}

function is_empty(x) {
if (typeof x !== "object") {
return true;
} else {
return false;
}
return typeof x !== "object";
}

function mem(x, _x_) {
Expand Down
6 changes: 1 addition & 5 deletions tests/tests/src/reasonReactRouter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ function urlNotEqual(a, b) {
let bList = _bList;
let aList = _aList;
if (!aList) {
if (bList) {
return true;
} else {
return false;
}
return bList;
}
if (!bList) {
return true;
Expand Down
6 changes: 1 addition & 5 deletions tests/tests/src/set_gen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ function max_elt(_x) {
}

function is_empty(x) {
if (typeof x !== "object") {
return true;
} else {
return false;
}
return typeof x !== "object";
}

function cardinal_aux(_acc, _x) {
Expand Down
6 changes: 1 addition & 5 deletions tests/tests/src/test_bool_equal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

function bool_equal(x, y) {
if (x) {
if (y) {
return true;
} else {
return false;
}
return y;
} else if (y) {
return false;
} else {
Expand Down
8 changes: 1 addition & 7 deletions tests/tests/src/test_set.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,7 @@ function Make(Ord) {
match$1[2]
];
};
let is_empty = x => {
if (typeof x !== "object") {
return true;
} else {
return false;
}
};
let is_empty = x => typeof x !== "object";
let mem = (x, _x_) => {
while (true) {
let x_ = _x_;
Expand Down
Loading