@@ -1394,13 +1394,15 @@ let rec int_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) =
13941394 _ ),
13951395 Number (Int {i = 0l }) ) ->
13961396 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 ->
13981399 false_
13991400 | Ceq , _ , _ -> int_equal e0 e1
14001401 | Cneq , Optional_block _, Undefined _
14011402 | Cneq , Undefined _, Optional_block _
14021403 | Cneq , Caml_block _, Number _
1403- | Cneq , Number _ , Caml_block _ ->
1404+ | Cneq , Number _, Caml_block _
1405+ when no_side_effect e0 && no_side_effect e1 ->
14041406 true_
14051407 | _ -> bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
14061408
@@ -1718,7 +1720,7 @@ let of_block ?comment ?e block : t =
17181720let is_null ?comment (x : t ) = triple_equal ?comment x nil
17191721let is_undef ?comment x = triple_equal ?comment x undefined
17201722
1721- let for_sure_js_null_undefined (x : t ) =
1723+ let is_null_undefined_constant (x : t ) =
17221724 match x.expression_desc with
17231725 | Null | Undefined _ -> true
17241726 | _ -> false
@@ -1730,28 +1732,36 @@ let is_null_undefined ?comment (x : t) : t =
17301732 | _ -> {comment; expression_desc = Is_null_or_undefined x}
17311733
17321734let eq_null_undefined_boolean ?comment (a : t ) (b : t ) =
1735+ (* [a == b] when either a or b is null or undefined *)
17331736 match (a.expression_desc, b.expression_desc) with
17341737 | ( (Null | Undefined _),
1735- (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _ ) ) ->
1738+ (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _) )
1739+ when no_side_effect b ->
17361740 false_
17371741 | ( (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _),
1738- (Null | Undefined _ ) ) ->
1742+ (Null | Undefined _) )
1743+ when no_side_effect a ->
17391744 false_
17401745 | Null , Undefined _ | Undefined _ , Null -> false_
17411746 | Null , Null | Undefined _ , Undefined _ -> true_
17421747 | _ -> {expression_desc = Bin (EqEqEq , a, b); comment}
17431748
17441749let neq_null_undefined_boolean ?comment (a : t ) (b : t ) =
1750+ (* [a != b] when either a or b is null or undefined *)
17451751 match (a.expression_desc, b.expression_desc) with
17461752 | ( (Null | Undefined _),
1747- (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _ ) ) ->
1753+ (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _) )
1754+ when no_side_effect b ->
17481755 true_
17491756 | ( (Bool _ | Number _ | Typeof _ | Fun _ | Array _ | Caml_block _),
1750- (Null | Undefined _ ) ) ->
1757+ (Null | Undefined _) )
1758+ when no_side_effect a ->
17511759 true_
17521760 | Null , Null | Undefined _ , Undefined _ -> false_
17531761 | 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}
17551765
17561766let make_exception (s : string ) =
17571767 pure_runtime_call Primitive_modules. exceptions Literals. create [str s]
0 commit comments