Skip to content

Commit 7649d79

Browse files
committed
improve negative cases
1 parent 4e6889f commit 7649d79

12 files changed

+131
-175
lines changed

Diff for: jscomp/core/lam.ml

+43-39
Original file line numberDiff line numberDiff line change
@@ -1121,40 +1121,6 @@ let let_ kind id e body : t
11211121
let letrec bindings body : t =
11221122
Lletrec(bindings,body)
11231123

1124-
let if_ (a : t) (b : t) c =
1125-
match a with
1126-
| Lconst v ->
1127-
begin match v with
1128-
| Const_pointer (x, _) | (Const_int x)
1129-
->
1130-
if x <> 0 then b else c
1131-
| (Const_char x) ->
1132-
if Char.code x <> 0 then b else c
1133-
| (Const_int32 x) ->
1134-
if x <> 0l then b else c
1135-
| (Const_int64 x) ->
1136-
if x <> 0L then b else c
1137-
| (Const_nativeint x) ->
1138-
if x <> 0n then b else c
1139-
| Const_js_false
1140-
| Const_js_null
1141-
| Const_js_undefined -> c
1142-
| Const_js_true
1143-
| Const_string _
1144-
| Const_float _
1145-
| Const_unicode _
1146-
| Const_block _
1147-
| Const_float_array _
1148-
| Const_immstring _ -> b
1149-
end
1150-
| _ ->
1151-
begin match a, b, c with
1152-
| Lprim {primitive = Pintcomp _;}, Lconst(Const_js_true), Lconst(Const_js_false)
1153-
-> a
1154-
| _ ->
1155-
1156-
Lifthenelse (a,b,c)
1157-
end
11581124

11591125

11601126
let abs_int x = if x < 0 then - x else x
@@ -1219,11 +1185,6 @@ let unit : t =
12191185
(* let assert_false_unit : t =
12201186
Lconst (Const_pointer( 0, Pt_constructor "impossible branch")) *)
12211187

1222-
(** [l || r ] *)
1223-
let sequor l r = if_ l true_ r
1224-
1225-
(** [l && r ] *)
1226-
let sequand l r = if_ l r false_
12271188

