diff --git a/compiler/core/j.ml b/compiler/core/j.ml index 4e7a5cd58e..638c59995d 100644 --- a/compiler/core/j.ml +++ b/compiler/core/j.ml @@ -33,8 +33,6 @@ type mutable_flag = Js_op.mutable_flag type binop = Js_op.binop -type int_op = Js_op.int_op -type kind = Js_op.kind type property = Js_op.property type number = Js_op.number type ident_info = Js_op.ident_info @@ -74,7 +72,6 @@ and exception_ident = ident and for_ident = ident and for_direction = Js_op.direction_flag and property_map = (property_name * expression) list -and length_object = Js_op.length_object and delim = External_arg_spec.delim = DNone | DStarJ | DNoQuotes | DBackQuotes and record_rest_field = { @@ -83,7 +80,7 @@ and record_rest_field = { } and expression_desc = - | Length of expression * length_object + | Length of expression | Is_null_or_undefined of expression (** where we use a trick [== null ] *) | String_append of expression * expression | Bool of bool (* js true/false*) @@ -98,9 +95,6 @@ and expression_desc = | Seq of expression * expression | Cond of expression * expression * expression | Bin of binop * expression * expression - (* [int_op] will guarantee return [int32] bits - https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators *) - (* | Int32_bin of int_op * expression * expression *) | FlatCall of expression * expression (* f.apply(null,args) -- Fully applied guaranteed TODO: once we know args's shape -- @@ -133,7 +127,7 @@ and expression_desc = All exported declarations have to be OCaml identifiers 2. Javascript dot (need to be preserved/or using quote) *) - | New of expression * expression list option (* TODO: option remove *) + | New of expression * expression list | Var of vident | Fun of { is_method: bool; @@ -151,15 +145,13 @@ and expression_desc = | Raw_js_code of Js_raw_info.t (* literally raw JS code *) - | Array of expression list * mutable_flag + | Array of expression list | Optional_block of expression * bool (* [true] means [identity] *) | Caml_block of expression list * mutable_flag * expression * tag_info (* The third argument is [tag] , forth is [tag_info] *) - (* | Caml_uninitialized_obj of expression * expression *) (* [tag] and [size] tailed for [Obj.new_block] *) | Caml_block_tag of expression * string (* e.tag *) - (* | Caml_block_set_length of expression * expression *) (* It will just fetch tag, to make it safe, when creating it, we need apply "|0", we don't do it in the last step since "|0" can potentially be optimized @@ -334,17 +326,13 @@ and deps_program = { int_clause; string_clause; for_direction; - (* exception_ident; *) - for_direction; expression_desc; statement_desc; for_ident_expression; label; finish_ident_expression; property_map; - length_object; record_rest_field; - (* for_ident; *) required_modules; case_clause; |]; diff --git a/compiler/core/js_analyzer.ml b/compiler/core/js_analyzer.ml index 9c82c14e29..f0598e4ebd 100644 --- a/compiler/core/js_analyzer.ml +++ b/compiler/core/js_analyzer.ml @@ -105,7 +105,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) = no_side_effect a && no_side_effect b | Is_null_or_undefined b -> no_side_effect b | Str _ -> true - | Array (xs, _mutable_flag) | Caml_block (xs, _mutable_flag, _, _) -> + | Array xs | Caml_block (xs, _, _, _) -> (* create [immutable] block, does not really mean that this opreation itself is [pure]. @@ -119,7 +119,7 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) = | None -> true) && Ext_list.for_all_snd kvs no_side_effect | String_append (a, b) | Seq (a, b) -> no_side_effect a && no_side_effect b - | Length (e, _) | Caml_block_tag (e, _) | Typeof e -> no_side_effect e + | Length e | Caml_block_tag (e, _) | Typeof e -> no_side_effect e | Bin (op, a, b) -> op <> Eq && no_side_effect a && no_side_effect b | Tagged_template (call_expr, strings, values) -> no_side_effect call_expr @@ -311,7 +311,7 @@ let rev_toplevel_flatten block = | Array_index (a,b) -> is_constant a && is_constant b | Str (b,_) -> b | Number _ -> true (* Can be refined later *) - | Array (xs,_mutable_flag) -> Ext_list.for_all xs is_constant + | Array xs -> Ext_list.for_all xs is_constant | Caml_block(xs, Immutable, tag, _) -> Ext_list.for_all xs is_constant && is_constant tag | Bin (_op, a, b) -> diff --git a/compiler/core/js_arr.ml b/compiler/core/js_arr.ml deleted file mode 100644 index 0c83e248b3..0000000000 --- a/compiler/core/js_arr.ml +++ /dev/null @@ -1,29 +0,0 @@ -(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P. - * Copyright (C) 2016 - Hongbo Zhang, Authors of ReScript - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -module E = Js_exp_make - -let set_array e e0 e1 = E.assign (E.array_index e e0) e1 - -let ref_array e e0 = E.array_index e e0 diff --git a/compiler/core/js_arr.mli b/compiler/core/js_arr.mli deleted file mode 100644 index 9c9dda8338..0000000000 --- a/compiler/core/js_arr.mli +++ /dev/null @@ -1,27 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * Copyright (C) 2016 - Hongbo Zhang, Authors of ReScript - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -val set_array : J.expression -> J.expression -> J.expression -> J.expression - -val ref_array : J.expression -> J.expression -> J.expression diff --git a/compiler/core/js_dump.ml b/compiler/core/js_dump.ml index 91cb93c9b5..d486357a20 100644 --- a/compiler/core/js_dump.ml +++ b/compiler/core/js_dump.ml @@ -150,7 +150,6 @@ let raw_snippet_exp_simple_enough (s : string) = *) let rec exp_need_paren ?(arrow = false) (e : J.expression) = match e.expression_desc with - (* | Caml_uninitialized_obj _ *) | Call ({expression_desc = Raw_js_code _}, _, _) -> true | Raw_js_code {code_info = Exp _} | Fun _ @@ -754,8 +753,7 @@ and expression_desc cxt ~(level : int) f x : cxt = P.paren_group f 0 (fun _ -> arguments cxt f (e :: el))) else ( Curry_gen.pp_app_any f; - P.paren_group f 0 (fun _ -> - arguments cxt f [e; E.array Mutable el])))) + P.paren_group f 0 (fun _ -> arguments cxt f [e; E.array el])))) | FlatCall (e, el) -> P.group f 0 (fun _ -> let cxt = expression ~level:15 cxt f e in @@ -939,7 +937,7 @@ and expression_desc cxt ~(level : int) f x : cxt = P.string f "+"; P.space f; expression ~level:rght cxt f e2) - | Array (el, _) -> ( + | Array el -> ( (* TODO: simplify for singleton list *) match el with | [] | [_] -> P.bracket_group f 1 (fun _ -> array_element_list cxt f el) @@ -955,11 +953,11 @@ and expression_desc cxt ~(level : int) f x : cxt = Ext_list.map_combine fields el (fun x -> Js_op.Lit (Ext_ident.convert x)) )) (*name convention of Record is slight different from modules*) - | Caml_block (el, mutable_flag, _, Blk_record {fields}) -> + | Caml_block (el, _, _, Blk_record {fields}) -> if Array.length fields <> 0 && Ext_array.for_alli fields (fun i (v, _) -> string_of_int i = v) - then expression_desc cxt ~level f (Array (el, mutable_flag)) + then expression_desc cxt ~level f (Array el) else let fields = Ext_list.array_list_filter_map fields el (fun (f, opt) x -> @@ -1050,8 +1048,8 @@ and expression_desc cxt ~(level : int) f x : cxt = | Caml_block (_, _, _, (Blk_module_export _ | Blk_some | Blk_some_not_nested)) -> assert false - | Caml_block (el, mutable_flag, _tag, Blk_tuple) -> - expression_desc cxt ~level f (Array (el, mutable_flag)) + | Caml_block (el, _, _tag, Blk_tuple) -> + expression_desc cxt ~level f (Array el) | Caml_block_tag (e, tag) -> P.group f 1 (fun _ -> let cxt = expression ~level:15 cxt f e in @@ -1072,23 +1070,20 @@ and expression_desc cxt ~(level : int) f x : cxt = refer and export *) cxt) - | Length (e, _) -> + | Length e -> (*Todo: check parens *) P.cond_paren_group f (level > 15) (fun _ -> let cxt = expression ~level:15 cxt f e in P.string f L.dot; P.string f L.length; cxt) - | New (e, el) -> + | New (e, args) -> P.cond_paren_group f (level > 15) (fun _ -> P.group f 0 (fun _ -> P.string f L.new_; P.space f; let cxt = expression ~level:16 cxt f e in - P.paren_group f 0 (fun _ -> - match el with - | Some el -> arguments cxt f el - | None -> cxt))) + P.paren_group f 0 (fun _ -> arguments cxt f args))) | Cond (e, e1, e2) -> let action () = let cxt = expression ~level:3 cxt f e in @@ -1200,8 +1195,8 @@ and print_jsx cxt ?(spread_props : J.expression option) if n = "children" then if fn_name = "jsxs" then match e.J.expression_desc with - | J.Array (xs, _) - | J.Optional_block ({expression_desc = J.Array (xs, _)}, _) -> + | J.Array xs | J.Optional_block ({expression_desc = J.Array xs}, _) + -> Some xs | _ -> Some [e] else Some [e] diff --git a/compiler/core/js_exp_make.ml b/compiler/core/js_exp_make.ml index 1d9ad3bd8b..6196de4809 100644 --- a/compiler/core/js_exp_make.ml +++ b/compiler/core/js_exp_make.ml @@ -38,8 +38,7 @@ let rec remove_pure_sub_exp (x : t) : t option = | Var _ | Str _ | Number _ -> None (* Can be refined later *) | Array_index (a, b) -> if is_pure_sub_exp a && is_pure_sub_exp b then None else Some x - | Array (xs, _mutable_flag) -> - if Ext_list.for_all xs is_pure_sub_exp then None else Some x + | Array xs -> if Ext_list.for_all xs is_pure_sub_exp then None else Some x | Seq (a, b) -> ( match (remove_pure_sub_exp a, remove_pure_sub_exp b) with | None, None -> None @@ -51,9 +50,6 @@ let rec remove_pure_sub_exp (x : t) : t option = and is_pure_sub_exp (x : t) = remove_pure_sub_exp x = None -(* let mk ?comment exp : t = - {expression_desc = exp ; comment } *) - let var ?comment id : t = {expression_desc = Var (Id id); comment; source_loc = None} @@ -165,8 +161,6 @@ let pure_runtime_call module_name fn_name args = (runtime_var_dot module_name fn_name) args -let runtime_ref module_name fn_name = runtime_var_dot module_name fn_name - let str ?(delim = J.DNone) ?comment txt : t = {expression_desc = Str {txt; delim}; comment; source_loc = None} @@ -177,8 +171,8 @@ let raw_js_code ?comment info s : t = source_loc = None; } -let array ?comment mt es : t = - {expression_desc = Array (es, mt); comment; source_loc = None} +let array ?comment es : t = + {expression_desc = Array es; comment; source_loc = None} let record_rest ?comment fields source : t = {expression_desc = Record_rest (fields, source); comment; source_loc = None} @@ -255,7 +249,7 @@ let is_array (e0 : t) : t = } let new_ ?comment e0 args : t = - {expression_desc = New (e0, Some args); comment; source_loc = None} + {expression_desc = New (e0, args); comment; source_loc = None} let unit : t = { @@ -264,9 +258,6 @@ let unit : t = source_loc = None; } -(* let math ?comment v args : t = - {comment ; expression_desc = Math(v,args)} *) - (* we can do constant folding here, but need to make sure the result is consistent {[ let f x = string_of_int x @@ -332,7 +323,7 @@ let dummy_obj ?comment (info : Lam_tag_info.t) : t = | Blk_poly_var _ | Blk_extension | Blk_record_ext _ -> {comment; source_loc = None; expression_desc = Object (None, [])} | Blk_tuple | Blk_module_export _ -> - {comment; source_loc = None; expression_desc = Array ([], Mutable)} + {comment; source_loc = None; expression_desc = Array []} | Blk_some | Blk_some_not_nested -> assert false (* TODO: complete @@ -355,9 +346,6 @@ let rec seq ?comment (e0 : t) (e1 : t) : t = let fuse_to_seq x xs = if xs = [] then x else Ext_list.fold_left xs x seq -(* let empty_string_literal : t = - {expression_desc = Str (true,""); comment = None; source_loc = None} *) - let zero_int_literal : t = { expression_desc = Number (Int {i = 0l; c = None}); @@ -479,7 +467,7 @@ let float_mod ?comment e1 e2 : J.expression = let array_index ?comment (e0 : t) (e1 : t) : t = match (e0.expression_desc, e1.expression_desc) with - | Array (l, _), Number (Int {i; _}) + | Array l, Number (Int {i; _}) (* Float i -- should not appear here *) when no_side_effect e0 -> ( match Ext_list.nth_opt l (Int32.to_int i) with @@ -490,8 +478,7 @@ let array_index ?comment (e0 : t) (e1 : t) : t = let array_index_by_int ?comment (e : t) (pos : int32) : t = match e.expression_desc with - | Array (l, _) (* Float i -- should not appear here *) - | Caml_block (l, _, _, _) + | (Array l (* Float i -- should not appear here *) | Caml_block (l, _, _, _)) when no_side_effect e -> ( match Ext_list.nth_opt l (Int32.to_int pos) with | Some x -> x @@ -509,10 +496,8 @@ let array_index_by_int ?comment (e : t) (pos : int32) : t = } let record_access (e : t) (name : string) (pos : int32) = - (* let name = Ext_ident.convert name in *) match e.expression_desc with - | Array (l, _) (* Float i -- should not appear here *) - | Caml_block (l, _, _, _) + | (Array l (* Float i -- should not appear here *) | Caml_block (l, _, _, _)) when no_side_effect e -> ( match Ext_list.nth_opt l (Int32.to_int pos) with | Some x -> x @@ -571,8 +556,7 @@ let poly_var_value_access (e : t) = let extension_access (e : t) name (pos : int32) : t = match e.expression_desc with - | Array (l, _) (* Float i -- should not appear here *) - | Caml_block (l, _, _, _) + | (Array l (* Float i -- should not appear here *) | Caml_block (l, _, _, _)) when no_side_effect e -> ( match Ext_list.nth_opt l (Int32.to_int pos) with | Some x -> x @@ -637,9 +621,6 @@ let assign_by_exp (e : t) index value : t = } value -let assign_by_int ?comment e0 (index : int32) value = - assign_by_exp e0 (int ?comment index) value - let record_assign (e : t) (pos : int32) (name : string) (value : t) = match e.expression_desc with | Array _ @@ -689,15 +670,15 @@ let extension_assign (e : t) (pos : int32) name (value : t) = let array_length ?comment (e : t) : t = match e.expression_desc with (* TODO: use array instead? *) - | (Array (l, _) | Caml_block (l, _, _, _)) when no_side_effect e -> + | (Array l | Caml_block (l, _, _, _)) when no_side_effect e -> int ?comment (Int32.of_int (List.length l)) - | _ -> {expression_desc = Length (e, Array); comment; source_loc = None} + | _ -> {expression_desc = Length e; comment; source_loc = None} let string_length ?comment (e : t) : t = match e.expression_desc with | Str {txt; delim = DNone} -> int ?comment (Int32.of_int (String.length txt)) (* No optimization for {j||j}*) - | _ -> {expression_desc = Length (e, String); comment; source_loc = None} + | _ -> {expression_desc = Length e; comment; source_loc = None} let function_length ?comment (e : t) : t = match e.expression_desc with @@ -705,12 +686,7 @@ let function_length ?comment (e : t) : t = let params_length = List.length params in int ?comment (Int32.of_int (if is_method then params_length - 1 else params_length)) - | _ -> {expression_desc = Length (e, Function); comment; source_loc = None} - -(** no dependency introduced *) -(* let js_global_dot ?comment (x : string) (e1 : string) : t = - { expression_desc = Static_index (js_global x, e1,None); comment; source_loc = None} -*) + | _ -> {expression_desc = Length e; comment; source_loc = None} let rec string_append ?comment (e : t) (el : t) : t = let concat a b ~delim = {e with expression_desc = Str {txt = a ^ b; delim}} in @@ -771,9 +747,9 @@ let rec triple_equal ?comment (e0 : t) (e1 : t) : t = let bin ?comment (op : J.binop) (e0 : t) (e1 : t) : t = match (op, e0.expression_desc, e1.expression_desc) with | EqEqEq, _, _ -> triple_equal ?comment e0 e1 - | Ge, Length (e, _), Number (Int {i = 0l}) when no_side_effect e -> + | Ge, Length e, Number (Int {i = 0l}) when no_side_effect e -> true_ (* x.length >=0 | [x] is pure -> true*) - | Gt, Length (_, _), Number (Int {i = 0l}) -> + | Gt, Length _, Number (Int {i = 0l}) -> (* [e] is kept so no side effect check needed *) {expression_desc = Bin (NotEqEq, e0, e1); comment; source_loc = None} | _ -> {expression_desc = Bin (op, e0, e1); comment; source_loc = None} @@ -1390,16 +1366,6 @@ let rec float_equal ?comment (e0 : t) (e1 : t) : t = match (e0.expression_desc, e1.expression_desc) with | Number (Int {i = i0; _}), Number (Int {i = i1}) -> bool (i0 = i1) | Undefined _, Undefined _ -> true_ - (* | (Bin(Bor, - {expression_desc = Number(Int {i = 0l; _})}, - ({expression_desc = Caml_block_tag _; _} as a )) - | - Bin(Bor, - ({expression_desc = Caml_block_tag _; _} as a), - {expression_desc = Number (Int {i = 0l; _})})), - Number (Int {i = 0l;}) when e1.comment = None - -> (** (x.tag | 0) === 0 *) - not a *) | ( ( Bin ( Bor, {expression_desc = Number (Int {i = 0l; _})}, @@ -1540,14 +1506,10 @@ let string_equal ?comment (e0 : t) (e1 : t) : t = string_comp Ceq ?comment e0 e1 let is_type_number ?comment (e : t) : t = string_equal ?comment (typeof e) (str "number") -let is_type_string ?comment (e : t) : t = - string_equal ?comment (typeof e) (str "string") - let is_type_object (e : t) : t = string_equal (typeof e) (str "object") let obj_length ?comment e : t = - to_int32 - {expression_desc = Length (e, Caml_block); comment; source_loc = None} + to_int32 {expression_desc = Length e; comment; source_loc = None} let compare_int_aux (cmp : Lam_compat.comparison) (l : int) r = match cmp with @@ -1613,9 +1575,6 @@ let bool_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) = bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1) | _, _ -> bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 -let float_comp cmp ?comment e0 e1 = - bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 - let js_comp cmp ?comment e0 e1 = bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 @@ -1702,34 +1661,14 @@ let rec float_add ?comment (e1 : t) (e2 : t) = source_loc = None; expression_desc = Bin (Plus, a1, int (Int32.add k j)); } - (* bin ?comment Plus a1 (int (k + j)) *) - (* TODO remove commented code ?? *) - (* | Bin(Plus, a0 , ({expression_desc = Number (Int a1)} )), *) - (* Bin(Plus, b0 , ({expression_desc = Number (Int b1)} )) *) - (* -> *) - (* bin ?comment Plus a1 (int (a1 + b1)) *) - - (* | _, Bin(Plus, b0, ({expression_desc = Number _} as v)) *) - (* -> *) - (* bin ?comment Plus (bin ?comment Plus e1 b0) v *) - (* | Bin(Plus, a1 , ({expression_desc = Number _} as v)), _ *) - (* | Bin(Plus, ({expression_desc = Number _} as v),a1), _ *) - (* -> *) - (* bin ?comment Plus (bin ?comment Plus a1 e2 ) v *) - (* | Number _, _ *) - (* -> *) - (* bin ?comment Plus e2 e1 *) | _ -> {comment; source_loc = None; expression_desc = Bin (Plus, e1, e2)} -(* bin ?comment Plus e1 e2 *) (* associative is error prone due to overflow *) and float_minus ?comment (e1 : t) (e2 : t) : t = match (e1.expression_desc, e2.expression_desc) with | Number (Int {i; _}), Number (Int {i = j; _}) -> int ?comment (Int32.sub i j) | _ -> {comment; source_loc = None; expression_desc = Bin (Minus, e1, e2)} -(* bin ?comment Minus e1 e2 *) -let unchecked_int32_add ?comment e1 e2 = float_add ?comment e1 e2 let int32_add ?comment e1 e2 = to_int32 (float_add ?comment e1 e2) let offset e1 (offset : int) = @@ -1738,12 +1677,8 @@ let offset e1 (offset : int) = let int32_minus ?comment e1 e2 : J.expression = to_int32 (float_minus ?comment e1 e2) -let unchecked_int32_minus ?comment e1 e2 : J.expression = - float_minus ?comment e1 e2 - let float_div ?comment e1 e2 = bin ?comment Div e1 e2 let float_pow ?comment e1 e2 = bin ?comment Pow e1 e2 -let float_notequal ?comment e1 e2 = bin ?comment NotEqEq e1 e2 let int32_asr ?comment e1 e2 : J.expression = {comment; source_loc = None; expression_desc = Bin (Asr, e1, e2)} @@ -1803,9 +1738,6 @@ let int32_mul ?comment (e1 : J.expression) (e2 : J.expression) : J.expression = else to_int32 (float_mul ?comment e1 e2) | _ -> to_int32 (float_mul ?comment e1 e2) -let unchecked_int32_mul ?comment e1 e2 : J.expression = - {comment; source_loc = None; expression_desc = Bin (Mul, e1, e2)} - let int_bnot ?comment (e : t) : J.expression = match e.expression_desc with | Number (Int {i}) -> int ?comment (Int32.lognot i) @@ -1838,9 +1770,6 @@ let rec int32_band ?comment (e1 : J.expression) (e2 : J.expression) : int32_band a e2 | _ -> {comment; source_loc = None; expression_desc = Bin (Band, e1, e2)} -(* let int32_bin ?comment op e1 e2 : J.expression = *) -(* {expression_desc = Int32_bin(op,e1, e2); comment; source_loc = None} *) - let bigint_op ?comment op (e1 : t) (e2 : t) = bin ?comment op e1 e2 let bigint_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) = diff --git a/compiler/core/js_exp_make.mli b/compiler/core/js_exp_make.mli index 84ffed98d6..5b98caf8c4 100644 --- a/compiler/core/js_exp_make.mli +++ b/compiler/core/js_exp_make.mli @@ -45,10 +45,6 @@ val var : ?comment:string -> J.ident -> t val js_global : ?comment:string -> string -> t -val runtime_var_dot : ?comment:string -> string -> string -> t - -(* val runtime_var_vid : string -> string -> J.vident *) - val ml_var_dot : ?comment:string -> ?dynamic_import:bool -> Ident.t -> string -> t (** [ml_var_dot ocaml_module name] @@ -84,17 +80,6 @@ val runtime_call : (* args *) t -val pure_runtime_call : - string -> - (* module_name *) - string -> - (* fn_name *) - t list -> - (* args *) - t - -val runtime_ref : string -> string -> t - val str : ?delim:J.delim -> ?comment:string -> string -> t val record_rest : ?comment:string -> J.record_rest_field list -> t -> t @@ -129,11 +114,8 @@ val bigint : ?comment:string -> bool -> string -> t val float : ?comment:string -> string -> t -(* val empty_string_literal : t *) (* TODO: we can do hash consing for small integers *) val zero_int_literal : t - -(* val one_int_literal : t *) val zero_float_lit : t val zero_bigint_literal : t @@ -159,13 +141,6 @@ val string_append : ?comment:string -> t -> t -> t we can not tag [js] object, since it can be frozen *) -(* val var_dot : ?comment:string -> Ident.t -> string -> t *) - -(* val bind_var_call : ?comment:string -> Ident.t -> string -> t list -> t *) - -(* val bind_call : ?comment:string -> J.expression -> string -> J.expression list -> t *) -(* val js_global_dot : ?comment:string -> string -> string -> t *) - val string_index : ?comment:string -> t -> t -> t val array_index : ?comment:string -> t -> t -> t @@ -190,14 +165,6 @@ val poly_var_value_access : t -> t val extension_assign : t -> int32 -> string -> t -> t -val assign_by_int : ?comment:string -> t -> int32 -> t -> t -(** - [assign_by_int e i v] - if the expression [e] is a temporay block - which has no side effect, - write to it does not really make sense, - optimize it away *) - val assign_by_exp : t -> t -> t -> t val assign : ?comment:string -> t -> t -> t @@ -209,8 +176,6 @@ val emit_check : t Ast_untagged_variants.Dynamic_checks.t -> t val triple_equal : ?comment:string -> t -> t -> t (* TODO: reduce [triple_equal] use *) -val float_equal : ?comment:string -> t -> t -> t - val int_equal : ?comment:string -> t -> t -> t val int_bnot : ?comment:string -> t -> t @@ -231,8 +196,6 @@ val is_a_literal_case : t -> t -val is_type_string : ?comment:string -> t -> t - val is_type_object : t -> t val typeof : ?comment:string -> t -> t @@ -241,20 +204,14 @@ val is_array : t -> t val to_int32 : ?comment:string -> t -> t -val unchecked_int32_add : ?comment:string -> t -> t -> t - val int32_add : ?comment:string -> t -> t -> t val offset : t -> int -> t -val unchecked_int32_minus : ?comment:string -> t -> t -> t - val int32_minus : ?comment:string -> t -> t -> t val int32_mul : ?comment:string -> t -> t -> t -val unchecked_int32_mul : ?comment:string -> t -> t -> t - val int32_div : checked:bool -> ?comment:string -> t -> t -> t val int32_mod : checked:bool -> ?comment:string -> t -> t -> t @@ -281,8 +238,6 @@ val float_mul : ?comment:string -> t -> t -> t val float_div : ?comment:string -> t -> t -> t -val float_notequal : ?comment:string -> t -> t -> t - val float_mod : ?comment:string -> t -> t -> t val float_pow : ?comment:string -> t -> t -> t @@ -293,8 +248,6 @@ val bool_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t val string_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t -val float_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t - val bigint_op : ?comment:string -> Js_op.binop -> t -> t -> t val bigint_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t @@ -315,7 +268,7 @@ val tagged_template : ?comment:string -> t -> t list -> t list -> t val new_ : ?comment:string -> J.expression -> J.expression list -> t -val array : ?comment:string -> J.mutable_flag -> J.expression list -> t +val array : ?comment:string -> J.expression list -> t val optional_block : J.expression -> J.expression diff --git a/compiler/core/js_fold.ml b/compiler/core/js_fold.ml index e6af7a6761..ebaccce531 100644 --- a/compiler/core/js_fold.ml +++ b/compiler/core/js_fold.ml @@ -81,14 +81,9 @@ class fold = _self) _self - method length_object : length_object -> 'self_type = unknown _self - method expression_desc : expression_desc -> 'self_type = function - | Length (_x0, _x1) -> - let _self = _self#expression _x0 in - let _self = _self#length_object _x1 in - _self + | Length _x0 -> _self#expression _x0 | Is_null_or_undefined _x0 -> let _self = _self#expression _x0 in _self @@ -149,12 +144,7 @@ class fold = _self | New (_x0, _x1) -> let _self = _self#expression _x0 in - let _self = - option - (fun _self -> list (fun _self -> _self#expression) _self) - _self _x1 - in - _self + list (fun _self -> _self#expression) _self _x1 | Var _x0 -> let _self = _self#vident _x0 in _self @@ -164,9 +154,7 @@ class fold = _self | Str _ -> _self | Raw_js_code _ -> _self - | Array (_x0, _x1) -> - let _self = list (fun _self -> _self#expression) _self _x0 in - _self + | Array _x0 -> list (fun _self -> _self#expression) _self _x0 | Optional_block (_x0, _x1) -> let _self = _self#expression _x0 in _self diff --git a/compiler/core/js_of_lam_array.ml b/compiler/core/js_of_lam_array.ml index e80f0e5a55..d395822386 100644 --- a/compiler/core/js_of_lam_array.ml +++ b/compiler/core/js_of_lam_array.ml @@ -25,7 +25,7 @@ module E = Js_exp_make (* Parrayref(u|s) *) -let make_array mt args = E.array mt args +let make_array args = E.array args let set_array e e0 e1 = E.assign (E.array_index e e0) e1 diff --git a/compiler/core/js_of_lam_array.mli b/compiler/core/js_of_lam_array.mli index d3a54f8369..c3e68255dd 100644 --- a/compiler/core/js_of_lam_array.mli +++ b/compiler/core/js_of_lam_array.mli @@ -24,7 +24,7 @@ (** Utilities for creating Array of JS IR *) -val make_array : J.mutable_flag -> J.expression list -> J.expression +val make_array : J.expression list -> J.expression (** create an array *) val set_array : J.expression -> J.expression -> J.expression -> J.expression diff --git a/compiler/core/js_of_lam_block.ml b/compiler/core/js_of_lam_block.ml index 850e8ad2f9..e694bd3c92 100644 --- a/compiler/core/js_of_lam_block.ml +++ b/compiler/core/js_of_lam_block.ml @@ -24,12 +24,8 @@ module E = Js_exp_make -(* TODO: it would be even better, if the [tag_info] contains more information - about immutablility -*) let make_block mutable_flag (tag_info : Lam_tag_info.t) tag args = - match tag_info with - | _ -> E.make_block tag tag_info args mutable_flag + E.make_block tag tag_info args mutable_flag let field (field_info : Lam_compat.field_dbg_info) e (i : int32) = match field_info with diff --git a/compiler/core/js_op.ml b/compiler/core/js_op.ml index 769af321af..3b18707546 100644 --- a/compiler/core/js_op.ml +++ b/compiler/core/js_op.ml @@ -26,19 +26,18 @@ type binop = | Eq - (* acutally assignment .. + (* Actually assignment. TODO: move it into statement, so that all expressions - are side efffect free (except function calls) + are side effect free (except function calls) *) | Or | And | EqEqEq - | NotEqEq (* | InstanceOf *) + | NotEqEq | Lt | Le | Gt | Ge - | Bnot | Bor | Bxor | Band @@ -53,71 +52,6 @@ type binop = | Pow | InstanceOf -(** - note that we don't need raise [Div_by_zero] in ReScript - - {[ - let add x y = x + y (* | 0 *) - let minus x y = x - y (* | 0 *) - let mul x y = x * y (* caml_mul | Math.imul *) - let div x y = x / y (* caml_div (x/y|0)*) - let imod x y = x mod y (* caml_mod (x%y) (zero_divide)*) - - let bor x y = x lor y (* x | y *) - let bxor x y = x lxor y (* x ^ y *) - let band x y = x land y (* x & y *) - let ilnot y = lnot y (* let lnot x = x lxor (-1) *) - let ilsl x y = x lsl y (* x << y*) - let ilsr x y = x lsr y (* x >>> y | 0 *) - let iasr x y = x asr y (* x >> y *) - ]} - - - Note that js treat unsigned shift 0 bits in a special way - Unsigned shifts convert their left-hand side to Uint32, - signed shifts convert it to Int32. - Shifting by 0 digits returns the converted value. - {[ - function ToUint32(x) { - return x >>> 0; - } - function ToInt32(x) { - return x >> 0; - } - ]} - So in Js, [-1 >>>0] will be the largest Uint32, while [-1>>0] will remain [-1] - and [-1 >>> 0 >> 0 ] will be [-1] -*) -type int_op = - | Bor - | Bxor - | Band - | Lsl - | Lsr - | Asr - | Plus - (* for [+], given two numbers - x + y | 0 - *) - | Minus - (* x - y | 0 *) - | Mul - (* *) - | Div - (* x / y | 0 *) - | Mod - (* x % y *) - | Pow (* x ** y | 0 *) - -(* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise_operators - {[ - ~ - ]} - ~0xff -> -256 - design; make sure each operation type is consistent -*) -type level = Log | Info | Warn | Error - type kind = | Ml | Runtime @@ -131,8 +65,6 @@ type property = Lam_compat.let_kind = Strict | Alias | StrictOpt | Variable type property_name = Lit of string | Symbol_name -type 'a access = Getter | Setter - (* literal char *) type float_lit = {f: string} [@@unboxed] @@ -143,7 +75,7 @@ type number = | Int of {i: int32; c: int option} | BigInt of bigint_lit -(* becareful when constant folding +/-, +(* Be careful when constant folding +/-, since we treat it as js nativeint, bitwise operators: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators The operands of all bitwise operators are converted to signed 32-bit integers in two's complement format.' @@ -153,14 +85,6 @@ type mutable_flag = Mutable | Immutable | NA type direction_flag = Upto | Downto | Up -(* - {[ - let rec x = 1 :: y - and y = 1 :: x - ]} -*) -type recursive_info = SingleRecursive | NonRecursie | NA - type used_stats = | Dead_pure (* only [Dead] should be taken serious, @@ -185,18 +109,8 @@ type used_stats = | Scanning_non_pure | NA -type ident_info = { - (* mutable recursive_info : recursive_info; *) - mutable used_stats: used_stats; -} +type ident_info = {mutable used_stats: used_stats} type exports = Ident.t list type tag_info = Lam_tag_info.t - -type length_object = Array | String | Bytes | Function | Caml_block - -(** TODO: define constant - for better constant folding *) -(* type constant = *) -(* | Const_int of int *) -(* | Const_ *) diff --git a/compiler/core/js_op_util.ml b/compiler/core/js_op_util.ml index 1ac9909021..9d4da5cddb 100644 --- a/compiler/core/js_op_util.ml +++ b/compiler/core/js_op_util.ml @@ -39,23 +39,12 @@ let op_prec (op : Js_op.binop) = | Bxor -> (6, 6, 6) | Band -> (7, 7, 7) | Lsl | Lsr | Asr -> (10, 10, 11) - | Bnot | Plus | Minus -> (11, 11, 12) - | Mul | Div | Mod -> (12, 12, 13) - | Pow -> (13, 14, 13) - -let op_int_prec (op : Js_op.int_op) = - match op with - | Bor -> (5, 5, 5) - | Bxor -> (6, 6, 6) - | Band -> (7, 7, 7) - | Lsl | Lsr | Asr -> (10, 10, 11) | Plus | Minus -> (11, 11, 12) | Mul | Div | Mod -> (12, 12, 13) - | Pow -> (13, 14, 12) + | Pow -> (13, 14, 13) let op_str (op : Js_op.binop) = match op with - | Bnot -> "~" | Bor -> "|" | Bxor -> "^" | Band -> "&" @@ -79,32 +68,6 @@ let op_str (op : Js_op.binop) = | Ge -> ">=" | InstanceOf -> "instanceof" -let op_int_str (op : Js_op.int_op) = - match op with - | Bor -> "|" - | Bxor -> "^" - | Band -> "&" - | Lsl -> "<<" - | Lsr -> ">>>" - | Asr -> ">>" - | Plus -> "+" - | Minus -> "-" - | Mul -> "*" - | Div -> "/" - | Mod -> "%" - | Pow -> "**" - -let str_of_used_stats x = - match (x : Js_op.used_stats) with - | Js_op.Dead_pure -> "Dead_pure" - | Dead_non_pure -> "Dead_non_pure" - | Exported -> "Exported" - | Once_pure -> "Once_pure" - | Used -> "Used" - | Scanning_pure -> "Scanning_pure" - | Scanning_non_pure -> "Scanning_non_pure" - | NA -> "NA" - let update_used_stats (ident_info : J.ident_info) used_stats = match ident_info.used_stats with | Dead_pure | Dead_non_pure | Exported -> () diff --git a/compiler/core/js_op_util.mli b/compiler/core/js_op_util.mli index db11b3ec08..8ed1ba9b4e 100644 --- a/compiler/core/js_op_util.mli +++ b/compiler/core/js_op_util.mli @@ -28,12 +28,6 @@ val op_prec : Js_op.binop -> int * int * int val op_str : Js_op.binop -> string -val op_int_prec : Js_op.int_op -> int * int * int - -val op_int_str : Js_op.int_op -> string - -val str_of_used_stats : Js_op.used_stats -> string - val update_used_stats : J.ident_info -> Js_op.used_stats -> unit val same_vident : J.vident -> J.vident -> bool diff --git a/compiler/core/js_record_fold.ml b/compiler/core/js_record_fold.ml index 99c3777f61..359f81e4d3 100644 --- a/compiler/core/js_record_fold.ml +++ b/compiler/core/js_record_fold.ml @@ -87,14 +87,9 @@ let property_map : 'a. ('a, property_map) fn = st) _self st arg -let length_object : 'a. ('a, length_object) fn = unknown - let expression_desc : 'a. ('a, expression_desc) fn = fun _self st -> function - | Length (_x0, _x1) -> - let st = _self.expression _self st _x0 in - let st = length_object _self st _x1 in - st + | Length _x0 -> _self.expression _self st _x0 | Is_null_or_undefined _x0 -> let st = _self.expression _self st _x0 in st @@ -155,12 +150,7 @@ let expression_desc : 'a. ('a, expression_desc) fn = st | New (_x0, _x1) -> let st = _self.expression _self st _x0 in - let st = - option - (fun _self st arg -> list _self.expression _self st arg) - _self st _x1 - in - st + list _self.expression _self st _x1 | Var _x0 -> let st = _self.vident _self st _x0 in st @@ -170,9 +160,7 @@ let expression_desc : 'a. ('a, expression_desc) fn = st | Str _ -> st | Raw_js_code _ -> st - | Array (_x0, _x1) -> - let st = list _self.expression _self st _x0 in - st + | Array _x0 -> list _self.expression _self st _x0 | Optional_block (_x0, _x1) -> let st = _self.expression _self st _x0 in st diff --git a/compiler/core/js_record_iter.ml b/compiler/core/js_record_iter.ml index 5009326fff..e836617d76 100644 --- a/compiler/core/js_record_iter.ml +++ b/compiler/core/js_record_iter.ml @@ -77,13 +77,9 @@ let property_map : property_map fn = fun _self arg -> list (fun _self (_x0, _x1) -> _self.expression _self _x1) _self arg -let length_object : length_object fn = unknown - let expression_desc : expression_desc fn = fun _self -> function - | Length (_x0, _x1) -> - _self.expression _self _x0; - length_object _self _x1 + | Length _x0 -> _self.expression _self _x0 | Is_null_or_undefined _x0 -> _self.expression _self _x0 | String_append (_x0, _x1) -> _self.expression _self _x0; @@ -124,14 +120,14 @@ let expression_desc : expression_desc fn = | Static_index (_x0, _x1, _x2) -> _self.expression _self _x0 | New (_x0, _x1) -> _self.expression _self _x0; - option (fun _self arg -> list _self.expression _self arg) _self _x1 + list _self.expression _self _x1 | Var _x0 -> _self.vident _self _x0 | Fun {params; body} -> list _self.ident _self params; _self.block _self body | Str _ -> () | Raw_js_code _ -> () - | Array (_x0, _x1) -> list _self.expression _self _x0 + | Array _x0 -> list _self.expression _self _x0 | Optional_block (_x0, _x1) -> _self.expression _self _x0 | Caml_block (_x0, _x1, _x2, _x3) -> list _self.expression _self _x0; diff --git a/compiler/core/js_record_map.ml b/compiler/core/js_record_map.ml index 4731157e93..0ab675b3df 100644 --- a/compiler/core/js_record_map.ml +++ b/compiler/core/js_record_map.ml @@ -87,14 +87,11 @@ let property_map : property_map fn = (_x0, _x1)) _self arg -let length_object : length_object fn = unknown - let expression_desc : expression_desc fn = fun _self -> function - | Length (_x0, _x1) -> + | Length _x0 -> let _x0 = _self.expression _self _x0 in - let _x1 = length_object _self _x1 in - Length (_x0, _x1) + Length _x0 | Is_null_or_undefined _x0 -> let _x0 = _self.expression _self _x0 in Is_null_or_undefined _x0 @@ -155,9 +152,7 @@ let expression_desc : expression_desc fn = Static_index (_x0, _x1, _x2) | New (_x0, _x1) -> let _x0 = _self.expression _self _x0 in - let _x1 = - option (fun _self arg -> list _self.expression _self arg) _self _x1 - in + let _x1 = list _self.expression _self _x1 in New (_x0, _x1) | Var _x0 -> let _x0 = _self.vident _self _x0 in @@ -168,9 +163,9 @@ let expression_desc : expression_desc fn = Fun {fun_ with params; body} | Str _ as v -> v | Raw_js_code _ as v -> v - | Array (_x0, _x1) -> + | Array _x0 -> let _x0 = list _self.expression _self _x0 in - Array (_x0, _x1) + Array _x0 | Optional_block (_x0, _x1) -> let _x0 = _self.expression _self _x0 in Optional_block (_x0, _x1) diff --git a/compiler/core/js_stmt_make.ml b/compiler/core/js_stmt_make.ml index 1c2ec55023..5a794bdeb4 100644 --- a/compiler/core/js_stmt_make.ml +++ b/compiler/core/js_stmt_make.ml @@ -32,7 +32,6 @@ let return_stmt ?comment e : t = let empty_stmt : t = {statement_desc = Block []; comment = None; source_loc = None} -(* let empty_block : J.block = [] *) let throw_stmt ?comment v : t = {statement_desc = Throw v; comment; source_loc = None} @@ -86,13 +85,6 @@ let define_variable ?comment ?ident_info ~kind (v : Ident.t) source_loc = None; } -(* let alias_variable ?comment ~exp (v:Ident.t) : t= - {statement_desc = - Variable { - ident = v; value = Some exp; property = Alias; - ident_info = {used_stats = NA } }; - comment; source_loc = None} *) - let int_switch ?(comment : string option) ?(declaration : (J.property * Ident.t) option) ?(default : J.block option) (e : J.expression) (clauses : (int * J.case_clause) list) : t = @@ -383,5 +375,3 @@ let continue_ ?label () : t = let debugger_stmt ?comment () : t = {statement_desc = Debugger; comment; source_loc = None} - -let debugger_block : t list = [debugger_stmt ()] diff --git a/compiler/core/js_stmt_make.mli b/compiler/core/js_stmt_make.mli index e83c8f8a9f..04a3feac3e 100644 --- a/compiler/core/js_stmt_make.mli +++ b/compiler/core/js_stmt_make.mli @@ -26,10 +26,6 @@ type t = J.statement -(** empty statement, block of length 0 *) -(* val empty_stmt : - t *) - val throw_stmt : ?comment:string -> J.expression -> t val if_ : @@ -97,39 +93,8 @@ val define_variable : J.expression -> t -(** created an alias expression *) -(* val alias_variable : - ?comment:string -> - exp:J.expression -> - Ident.t -> - t *) - val assign : ?comment:string -> J.ident -> J.expression -> t -(** Used in cases like - {[ - let x = while true do - ... - done in .. - ]} -*) -(* val assign_unit : - ?comment:string -> - J.ident -> - t *) - -(** used in cases like - {[ - let x = while true do - ... - done in .. - ]} -*) -(* val declare_unit : - ?comment:string -> - J.ident -> - t *) - val while_ : ?comment:string -> ?label:J.label -> J.expression -> J.block -> t val for_ : @@ -159,21 +124,8 @@ val exp : ?comment:string -> J.expression -> t val return_stmt : ?comment:string -> J.expression -> t -(* val return_unit : t list *) -(** for ocaml function which returns unit - it will be compiled into [return 0] in js *) - -(** if [label] is not set, it will default to empty *) -(* val continue_stmt : - ?comment:string -> - ?label:J.label -> - unit -> - t *) - val break_ : ?label:J.label -> unit -> t val continue_ : ?label:J.label -> unit -> t val debugger_stmt : ?comment:string -> unit -> t - -val debugger_block : t list diff --git a/compiler/core/lam_compat.ml b/compiler/core/lam_compat.ml index a652d74ca4..65615c5322 100644 --- a/compiler/core/lam_compat.ml +++ b/compiler/core/lam_compat.ml @@ -63,7 +63,7 @@ let cmp_int (cmp : comparison) (a : int) b : bool = type let_kind = Lambda.let_kind = Strict | Alias | StrictOpt | Variable type field_dbg_info = Lambda.field_dbg_info = - | Fld_record of {name: string; mutable_flag: Asttypes.mutable_flag} + | Fld_record of {name: string} | Fld_module of {name: string} | Fld_record_inline of {name: string} | Fld_record_extension of {name: string} diff --git a/compiler/core/lam_compat.mli b/compiler/core/lam_compat.mli index 4d67d95242..1082b9d3ee 100644 --- a/compiler/core/lam_compat.mli +++ b/compiler/core/lam_compat.mli @@ -27,7 +27,7 @@ type comparison = Lambda.comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge type let_kind = Lambda.let_kind = Strict | Alias | StrictOpt | Variable type field_dbg_info = Lambda.field_dbg_info = - | Fld_record of {name: string; mutable_flag: Asttypes.mutable_flag} + | Fld_record of {name: string} | Fld_module of {name: string} | Fld_record_inline of {name: string} | Fld_record_extension of {name: string} diff --git a/compiler/core/lam_compile_external_call.ml b/compiler/core/lam_compile_external_call.ml index bc12f870df..531cc746fc 100644 --- a/compiler/core/lam_compile_external_call.ml +++ b/compiler/core/lam_compile_external_call.ml @@ -211,8 +211,7 @@ let assemble_args_has_splice (arg_types : specs) (args : exprs) : | {arg_label; arg_type} :: labels, arg :: args -> ( let accs, eff = aux labels args in match (args, (arg : E.t)) with - | [], {expression_desc = Array (ls, _mutable_flag); _} -> - (Ext_list.append ls accs, eff) + | [], {expression_desc = Array ls; _} -> (Ext_list.append ls accs, eff) | _ -> if args = [] then dynamic := true; let acc, new_eff = ocaml_to_js_eff ~arg_type ~arg_label arg in @@ -417,7 +416,8 @@ let translate_ffi ?(transformed_jsx = false) (cxt : Lam_compile_context.t) add_eff cur_eff @@ match args with - | [obj; v] -> Js_arr.ref_array (translate_scoped_access scopes obj) v + | [obj; v] -> + Js_of_lam_array.ref_array (translate_scoped_access scopes obj) v | _ -> assert false) | Js_set_index {js_set_index_scopes = scopes} -> ( let args, cur_eff = assemble_args_no_splice arg_types args in @@ -425,5 +425,5 @@ let translate_ffi ?(transformed_jsx = false) (cxt : Lam_compile_context.t) @@ match args with | [obj; v; value] -> - Js_arr.set_array (translate_scoped_access scopes obj) v value + Js_of_lam_array.set_array (translate_scoped_access scopes obj) v value | _ -> assert false) diff --git a/compiler/core/lam_compile_primitive.ml b/compiler/core/lam_compile_primitive.ml index 4cbaf9b416..47b41b1789 100644 --- a/compiler/core/lam_compile_primitive.ml +++ b/compiler/core/lam_compile_primitive.ml @@ -99,8 +99,8 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) match args with | [ fn; - {expression_desc = Array (strings, _); _}; - {expression_desc = Array (values, _); _}; + {expression_desc = Array strings; _}; + {expression_desc = Array values; _}; ] -> E.tagged_template fn strings values | _ -> assert false) @@ -568,7 +568,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | _ -> assert false) | Parrayrefs -> E.runtime_call Primitive_modules.array "get" args | Parraysets -> E.runtime_call Primitive_modules.array "set" args - | Pmakearray -> Js_of_lam_array.make_array Mutable args + | Pmakearray -> Js_of_lam_array.make_array args | Pmakelist -> Js_of_lam_block.make_block (Js_op_util.of_lam_mutable_flag Mutable) @@ -576,7 +576,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) (E.small_int 0) args | Pmakedict -> ( match args with - | [{expression_desc = Array (items, _)}] -> + | [{expression_desc = Array items}] -> E.obj (items |> List.filter_map (fun (exp : J.expression) -> diff --git a/compiler/core/lam_convert.ml b/compiler/core/lam_convert.ml index 13193e3686..267c1d8379 100644 --- a/compiler/core/lam_convert.ml +++ b/compiler/core/lam_convert.ml @@ -23,7 +23,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) let caml_id_field_info : Lambda.field_dbg_info = - Fld_record {name = Literals.exception_id; mutable_flag = Immutable} + Fld_record {name = Literals.exception_id} let lam_caml_id : Lam_primitive.t = Pfield (0, caml_id_field_info) let prim = Lam.prim @@ -288,13 +288,13 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Poffsetint x -> prim ~primitive:(Poffsetint x) ~args loc | Poffsetref x -> prim ~primitive:(Poffsetref x) ~args loc | Pfloatcomp x -> prim ~primitive:(Pfloatcomp x) ~args loc - | Pmakearray _mutable_flag (*FIXME*) -> prim ~primitive:Pmakearray ~args loc + | Pmakearray -> prim ~primitive:Pmakearray ~args loc | Parraylength -> prim ~primitive:Parraylength ~args loc | Parrayrefu -> prim ~primitive:Parrayrefu ~args loc | Parraysetu -> prim ~primitive:Parraysetu ~args loc | Parrayrefs -> prim ~primitive:Parrayrefs ~args loc | Parraysets -> prim ~primitive:Parraysets ~args loc - | Pmakelist _mutable_flag (*FIXME*) -> prim ~primitive:Pmakelist ~args loc + | Pmakelist -> prim ~primitive:Pmakelist ~args loc | Pmakedict -> prim ~primitive:Pmakedict ~args loc | Pdict_has -> prim ~primitive:Pdict_has ~args loc | Pawait -> prim ~primitive:Pawait ~args loc diff --git a/compiler/ml/lambda.ml b/compiler/ml/lambda.ml index ea759e2a50..8dd296b270 100644 --- a/compiler/ml/lambda.ml +++ b/compiler/ml/lambda.ml @@ -112,7 +112,7 @@ let ref_tag_info : tag_info = Blk_record {fields = [|("contents", false)|]; mutable_flag = Mutable} type field_dbg_info = - | Fld_record of {name: string; mutable_flag: Asttypes.mutable_flag} + | Fld_record of {name: string} | Fld_module of {name: string} | Fld_record_inline of {name: string} | Fld_record_extension of {name: string} @@ -125,17 +125,13 @@ type field_dbg_info = let fld_record (lbl : label) = Fld_record - { - name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name; - mutable_flag = lbl.lbl_mut; - } + {name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name} let fld_record_extension (lbl : label) = Fld_record_extension {name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name} -let ref_field_info : field_dbg_info = - Fld_record {name = "contents"; mutable_flag = Mutable} +let ref_field_info : field_dbg_info = Fld_record {name = "contents"} type set_field_dbg_info = | Fld_record_set of string @@ -261,14 +257,14 @@ type primitive = | Pstringmax | Pstringadd (* Array operations *) - | Pmakearray of Asttypes.mutable_flag + | Pmakearray | Parraylength | Parrayrefu | Parraysetu | Parrayrefs | Parraysets (* List primitives *) - | Pmakelist of Asttypes.mutable_flag + | Pmakelist (* dict primitives *) | Pmakedict | Pdict_has diff --git a/compiler/ml/lambda.mli b/compiler/ml/lambda.mli index 43b42c5849..3a4ae0f904 100644 --- a/compiler/ml/lambda.mli +++ b/compiler/ml/lambda.mli @@ -83,7 +83,7 @@ val blk_record_inlined : val ref_tag_info : tag_info type field_dbg_info = - | Fld_record of {name: string; mutable_flag: Asttypes.mutable_flag} + | Fld_record of {name: string} | Fld_module of {name: string} | Fld_record_inline of {name: string} | Fld_record_extension of {name: string} @@ -230,14 +230,14 @@ type primitive = | Pstringmax | Pstringadd (* Array operations *) - | Pmakearray of mutable_flag + | Pmakearray | Parraylength | Parrayrefu | Parraysetu | Parrayrefs | Parraysets (* List primitives *) - | Pmakelist of Asttypes.mutable_flag + | Pmakelist (* dict primitives *) | Pmakedict | Pdict_has diff --git a/compiler/ml/printlambda.ml b/compiler/ml/printlambda.ml index bb5c8832d3..681f33a98b 100644 --- a/compiler/ml/printlambda.ml +++ b/compiler/ml/printlambda.ml @@ -223,14 +223,12 @@ let primitive ppf = function | Pstringmax -> fprintf ppf "max" | Pstringadd -> fprintf ppf "string.concat" | Parraylength -> fprintf ppf "array.length" - | Pmakearray Mutable -> fprintf ppf "makearray" - | Pmakearray Immutable -> fprintf ppf "makearray_imm" + | Pmakearray -> fprintf ppf "makearray" | Parrayrefu -> fprintf ppf "array.unsafe_get" | Parraysetu -> fprintf ppf "array.unsafe_set" | Parrayrefs -> fprintf ppf "array.get" | Parraysets -> fprintf ppf "array.set" - | Pmakelist Mutable -> fprintf ppf "makelist" - | Pmakelist Immutable -> fprintf ppf "makelist_imm" + | Pmakelist -> fprintf ppf "makelist" | Pmakedict -> fprintf ppf "makedict" | Pdict_has -> fprintf ppf "dict.has" | Pisint -> fprintf ppf "isint" diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 3ecb5b77f9..bc8eb28c96 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -385,7 +385,7 @@ let primitives_table = ("%curry_apply6", Pcurry_apply 6); ("%curry_apply7", Pcurry_apply 7); ("%curry_apply8", Pcurry_apply 8); - ("%makemutablelist", Pmakelist Mutable); + ("%makemutablelist", Pmakelist); ("%unsafe_to_method", Pjs_fn_method); (* Compiler internals, never expose to ReScript files *) ("#raw_expr", Pjs_raw_expr); @@ -397,7 +397,7 @@ let primitives_table = ("#is_nullable", Pisnullable); ("#null_to_opt", Pnull_to_opt); ("#nullable_to_opt", Pnullable_to_opt); - ("#makemutablelist", Pmakelist Mutable); + ("#makemutablelist", Pmakelist); ("#import", Pimport); (* FIXME: Deprecated *) ("%obj_field", Parrayrefu); @@ -928,7 +928,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda = Lprim (access, [transl_exp arg; transl_exp newval], e.exp_loc) | Texp_array expr_list -> let ll = transl_list expr_list in - Lprim (Pmakearray Mutable, ll, e.exp_loc) + Lprim (Pmakearray, ll, e.exp_loc) | Texp_ifthenelse (cond, ifso, Some ifnot) -> Lifthenelse (transl_exp cond, transl_exp ifso, transl_exp ifnot) | Texp_ifthenelse (cond, ifso, None) ->