@@ -5,7 +5,7 @@ val version : string
55
66end = struct
77#1 "bs_version.ml"
8- let version = "1.4.3 "
8+ let version = "1.4.2 "
99
1010end
1111module Terminfo : sig
@@ -66066,6 +66066,13 @@ val rev_toplevel_flatten : J.block -> J.block
6606666066
6606766067val is_constant : J.expression -> bool
6606866068
66069+
66070+ (** Simple expression,
66071+ no computation involved so that it is okay to be duplicated
66072+ *)
66073+
66074+ val is_simple_no_side_effect_expression
66075+ : J.expression -> bool
6606966076end = struct
6607066077#1 "js_analyzer.ml"
6607166078(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -66321,6 +66328,16 @@ let rec is_constant (x : J.expression) =
6632166328 is_constant a && is_constant b
6632266329 | _ -> false
6632366330
66331+
66332+ let rec is_simple_no_side_effect_expression (e : J.expression) =
66333+ match e.expression_desc with
66334+ | Var _
66335+ | Bool _
66336+ | Str _
66337+ | Number _ -> true
66338+ | Dot (e, (_ : string), _) -> is_simple_no_side_effect_expression e
66339+ | _ -> false
66340+
6632466341end
6632566342module Js_op_util : sig
6632666343#1 "js_op_util.mli"
@@ -85774,10 +85791,7 @@ module Js_ast_util : sig
8577485791 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
8577585792
8577685793
85777- (** Simple expression,
85778- no computation involved so that it is okay to be duplicated
85779- *)
85780- val is_simple_expression : J.expression -> bool
85794+
8578185795
8578285796
8578385797
@@ -85819,18 +85833,10 @@ module E = Js_exp_make
8581985833
8582085834module S = Js_stmt_make
8582185835
85822- let rec is_simple_expression (e : J.expression) =
85823- match e.expression_desc with
85824- | Var _
85825- | Bool _
85826- | Str _
85827- | Number _ -> true
85828- | Dot (e, _, _) -> is_simple_expression e
85829- | _ -> false
8583085836
8583185837let rec named_expression (e : J.expression)
8583285838 : (J.statement * Ident.t) option =
85833- if is_simple_expression e then
85839+ if Js_analyzer.is_simple_no_side_effect_expression e then
8583485840 None
8583585841 else
8583685842 let obj = Ext_ident.create Literals.tmp in
@@ -87163,22 +87169,22 @@ let int64_call (fn : string) args =
8716387169(* TODO: make layout easier to change later *)
8716487170let record_info = Lambda.Blk_record [| "hi"; "lo"|]
8716587171let make_const ~lo ~hi =
87166- E.make_block
87167- ~comment:"int64" (E.zero_int_literal)
87168- record_info
87169- [E.int hi; E.to_uint32 @@ E.int lo ; ]
87170- (* If we use unsigned int for lo field,
87171- then we can not use [E.int] which is
87172- assumed to to be signed int.
87173- Or we can use [Int64] to encode
87174- in the ast node?
87175- *)
87176- Immutable
87172+ E.make_block
87173+ ~comment:"int64" (E.zero_int_literal)
87174+ record_info
87175+ [E.int hi; E.to_uint32 @@ E.int lo ; ]
87176+ (* If we use unsigned int for lo field,
87177+ then we can not use [E.int] which is
87178+ assumed to to be signed int.
87179+ Or we can use [Int64] to encode
87180+ in the ast node?
87181+ *)
87182+ Immutable
8717787183let make ~lo ~hi =
87178- E.make_block
87179- ~comment:"int64" (E.zero_int_literal)
87180- record_info [ hi; E.to_uint32 lo ]
87181- Immutable
87184+ E.make_block
87185+ ~comment:"int64" (E.zero_int_literal)
87186+ record_info [ hi; E.to_uint32 lo ]
87187+ Immutable
8718287188let get_lo x = E.index x 1l
8718387189let get_hi x = E.index x 0l
8718487190
@@ -87193,8 +87199,8 @@ let of_const (v : Int64.t) =
8719387199
8719487200let to_int32 args =
8719587201 begin match args with
87196- | [v] -> E.to_int32 @@ get_lo v
87197- | _ -> assert false
87202+ | [v] -> E.to_int32 @@ get_lo v
87203+ | _ -> assert false
8719887204 end
8719987205
8720087206let of_int32 (args : J.expression list) =
@@ -87230,16 +87236,25 @@ let mul args =
8723087236let div args =
8723187237 int64_call "div" args
8723287238
87233- let bit_op op args =
87239+
87240+ (** Note if operands are not pure, we need hold shared value,
87241+ which is a statement [var x = ... ; x ], it does not fit
87242+ current pipe-line fall back to a function call
87243+ *)
87244+ let bit_op op runtime_call args =
8723487245 match args with
8723587246 | [l;r] ->
87236- make ~lo:(op (get_lo l) (get_lo r))
87237- ~hi:(op (get_hi l) (get_hi r))
87247+ (* Int64 is a block in ocaml, a little more conservative in inlining *)
87248+ if Js_analyzer.is_simple_no_side_effect_expression l &&
87249+ Js_analyzer.is_simple_no_side_effect_expression r then
87250+ make ~lo:(op (get_lo l) (get_lo r))
87251+ ~hi:(op (get_hi l) (get_hi r))
87252+ else int64_call runtime_call args
8723887253 | _ -> assert false
8723987254
87240- let xor = bit_op E.int32_bxor
87241- let or_ = bit_op E.int32_bor
87242- let and_ = bit_op E.int32_band
87255+ let xor = bit_op E.int32_bxor "xor"
87256+ let or_ = bit_op E.int32_bor "or_"
87257+ let and_ = bit_op E.int32_band "and_"
8724387258
8724487259
8724587260let lsl_ args =
@@ -87297,9 +87312,9 @@ let to_float (args : J.expression list ) =
8729787312 (* {expression_desc = Number (Int {i = hi; _}) }; *)
8729887313 (* ], _, _, _); _ }] *)
8729987314 (* -> *)
87300-
87315+
8730187316 | [ _ ] ->
87302- int64_call "to_float" args
87317+ int64_call "to_float" args
8730387318 | _ ->
8730487319 assert false
8730587320
@@ -88962,7 +88977,7 @@ let get_default_undefined (arg : J.expression) : J.expression =
8896288977 | Array ([x],_)
8896388978 | Caml_block([x],_,_,_) -> x (* invariant: option encoding *)
8896488979 | _ ->
88965- if Js_ast_util.is_simple_expression arg then
88980+ if Js_analyzer.is_simple_no_side_effect_expression arg then
8896688981 E.econd arg (E.index arg 0l) E.undefined
8896788982 else E.runtime_call Js_config.js_primitive "option_get" [arg]
8896888983
0 commit comments