12281189
let seq a b : t =
12291190
(* match a, b with
@@ -1457,7 +1418,50 @@ let not_ loc x : t =
14571418
prim ~primitive:Pnot ~args:[x] loc
14581419

14591420

1421+
let if_ (a : t) (b : t) c =
1422+
match a with
1423+
| Lconst v ->
1424+
begin match v with
1425+
| Const_pointer (x, _) | (Const_int x)
1426+
->
1427+
if x <> 0 then b else c
1428+
| (Const_char x) ->
1429+
if Char.code x <> 0 then b else c
1430+
| (Const_int32 x) ->
1431+
if x <> 0l then b else c
1432+
| (Const_int64 x) ->
1433+
if x <> 0L then b else c
1434+
| (Const_nativeint x) ->
1435+
if x <> 0n then b else c
1436+
| Const_js_false
1437+
| Const_js_null
1438+
| Const_js_undefined -> c
1439+
| Const_js_true
1440+
| Const_string _
1441+
| Const_float _
1442+
| Const_unicode _
1443+
| Const_block _
1444+
| Const_float_array _
1445+
| Const_immstring _ -> b
1446+
end
1447+
| _ ->
1448+
begin match a, b, c with
1449+
| Lprim {primitive = Pintcomp _;}, Lconst(Const_js_true), Lconst(Const_js_false)
1450+
-> a
1451+
| Lprim {primitive = Pintcomp _;loc}, Lconst(Const_js_false), Lconst(Const_js_true)
1452+
-> not_ loc a
1453+
| _ ->
1454+
1455+
Lifthenelse (a,b,c)
1456+
end
1457+
1458+
14601459

1460+
(** [l || r ] *)
1461+
let sequor l r = if_ l true_ r
1462+
1463+
(** [l && r ] *)
1464+
let sequand l r = if_ l r false_
14611465

14621466
(******************************************************************)
14631467
(** only [handle_bs_non_obj_ffi] will be used outside *)

Diff for: jscomp/test/bdd.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ function $$eval(_bdd, vars) {
88
while(true) {
99
var bdd = _bdd;
1010
if (typeof bdd === "number") {
11-
if (bdd !== 0) {
12-
return false;
13-
} else {
14-
return true;
15-
}
11+
return bdd === 0;
1612
} else if (Caml_array.caml_array_get(vars, bdd[1])) {
1713
_bdd = bdd[3];
1814
continue ;

Diff for: jscomp/test/bs_poly_map_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ var match$1 = match[0];
264264

265265
var match$2 = Belt_Map.get(v3, 10);
266266

267-
b("File \"bs_poly_map_test.ml\", line 126, characters 4-11", match$2 && match$2[0] === 11 ? true : false);
267+
b("File \"bs_poly_map_test.ml\", line 126, characters 4-11", match$2 ? match$2[0] === 11 : false);
268268

269269
var match$3 = Belt_Map.get(v3, -10);
270270

271271
b("File \"bs_poly_map_test.ml\", line 127, characters 4-11", match$3 ? false : true);
272272

273273
var match$4 = Belt_Map.get(v4, -10);
274274

275-
b("File \"bs_poly_map_test.ml\", line 128, characters 4-11", match$4 && match$4[0] === 0 ? true : false);
275+
b("File \"bs_poly_map_test.ml\", line 128, characters 4-11", match$4 ? match$4[0] === 0 : false);
276276

277277
var map = Belt_Map.remove({
278278
cmp: Icmp[/* cmp */0],
@@ -288,7 +288,7 @@ var map$1 = Belt_Map.removeMany({
288288

289289
b("File \"bs_poly_map_test.ml\", line 130, characters 4-11", Belt_MapDict.isEmpty(map$1.data));
290290

291-
b("File \"bs_poly_map_test.ml\", line 131, characters 4-11", pres && pres[0] === 5000 ? true : false);
291+
b("File \"bs_poly_map_test.ml\", line 131, characters 4-11", pres ? pres[0] === 5000 : false);
292292

293293
b("File \"bs_poly_map_test.ml\", line 132, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$1[0].data), Belt_Array.makeBy(5000, (function (i) {
294294
return i;

Diff for: jscomp/test/compare_test.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@ function compare(x, y) {
1616
function compare2(x, y) {
1717
switch (x) {
1818
case 0 :
19-
if (y !== 0) {
20-
return false;
21-
} else {
22-
return true;
23-
}
19+
return y === 0;
2420
case 1 :
25-
if (y !== 1) {
26-
return false;
27-
} else {
28-
return true;
29-
}
21+
return y === 1;
3022
case 2 :
3123
return y >= 2;
3224

Diff for: jscomp/test/ext_string_test.js

+6-24
Original file line numberDiff line numberDiff line change
@@ -478,26 +478,14 @@ function is_valid_module_file(s) {
478478
if (x >= 65) {
479479
var switcher = x - 91 | 0;
480480
if (switcher > 5 || switcher < 0) {
481-
if (switcher >= 32) {
482-
return false;
483-
} else {
484-
return true;
485-
}
486-
} else if (switcher !== 4) {
487-
return false;
481+
return switcher < 32;
488482
} else {
489-
return true;
483+
return switcher === 4;
490484
}
491485
} else if (x >= 48) {
492-
if (x >= 58) {
493-
return false;
494-
} else {
495-
return true;
496-
}
497-
} else if (x !== 39) {
498-
return false;
486+
return x < 58;
499487
} else {
500-
return true;
488+
return x === 39;
501489
}
502490
}));
503491
}
@@ -527,15 +515,9 @@ function is_valid_npm_package_name(s) {
527515
return unsafe_for_all_range(s, 1, len - 1 | 0, (function (x) {
528516
if (x >= 58) {
529517
if (x >= 97) {
530-
if (x >= 123) {
531-
return false;
532-
} else {
533-
return true;
534-
}
535-
} else if (x !== 95) {
536-
return false;
518+
return x < 123;
537519
} else {
538-
return true;
520+
return x === 95;
539521
}
540522
} else if (x !== 45) {
541523
return x >= 48;

Diff for: jscomp/test/flow_parser_reg_test.js

+9-15
Original file line numberDiff line numberDiff line change
@@ -4913,15 +4913,9 @@ function is_identifier($staropt$star, env) {
49134913
} else if (typeof match === "number") {
49144914
var switcher = match - 1 | 0;
49154915
if (switcher > 56 || switcher < 0) {
4916-
if (switcher >= 62) {
4917-
return false;
4918-
} else {
4919-
return true;
4920-
}
4921-
} else if (switcher !== 25) {
4922-
return false;
4916+
return switcher < 62;
49234917
} else {
4924-
return true;
4918+
return switcher === 25;
49254919
}
49264920
} else {
49274921
return false;
@@ -4942,8 +4936,12 @@ function is_function($staropt$star, env) {
49424936
function is_class($staropt$star, env) {
49434937
var i = $staropt$star ? $staropt$star[0] : 0;
49444938
var match = token$2(/* Some */[i], env);
4945-
if (typeof match === "number" && !(match !== 12 && match !== 38)) {
4946-
return true;
4939+
if (typeof match === "number") {
4940+
if (match !== 12) {
4941+
return match === 38;
4942+
} else {
4943+
return true;
4944+
}
49474945
} else {
49484946
return false;
49494947
}
@@ -11066,11 +11064,7 @@ function case_list(env, _param) {
1106611064
if (typeof param === "number") {
1106711065
var switcher = param - 2 | 0;
1106811066
if (switcher > 29 || switcher < 0) {
11069-
if (switcher !== 32) {
11070-
return false;
11071-
} else {
11072-
return true;
11073-
}
11067+
return switcher === 32;
1107411068
} else if (switcher > 28 || switcher < 1) {
1107511069
return true;
1107611070
} else {

Diff for: jscomp/test/ocaml_re_test.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ var unknown_state = /* record */[
14551455

14561456
function mk_state(ncol, desc) {
14571457
var match = status(desc);
1458-
var break_state = typeof match === "number" && match !== 0 ? false : true;
1458+
var break_state = typeof match === "number" ? match === 0 : true;
14591459
return /* record */[
14601460
/* idx */break_state ? -3 : desc[/* idx */0],
14611461
/* real_idx */desc[/* idx */0],
@@ -1899,56 +1899,56 @@ function equal$2(_x1, _x2) {
18991899
if (typeof x1 === "number") {
19001900
switch (x1) {
19011901
case 0 :
1902-
if (typeof x2 === "number" && x2 === 0) {
1903-
return true;
1902+
if (typeof x2 === "number") {
1903+
return x2 === 0;
19041904
} else {
19051905
return false;
19061906
}
19071907
case 1 :
1908-
if (typeof x2 === "number" && x2 === 1) {
1909-
return true;
1908+
if (typeof x2 === "number") {
1909+
return x2 === 1;
19101910
} else {
19111911
return false;
19121912
}
19131913
case 2 :
1914-
if (typeof x2 === "number" && x2 === 2) {
1915-
return true;
1914+
if (typeof x2 === "number") {
1915+
return x2 === 2;
19161916
} else {
19171917
return false;
19181918
}
19191919
case 3 :
1920-
if (typeof x2 === "number" && x2 === 3) {
1921-
return true;
1920+
if (typeof x2 === "number") {
1921+
return x2 === 3;
19221922
} else {
19231923
return false;
19241924
}
19251925
case 4 :
1926-
if (typeof x2 === "number" && x2 === 4) {
1927-
return true;
1926+
if (typeof x2 === "number") {
1927+
return x2 === 4;
19281928
} else {
19291929
return false;
19301930
}
19311931
case 5 :
1932-
if (typeof x2 === "number" && x2 === 5) {
1933-
return true;
1932+
if (typeof x2 === "number") {
1933+
return x2 === 5;
19341934
} else {
19351935
return false;
19361936
}
19371937
case 6 :
1938-
if (typeof x2 === "number" && x2 === 6) {
1939-
return true;
1938+
if (typeof x2 === "number") {
1939+
return x2 === 6;
19401940
} else {
19411941
return false;
19421942
}
19431943
case 7 :
1944-
if (typeof x2 === "number" && x2 === 7) {
1945-
return true;
1944+
if (typeof x2 === "number") {
1945+
return x2 === 7;
19461946
} else {
19471947
return false;
19481948
}
19491949
case 8 :
1950-
if (typeof x2 === "number" && x2 === 8) {
1951-
return true;
1950+
if (typeof x2 === "number") {
1951+
return x2 === 8;
19521952
} else {
19531953
return false;
19541954
}

Diff for: jscomp/test/ocaml_typedtree_test.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -35145,20 +35145,14 @@ function parenthesized_ident(name) {
3514535145
var match = Caml_string.get(name, 0);
3514635146
if (match >= 97) {
3514735147
if (match >= 223) {
35148-
if (match !== 247) {
35149-
return false;
35150-
} else {
35151-
return true;
35152-
}
35148+
return match === 247;
3515335149
} else {
3515435150
return match >= 123;
3515535151
}
3515635152
} else if (match >= 91) {
3515735153
return match !== 95;
35158-
} else if (match >= 65) {
35159-
return false;
3516035154
} else {
35161-
return true;
35155+
return match < 65;
3516235156
}
3516335157
}
3516435158
}

Diff for: jscomp/test/qcc.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ function isid(param) {
135135
} else {
136136
return true;
137137
}
138-
} else if (switcher !== 4) {
139-
return false;
140138
} else {
141-
return true;
139+
return switcher === 4;
142140
}
143141
}
144142

Diff for: lib/js/bytes.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,7 @@ function cat(s1, s2) {
161161
function is_space(param) {
162162
var switcher = param - 9 | 0;
163163
if (switcher > 4 || switcher < 0) {
164-
if (switcher !== 23) {
165-
return false;
166-
} else {
167-
return true;
168-
}
164+
return switcher === 23;
169165
} else {
170166
return switcher !== 2;
171167
}

0 commit comments

Comments
 (0)