Skip to content

Commit fbb2774

Browse files
committed
More side effects.
1 parent 51d1abe commit fbb2774

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

compiler/core/js_exp_make.ml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =
17181720
let is_null ?comment (x : t) = triple_equal ?comment x nil
17191721
let 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

17321734
let 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

17441749
let 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

17561766
let make_exception (s : string) =
17571767
pure_runtime_call Primitive_modules.exceptions Literals.create [str s]

compiler/core/js_exp_make.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ val is_null : ?comment:string -> t -> t
365365

366366
val is_undef : ?comment:string -> t -> t
367367

368-
val for_sure_js_null_undefined : J.expression -> bool
368+
val is_null_undefined_constant : J.expression -> bool
369369

370370
val is_null_undefined : ?comment:string -> t -> t
371371

compiler/core/lam_compile_primitive.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,13 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
373373
match args with
374374
| [e1; e2]
375375
when cmp = Ceq
376-
&& (E.for_sure_js_null_undefined e1
377-
|| E.for_sure_js_null_undefined e2) ->
376+
&& (E.is_null_undefined_constant e1
377+
|| E.is_null_undefined_constant e2) ->
378378
E.eq_null_undefined_boolean e1 e2
379379
| [e1; e2]
380380
when cmp = Cneq
381-
&& (E.for_sure_js_null_undefined e1
382-
|| E.for_sure_js_null_undefined e2) ->
381+
&& (E.is_null_undefined_constant e1
382+
|| E.is_null_undefined_constant e2) ->
383383
E.neq_null_undefined_boolean e1 e2
384384
| [e1; e2] ->
385385
Location.prerr_warning loc Warnings.Bs_polymorphic_comparison;

0 commit comments

Comments
 (0)