@@ -1394,13 +1394,15 @@ let rec int_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) =
1394
1394
_ ),
1395
1395
Number (Int {i = 0l }) ) ->
1396
1396
int_comp cmp l r (* = 0 > 0 < 0 *)
1397
- | Ceq , Optional_block _ , Undefined _ | Ceq , Undefined _ , Optional_block _ ->
1397
+ | (Ceq , Optional_block _, Undefined _ | Ceq , Undefined _, Optional_block _)
1398
+ when no_side_effect e0 && no_side_effect e1 ->
1398
1399
false_
1399
1400
| Ceq , _ , _ -> int_equal e0 e1
1400
1401
| Cneq , Optional_block _, Undefined _
1401
1402
| Cneq , Undefined _, Optional_block _
1402
1403
| Cneq , Caml_block _, Number _
1403
- | Cneq , Number _ , Caml_block _ ->
1404
+ | Cneq , Number _, Caml_block _
1405
+ when no_side_effect e0 && no_side_effect e1 ->
1404
1406
true_
1405
1407
| _ -> bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
1406
1408
@@ -1718,7 +1720,7 @@ let of_block ?comment ?e block : t =
1718
1720
let is_null ?comment (x : t ) = triple_equal ?comment x nil
1719
1721
let is_undef ?comment x = triple_equal ?comment x undefined
1720
1722
1721
- let for_sure_js_null_undefined (x : t ) =
1723
+ let is_null_undefined_constant (x : t ) =
1722
1724
match x.expression_desc with
1723
1725
| Null | Undefined _ -> true
1724
1726
| _ -> false
@@ -1730,28 +1732,36 @@ let is_null_undefined ?comment (x : t) : t =
1730
1732
| _ -> {comment; expression_desc = Is_null_or_undefined x}
1731
1733
1732
1734
let eq_null_undefined_boolean ?comment (a : t ) (b : t ) =
1735
+ (* [a == b] when either a or b is null or undefined *)
1733
1736
match (a.expression_desc, b.expression_desc) with
1734
1737
| ( (Null | Undefined _),
1735
- (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _ ) ) ->
1738
+ (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _) )
1739
+ when no_side_effect b ->
1736
1740
false_
1737
1741
| ( (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _),
1738
- (Null | Undefined _ ) ) ->
1742
+ (Null | Undefined _) )
1743
+ when no_side_effect a ->
1739
1744
false_
1740
1745
| Null , Undefined _ | Undefined _ , Null -> false_
1741
1746
| Null , Null | Undefined _ , Undefined _ -> true_
1742
1747
| _ -> {expression_desc = Bin (EqEqEq , a, b); comment}
1743
1748
1744
1749
let neq_null_undefined_boolean ?comment (a : t ) (b : t ) =
1750
+ (* [a != b] when either a or b is null or undefined *)
1745
1751
match (a.expression_desc, b.expression_desc) with
1746
1752
| ( (Null | Undefined _),
1747
- (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _ ) ) ->
1753
+ (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _) )
1754
+ when no_side_effect b ->
1748
1755
true_
1749
1756
| ( (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _),
1750
- (Null | Undefined _ ) ) ->
1757
+ (Null | Undefined _) )
1758
+ when no_side_effect a ->
1751
1759
true_
1752
1760
| Null , Null | Undefined _ , Undefined _ -> false_
1753
1761
| Null , Undefined _ | Undefined _ , Null -> true_
1754
- | _ -> {expression_desc = Bin (NotEqEq , a, b); comment}
1762
+ | _ ->
1763
+ let _ = assert false in
1764
+ {expression_desc = Bin (NotEqEq , a, b); comment}
1755
1765
1756
1766
let make_exception (s : string ) =
1757
1767
pure_runtime_call Primitive_modules. exceptions Literals. create [str s]
0 commit comments