diff --git a/jscomp/all.depend b/jscomp/all.depend index 99909023bf..36139597ae 100644 --- a/jscomp/all.depend +++ b/jscomp/all.depend @@ -365,7 +365,7 @@ core/js_of_lam_array.cmi : core/j.cmx core/js_of_lam_block.cmi : core/js_op.cmx core/j.cmx core/js_of_lam_string.cmi : core/j.cmx core/js_of_lam_tuple.cmi : core/j.cmx -core/js_of_lam_record.cmi : core/js_exp_make.cmi core/j.cmx +core/js_of_lam_record.cmi : core/j.cmx core/js_of_lam_float_record.cmi : core/j.cmx core/js_arr.cmi : core/j.cmx core/lam_compile_const.cmi : core/lam.cmi core/j.cmx \ @@ -645,12 +645,11 @@ core/lam_compile_external_obj.cmx : core/lam_compile_external_call.cmx \ core/lam_compile_primitive.cmx : core/lam_print.cmx \ core/lam_dispatch_primitive.cmx core/lam_compile_external_call.cmx \ core/lam_compile_context.cmx core/lam.cmx core/js_runtime_modules.cmx \ - core/js_op_util.cmx core/js_of_lam_string.cmx core/js_of_lam_record.cmx \ - core/js_of_lam_option.cmx core/js_of_lam_float_record.cmx \ - core/js_of_lam_exception.cmx core/js_of_lam_block.cmx \ - core/js_of_lam_array.cmx core/js_long.cmx core/js_exp_make.cmx \ - common/js_config.cmx core/j.cmx common/bs_warnings.cmx \ - core/lam_compile_primitive.cmi + core/js_op_util.cmx core/js_of_lam_string.cmx core/js_of_lam_option.cmx \ + core/js_of_lam_float_record.cmx core/js_of_lam_exception.cmx \ + core/js_of_lam_block.cmx core/js_of_lam_array.cmx core/js_long.cmx \ + core/js_exp_make.cmx common/js_config.cmx core/j.cmx \ + common/bs_warnings.cmx core/lam_compile_primitive.cmi core/lam_compile.cmx : ext/literals.cmx core/lam_util.cmx \ common/lam_methname.cmx core/lam_exit_code.cmx \ core/lam_eta_conversion.cmx core/lam_compile_primitive.cmx \ diff --git a/jscomp/core/j.ml b/jscomp/core/j.ml index b580e3b5e1..0f8ce11f2f 100644 --- a/jscomp/core/j.ml +++ b/jscomp/core/j.ml @@ -104,8 +104,6 @@ and expression_desc = | Char_to_int of expression | Is_null_or_undefined of expression (** where we use a trick [== null ] *) - | Array_copy of expression (* shallow copy, like [x.slice] *) - | String_append of expression * expression | Bool of bool (* js true/false*) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence diff --git a/jscomp/core/js_analyzer.ml b/jscomp/core/js_analyzer.ml index 949c132abd..492df86778 100644 --- a/jscomp/core/js_analyzer.ml +++ b/jscomp/core/js_analyzer.ml @@ -115,7 +115,6 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) = | Bin (op, a, b) -> op <> Eq && no_side_effect a && no_side_effect b | Math _ - | Array_copy _ | Js_not _ | Cond _ @@ -254,7 +253,6 @@ let rec eq_expression | Char_of_int _ | Char_to_int _ | Is_null_or_undefined _ - | Array_copy _ | String_append _ | Typeof _ | Js_not _ diff --git a/jscomp/core/js_dump.ml b/jscomp/core/js_dump.ml index 959b40ee9c..dcd71c5e9b 100644 --- a/jscomp/core/js_dump.ml +++ b/jscomp/core/js_dump.ml @@ -494,14 +494,6 @@ and expression 1 cxt f el ) ) - - | Array_copy e -> - P.group f 1 (fun _ -> - let cxt = expression 15 cxt f e in - P.string f ".slice"; - P.string f "()" ; - cxt - ) | Char_to_int e -> begin match e.expression_desc with | String_access (a,b) -> @@ -1039,7 +1031,6 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t = | Length _ | Caml_block_set_length _ | Call _ - | Array_copy _ | Caml_block_tag _ | Seq _ | Dot _ diff --git a/jscomp/core/js_exp_make.ml b/jscomp/core/js_exp_make.ml index c69b589c8a..d4ff8715f2 100644 --- a/jscomp/core/js_exp_make.ml +++ b/jscomp/core/js_exp_make.ml @@ -441,8 +441,6 @@ let char_to_int ?comment (v : t) : t = | _ -> {comment; expression_desc = Char_to_int v } -let array_copy ?comment e : t = - { comment ; expression_desc = Array_copy e} let rec string_append ?comment (e : t) (el : t) : t = match e.expression_desc , el.expression_desc with diff --git a/jscomp/core/js_exp_make.mli b/jscomp/core/js_exp_make.mli index c8fc9b25f5..ac956bbd1d 100644 --- a/jscomp/core/js_exp_make.mli +++ b/jscomp/core/js_exp_make.mli @@ -146,7 +146,7 @@ val function_length : unary_op val char_of_int : unary_op val char_to_int : unary_op -val array_copy : unary_op + val string_append : binary_op (** When in ES6 mode, we can use Symbol to guarantee its uniquess, diff --git a/jscomp/core/js_fold.ml b/jscomp/core/js_fold.ml index 9540e705ac..7564b4be71 100644 --- a/jscomp/core/js_fold.ml +++ b/jscomp/core/js_fold.ml @@ -124,8 +124,7 @@ class virtual fold = Qualified (_, Runtime, Some "caml_int_compare") ]} *) - (** where we use a trick [== null ] *) - (* shallow copy, like [x.slice] *) (* js true/false*) + (** where we use a trick [== null ] *) (* js true/false*) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence [typeof] is an operator *) @@ -320,7 +319,6 @@ class virtual fold = | Char_of_int _x -> let o = o#expression _x in o | Char_to_int _x -> let o = o#expression _x in o | Is_null_or_undefined _x -> let o = o#expression _x in o - | Array_copy _x -> let o = o#expression _x in o | String_append (_x, _x_i1) -> let o = o#expression _x in let o = o#expression _x_i1 in o | Bool _x -> let o = o#bool _x in o diff --git a/jscomp/core/js_map.ml b/jscomp/core/js_map.ml index dfb241d0e8..5d65054601 100644 --- a/jscomp/core/js_map.ml +++ b/jscomp/core/js_map.ml @@ -137,8 +137,7 @@ class virtual map = Qualified (_, Runtime, Some "caml_int_compare") ]} *) - (** where we use a trick [== null ] *) - (* shallow copy, like [x.slice] *) (* js true/false*) + (** where we use a trick [== null ] *) (* js true/false*) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence [typeof] is an operator *) @@ -346,7 +345,6 @@ class virtual map = | Char_to_int _x -> let _x = o#expression _x in Char_to_int _x | Is_null_or_undefined _x -> let _x = o#expression _x in Is_null_or_undefined _x - | Array_copy _x -> let _x = o#expression _x in Array_copy _x | String_append (_x, _x_i1) -> let _x = o#expression _x in let _x_i1 = o#expression _x_i1 in String_append (_x, _x_i1) diff --git a/jscomp/core/js_of_lam_record.ml b/jscomp/core/js_of_lam_record.ml index bd9ae9b09d..c2aa24985c 100644 --- a/jscomp/core/js_of_lam_record.ml +++ b/jscomp/core/js_of_lam_record.ml @@ -49,10 +49,4 @@ let field field_info e i = | Lambda.Fld_module s -> E.index ~comment:s e i -(** - used in [Pduprecord] - this is due to we encode record as an array, it is going to change - if we have another encoding -*) -let copy = E.array_copy diff --git a/jscomp/core/js_of_lam_record.mli b/jscomp/core/js_of_lam_record.mli index 3c8dea23ec..990731daf7 100644 --- a/jscomp/core/js_of_lam_record.mli +++ b/jscomp/core/js_of_lam_record.mli @@ -34,4 +34,3 @@ val field : Lambda.field_dbg_info -> J.expression -> J.jsint ->J.expression -val copy : Js_exp_make.unary_op diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index 89c9233e1f..547a6bdb6e 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -675,27 +675,18 @@ let translate loc | Pctconst ct -> begin match ct with - | Big_endian -> - if Sys.big_endian then E.caml_true - else E.caml_false + | Big_endian -> E.bool Sys.big_endian | Word_size -> E.small_int Sys.word_size - | Ostype_unix -> - if Sys.unix then E.caml_true else E.caml_false - | Ostype_win32 -> - if Sys.win32 then E.caml_true else E.caml_false - | Ostype_cygwin -> - if Sys.cygwin then E.caml_true else E.caml_false - end - (* | Psetglobal _ -> *) - (* assert false (\* already handled *\) *) - (* assert false *) - | Pduprecord ((Record_regular - | Record_float ),_size) -> (* _size is the length of all_lables*) - begin match args with - | [e] -> Js_of_lam_record.copy e - | _ -> assert false + | Ostype_unix -> E.bool Sys.unix + | Ostype_win32 -> E.bool Sys.win32 + | Ostype_cygwin -> E.bool Sys.cygwin end + | Pduprecord ((Record_regular + | Record_float ),_) -> + (* _size is the length of all_lables*) + (* TODO: In debug mode, need switch to *) + Lam_dispatch_primitive.translate loc "caml_array_dup" args | Pbigarrayref (unsafe, dimension, kind, layout) -> (* can be refined to diff --git a/jscomp/core/lam_dispatch_primitive.ml b/jscomp/core/lam_dispatch_primitive.ml index 451e875255..9e2d8ffcfb 100644 --- a/jscomp/core/lam_dispatch_primitive.ml +++ b/jscomp/core/lam_dispatch_primitive.ml @@ -657,7 +657,7 @@ let translate loc (prim_name : string) and discarded it immediately This could be canceled *) - | _ -> E.array_copy a + | _ -> call Js_runtime_modules.array end | _ -> assert false end diff --git a/jscomp/others/belt_Array.ml b/jscomp/others/belt_Array.ml index b01a76f016..af917f6314 100644 --- a/jscomp/others/belt_Array.ml +++ b/jscomp/others/belt_Array.ml @@ -37,13 +37,9 @@ external makeUninitialized : int -> 'a Js.undefined array = "Array" [@@bs.new] external makeUninitializedUnsafe : int -> 'a array = "Array" [@@bs.new] -let copy a = - let l = length a in - let v = makeUninitializedUnsafe l in - for i = 0 to l - 1 do - setUnsafe v i (getUnsafe a i) - done ; - v +external copy : 'a array -> (_ [@bs.as 0]) -> 'a array = + "slice" [@@bs.send] + let swapUnsafe xs i j = let tmp = getUnsafe xs i in diff --git a/jscomp/others/belt_Array.mli b/jscomp/others/belt_Array.mli index cdabbf9c3c..0320f60ec2 100644 --- a/jscomp/others/belt_Array.mli +++ b/jscomp/others/belt_Array.mli @@ -183,7 +183,7 @@ val slice: 'a array -> offset:int -> len:int -> 'a array *) -val copy: 'a array -> 'a array +external copy : 'a array -> (_ [@bs.as 0]) -> 'a array = "slice" [@@bs.send] (** [copy a] @return a copy of [a], that is, a fresh array diff --git a/jscomp/runtime/caml_array.ml b/jscomp/runtime/caml_array.ml index d12d0ae258..d10625d9b5 100644 --- a/jscomp/runtime/caml_array.ml +++ b/jscomp/runtime/caml_array.ml @@ -29,6 +29,9 @@ external new_uninitialized : int -> 'a array = "Array" [@@bs.new] external append : 'a array -> 'a array -> 'a array = "concat" [@@bs.send] +external caml_array_dup : 'a array -> (_ [@bs.as 0]) -> 'a array = + "slice" [@@bs.send] + let caml_array_sub (x : 'a array) (offset : int) (len : int) = let result = new_uninitialized len in @@ -99,3 +102,4 @@ let caml_array_blit a1 i1 a2 i2 len = for j = len - 1 downto 0 do a2.(j+i2) <- a1.(j+i1) done + diff --git a/jscomp/runtime/caml_array.mli b/jscomp/runtime/caml_array.mli index 3dc4845f3a..1b45183cf5 100644 --- a/jscomp/runtime/caml_array.mli +++ b/jscomp/runtime/caml_array.mli @@ -27,7 +27,8 @@ external new_uninitialized : int -> 'a array = "Array" [@@bs.new] external append : 'a array -> 'a array -> 'a array = "concat" [@@bs.send] -(*external make : int -> 'a -> 'a array = "caml_make_vect"*) + +val caml_array_dup : 'a array -> 'a array val caml_array_sub : 'a array -> int -> int -> 'a array diff --git a/jscomp/test/bs_array_test.js b/jscomp/test/bs_array_test.js index 1179e2fade..0b7db5c944 100644 --- a/jscomp/test/bs_array_test.js +++ b/jscomp/test/bs_array_test.js @@ -432,7 +432,7 @@ eq("File \"bs_array_test.ml\", line 126, characters 5-12", makeMatrixExn(0, 3, 1 eq("File \"bs_array_test.ml\", line 127, characters 5-12", makeMatrixExn(1, 1, 1), /* array */[/* array */[1]]); -eq("File \"bs_array_test.ml\", line 128, characters 5-12", Belt_Array.copy(/* array */[]), /* array */[]); +eq("File \"bs_array_test.ml\", line 128, characters 5-12", /* array */[].slice(0), /* array */[]); eq("File \"bs_array_test.ml\", line 129, characters 5-12", Belt_Array.map(/* array */[], (function (prim) { return prim + 1 | 0; @@ -648,7 +648,7 @@ var a$3 = Belt_Array.makeBy(10, (function (x) { Belt_Array.fill(a$3, 0, 3, 0); -eq("File \"bs_array_test.ml\", line 172, characters 6-13", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 172, characters 6-13", a$3.slice(0), /* array */[ 0, 0, 0, @@ -663,7 +663,7 @@ eq("File \"bs_array_test.ml\", line 172, characters 6-13", Belt_Array.copy(a$3), Belt_Array.fill(a$3, 2, 8, 1); -eq("File \"bs_array_test.ml\", line 174, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 174, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -678,7 +678,7 @@ eq("File \"bs_array_test.ml\", line 174, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, 8, 1, 9); -eq("File \"bs_array_test.ml\", line 176, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 176, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -693,7 +693,7 @@ eq("File \"bs_array_test.ml\", line 176, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, 8, 2, 9); -eq("File \"bs_array_test.ml\", line 178, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 178, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -708,7 +708,7 @@ eq("File \"bs_array_test.ml\", line 178, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, 8, 3, 12); -eq("File \"bs_array_test.ml\", line 180, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 180, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -723,7 +723,7 @@ eq("File \"bs_array_test.ml\", line 180, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, -2, 3, 11); -eq("File \"bs_array_test.ml\", line 182, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 182, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -738,7 +738,7 @@ eq("File \"bs_array_test.ml\", line 182, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, -3, 3, 10); -eq("File \"bs_array_test.ml\", line 184, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 184, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -753,7 +753,7 @@ eq("File \"bs_array_test.ml\", line 184, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, -3, 1, 7); -eq("File \"bs_array_test.ml\", line 186, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 186, characters 5-12", a$3.slice(0), /* array */[ 0, 0, 1, @@ -768,7 +768,7 @@ eq("File \"bs_array_test.ml\", line 186, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, -13, 1, 7); -eq("File \"bs_array_test.ml\", line 188, characters 5-12", Belt_Array.copy(a$3), /* array */[ +eq("File \"bs_array_test.ml\", line 188, characters 5-12", a$3.slice(0), /* array */[ 7, 0, 1, @@ -783,11 +783,11 @@ eq("File \"bs_array_test.ml\", line 188, characters 5-12", Belt_Array.copy(a$3), Belt_Array.fill(a$3, -13, 12, 7); -eq("File \"bs_array_test.ml\", line 190, characters 5-12", Belt_Array.copy(a$3), Belt_Array.make(10, 7)); +eq("File \"bs_array_test.ml\", line 190, characters 5-12", a$3.slice(0), Belt_Array.make(10, 7)); Belt_Array.fill(a$3, 0, -1, 2); -eq("File \"bs_array_test.ml\", line 192, characters 5-12", Belt_Array.copy(a$3), Belt_Array.make(10, 7)); +eq("File \"bs_array_test.ml\", line 192, characters 5-12", a$3.slice(0), Belt_Array.make(10, 7)); var b$1 = /* array */[ 1, @@ -819,7 +819,7 @@ var b0 = Belt_Array.make(10, 3); Belt_Array.blit(a0, 1, b0, 2, 5); -eq("File \"bs_array_test.ml\", line 203, characters 5-12", Belt_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 203, characters 5-12", b0.slice(0), /* array */[ 3, 3, 1, @@ -834,7 +834,7 @@ eq("File \"bs_array_test.ml\", line 203, characters 5-12", Belt_Array.copy(b0), Belt_Array.blit(a0, -1, b0, 2, 5); -eq("File \"bs_array_test.ml\", line 206, characters 5-12", Belt_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 206, characters 5-12", b0.slice(0), /* array */[ 3, 3, 9, @@ -849,7 +849,7 @@ eq("File \"bs_array_test.ml\", line 206, characters 5-12", Belt_Array.copy(b0), Belt_Array.blit(a0, -1, b0, -2, 5); -eq("File \"bs_array_test.ml\", line 209, characters 5-12", Belt_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 209, characters 5-12", b0.slice(0), /* array */[ 3, 3, 9, @@ -864,7 +864,7 @@ eq("File \"bs_array_test.ml\", line 209, characters 5-12", Belt_Array.copy(b0), Belt_Array.blit(a0, -2, b0, -2, 2); -eq("File \"bs_array_test.ml\", line 212, characters 5-12", Belt_Array.copy(b0), /* array */[ +eq("File \"bs_array_test.ml\", line 212, characters 5-12", b0.slice(0), /* array */[ 3, 3, 9, @@ -879,11 +879,11 @@ eq("File \"bs_array_test.ml\", line 212, characters 5-12", Belt_Array.copy(b0), Belt_Array.blit(a0, -11, b0, -11, 100); -eq("File \"bs_array_test.ml\", line 215, characters 5-12", Belt_Array.copy(b0), a0); +eq("File \"bs_array_test.ml\", line 215, characters 5-12", b0.slice(0), a0); Belt_Array.blit(a0, -11, b0, -11, 2); -eq("File \"bs_array_test.ml\", line 217, characters 5-12", Belt_Array.copy(b0), a0); +eq("File \"bs_array_test.ml\", line 217, characters 5-12", b0.slice(0), a0); var aa = Belt_Array.makeBy(10, (function (x) { return x; @@ -891,7 +891,7 @@ var aa = Belt_Array.makeBy(10, (function (x) { Belt_Array.blit(aa, -1, aa, 1, 2); -eq("File \"bs_array_test.ml\", line 220, characters 5-12", Belt_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 220, characters 5-12", aa.slice(0), /* array */[ 0, 9, 2, @@ -906,7 +906,7 @@ eq("File \"bs_array_test.ml\", line 220, characters 5-12", Belt_Array.copy(aa), Belt_Array.blit(aa, -2, aa, 1, 2); -eq("File \"bs_array_test.ml\", line 222, characters 5-12", Belt_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 222, characters 5-12", aa.slice(0), /* array */[ 0, 8, 9, @@ -921,7 +921,7 @@ eq("File \"bs_array_test.ml\", line 222, characters 5-12", Belt_Array.copy(aa), Belt_Array.blit(aa, -5, aa, 4, 3); -eq("File \"bs_array_test.ml\", line 224, characters 5-12", Belt_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 224, characters 5-12", aa.slice(0), /* array */[ 0, 8, 9, @@ -936,7 +936,7 @@ eq("File \"bs_array_test.ml\", line 224, characters 5-12", Belt_Array.copy(aa), Belt_Array.blit(aa, 4, aa, 5, 3); -eq("File \"bs_array_test.ml\", line 226, characters 5-12", Belt_Array.copy(aa), /* array */[ +eq("File \"bs_array_test.ml\", line 226, characters 5-12", aa.slice(0), /* array */[ 0, 8, 9, @@ -1112,7 +1112,7 @@ b("File \"bs_array_test.ml\", line 250, characters 4-11", (Belt_Array.forEachWit })), c$1[0] === 6)); function id$1(_, x) { - var u = Belt_Array.copy(x); + var u = x.slice(0); return eq("File \"bs_array_test.ml\", line 260, characters 5-12", Belt_Array.reverse(x), (Belt_Array.reverseInPlace(u), u)); } diff --git a/jscomp/test/bs_sort_test.js b/jscomp/test/bs_sort_test.js index 8bb53163f4..1eb7c5c8ac 100644 --- a/jscomp/test/bs_sort_test.js +++ b/jscomp/test/bs_sort_test.js @@ -115,9 +115,9 @@ b("File \"bs_sort_test.ml\", line 70, characters 4-11", !Belt_SortArray.isSorted var u = Array_data_util.randomRange(0, 1000000); -var u1 = Belt_Array.copy(u); +var u1 = u.slice(0); -var u2 = Belt_Array.copy(u); +var u2 = u.slice(0); console.time("bs_sort_test.ml 80"); diff --git a/jscomp/test/flow_parser_reg_test.js b/jscomp/test/flow_parser_reg_test.js index 089a6ae1b2..d9fde50c4a 100644 --- a/jscomp/test/flow_parser_reg_test.js +++ b/jscomp/test/flow_parser_reg_test.js @@ -4709,79 +4709,79 @@ function lookahead($staropt$star, env) { } function with_strict(in_strict_mode, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* in_strict_mode */5] = in_strict_mode; return newrecord; } function with_in_function(in_function, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* in_function */9] = in_function; return newrecord; } function with_allow_yield(allow_yield, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* allow_yield */13] = allow_yield; return newrecord; } function with_no_let(no_let, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* no_let */12] = no_let; return newrecord; } function with_in_loop(in_loop, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* in_loop */7] = in_loop; return newrecord; } function with_no_in(no_in, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* no_in */10] = no_in; return newrecord; } function with_in_switch(in_switch, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* in_switch */8] = in_switch; return newrecord; } function with_in_export(in_export, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* in_export */6] = in_export; return newrecord; } function with_no_call(no_call, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* no_call */11] = no_call; return newrecord; } function with_error_callback(error_callback, env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* error_callback */15] = /* Some */[error_callback]; return newrecord; } function without_error_callback(env) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* error_callback */15] = /* None */0; return newrecord; } function add_label(env, label) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* labels */2] = add(label, env[/* labels */2]); return newrecord; } function enter_function(env, async, generator) { - var newrecord = env.slice(); + var newrecord = Caml_array.caml_array_dup(env); newrecord[/* labels */2] = /* Empty */0; newrecord[/* in_loop */7] = false; newrecord[/* in_switch */8] = false; diff --git a/jscomp/test/ocaml_typedtree_test.js b/jscomp/test/ocaml_typedtree_test.js index 0846ce2f3b..bb8b5652ca 100644 --- a/jscomp/test/ocaml_typedtree_test.js +++ b/jscomp/test/ocaml_typedtree_test.js @@ -8666,7 +8666,7 @@ function loc(s, x) { } } -var newrecord = default_mapper.slice(); +var newrecord = Caml_array.caml_array_dup(default_mapper); newrecord[/* location */20] = (function (_, _$1) { return none; @@ -52780,7 +52780,7 @@ function check_deprecated(loc, attrs, s) { }), attrs); } -var newrecord$1 = default_mapper.slice(); +var newrecord$1 = Caml_array.caml_array_dup(default_mapper); newrecord$1[/* attribute */0] = (function (_, a) { var exit = 0; diff --git a/lib/bsdep.ml b/lib/bsdep.ml index 150034bf45..f2a3d37188 100644 --- a/lib/bsdep.ml +++ b/lib/bsdep.ml @@ -27300,8 +27300,7 @@ module Bs_warnings : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type t = - | Unsafe_ffi_bool_type +type t = | Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit @@ -27339,9 +27338,7 @@ end = struct -type t = - | Unsafe_ffi_bool_type - +type t = | Unsafe_poly_variant_type (* for users write code like this: {[ external f : [`a of int ] -> string = ""]} @@ -27352,9 +27349,6 @@ type t = let to_string t = match t with - | Unsafe_ffi_bool_type - -> - "You are passing a OCaml bool type into JS, probably you want to pass Js.boolean" | Unsafe_poly_variant_type -> "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " @@ -32615,10 +32609,6 @@ let get_arg_type ~nolabel optional end, {ptyp with ptyp_attributes}) | (`Nothing, ptyp_attributes) -> begin match ptyp_desc with - | Ptyp_constr ({txt = Lident "bool"; _}, []) - -> - Bs_warnings.prerr_bs_ffi_warning ptyp.ptyp_loc Unsafe_ffi_bool_type; - Nothing | Ptyp_constr ({txt = Lident "unit"; _}, []) -> if nolabel then Extern_unit else Nothing | Ptyp_constr ({txt = Lident "array"; _}, [_]) diff --git a/lib/bsppx.ml b/lib/bsppx.ml index d736f918a1..936ef198ab 100644 --- a/lib/bsppx.ml +++ b/lib/bsppx.ml @@ -9242,8 +9242,7 @@ module Bs_warnings : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type t = - | Unsafe_ffi_bool_type +type t = | Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit @@ -9281,9 +9280,7 @@ end = struct -type t = - | Unsafe_ffi_bool_type - +type t = | Unsafe_poly_variant_type (* for users write code like this: {[ external f : [`a of int ] -> string = ""]} @@ -9294,9 +9291,6 @@ type t = let to_string t = match t with - | Unsafe_ffi_bool_type - -> - "You are passing a OCaml bool type into JS, probably you want to pass Js.boolean" | Unsafe_poly_variant_type -> "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " @@ -14620,10 +14614,6 @@ let get_arg_type ~nolabel optional end, {ptyp with ptyp_attributes}) | (`Nothing, ptyp_attributes) -> begin match ptyp_desc with - | Ptyp_constr ({txt = Lident "bool"; _}, []) - -> - Bs_warnings.prerr_bs_ffi_warning ptyp.ptyp_loc Unsafe_ffi_bool_type; - Nothing | Ptyp_constr ({txt = Lident "unit"; _}, []) -> if nolabel then Extern_unit else Nothing | Ptyp_constr ({txt = Lident "array"; _}, [_]) diff --git a/lib/js/belt_Array.js b/lib/js/belt_Array.js index 24e8f34db7..cc8b695e42 100644 --- a/lib/js/belt_Array.js +++ b/lib/js/belt_Array.js @@ -36,15 +36,6 @@ function setExn(arr, i, v) { return /* () */0; } -function copy(a) { - var l = a.length; - var v = new Array(l); - for(var i = 0 ,i_finish = l - 1 | 0; i <= i_finish; ++i){ - v[i] = a[i]; - } - return v; -} - function swapUnsafe(xs, i, j) { var tmp = xs[i]; xs[i] = xs[j]; @@ -61,7 +52,7 @@ function shuffleInPlace(xs) { } function shuffle(xs) { - var result = copy(xs); + var result = xs.slice(0); shuffleInPlace(result); return result; } @@ -571,7 +562,6 @@ exports.zipBy = zipBy; exports.concat = concat; exports.concatMany = concatMany; exports.slice = slice; -exports.copy = copy; exports.fill = fill; exports.blit = blit; exports.blitUnsafe = blitUnsafe; diff --git a/lib/js/belt_SortArray.js b/lib/js/belt_SortArray.js index 74f6680db1..24a945962b 100644 --- a/lib/js/belt_SortArray.js +++ b/lib/js/belt_SortArray.js @@ -358,7 +358,7 @@ function stableSortInPlaceBy(a, cmp) { } function stableSortByU(a, cmp) { - var b = Belt_Array.copy(a); + var b = a.slice(0); stableSortInPlaceByU(b, cmp); return b; } diff --git a/lib/js/belt_SortArrayInt.js b/lib/js/belt_SortArrayInt.js index adec613410..2aa70d02ff 100644 --- a/lib/js/belt_SortArrayInt.js +++ b/lib/js/belt_SortArrayInt.js @@ -328,7 +328,7 @@ function stableSortInPlace(a) { } function stableSort(a) { - var b = Belt_Array.copy(a); + var b = a.slice(0); stableSortInPlace(b); return b; } diff --git a/lib/js/belt_SortArrayString.js b/lib/js/belt_SortArrayString.js index adec613410..2aa70d02ff 100644 --- a/lib/js/belt_SortArrayString.js +++ b/lib/js/belt_SortArrayString.js @@ -328,7 +328,7 @@ function stableSortInPlace(a) { } function stableSort(a) { - var b = Belt_Array.copy(a); + var b = a.slice(0); stableSortInPlace(b); return b; } diff --git a/lib/js/caml_array.js b/lib/js/caml_array.js index 7b03e28162..df61767d44 100644 --- a/lib/js/caml_array.js +++ b/lib/js/caml_array.js @@ -111,6 +111,11 @@ function caml_array_blit(a1, i1, a2, i2, len) { } } +function caml_array_dup(prim) { + return prim.slice(0); +} + +exports.caml_array_dup = caml_array_dup; exports.caml_array_sub = caml_array_sub; exports.caml_array_concat = caml_array_concat; exports.caml_make_vect = caml_make_vect; diff --git a/lib/whole_compiler.ml b/lib/whole_compiler.ml index 0f50bc9e5c..cdbb8bf6ee 100644 --- a/lib/whole_compiler.ml +++ b/lib/whole_compiler.ml @@ -63302,8 +63302,6 @@ and expression_desc = | Char_to_int of expression | Is_null_or_undefined of expression (** where we use a trick [== null ] *) - | Array_copy of expression (* shallow copy, like [x.slice] *) - | String_append of expression * expression | Bool of bool (* js true/false*) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence @@ -69544,8 +69542,7 @@ class virtual fold = Qualified (_, Runtime, Some "caml_int_compare") ]} *) - (** where we use a trick [== null ] *) - (* shallow copy, like [x.slice] *) (* js true/false*) + (** where we use a trick [== null ] *) (* js true/false*) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence [typeof] is an operator *) @@ -69740,7 +69737,6 @@ class virtual fold = | Char_of_int _x -> let o = o#expression _x in o | Char_to_int _x -> let o = o#expression _x in o | Is_null_or_undefined _x -> let o = o#expression _x in o - | Array_copy _x -> let o = o#expression _x in o | String_append (_x, _x_i1) -> let o = o#expression _x in let o = o#expression _x_i1 in o | Bool _x -> let o = o#bool _x in o @@ -70045,7 +70041,6 @@ let rec no_side_effect_expression_desc (x : J.expression_desc) = | Bin (op, a, b) -> op <> Eq && no_side_effect a && no_side_effect b | Math _ - | Array_copy _ | Js_not _ | Cond _ @@ -70184,7 +70179,6 @@ let rec eq_expression | Char_of_int _ | Char_to_int _ | Is_null_or_undefined _ - | Array_copy _ | String_append _ | Typeof _ | Js_not _ @@ -70826,7 +70820,7 @@ val function_length : unary_op val char_of_int : unary_op val char_to_int : unary_op -val array_copy : unary_op + val string_append : binary_op (** When in ES6 mode, we can use Symbol to guarantee its uniquess, @@ -71452,8 +71446,6 @@ let char_to_int ?comment (v : t) : t = | _ -> {comment; expression_desc = Char_to_int v } -let array_copy ?comment e : t = - { comment ; expression_desc = Array_copy e} let rec string_append ?comment (e : t) (el : t) : t = match e.expression_desc , el.expression_desc with @@ -84593,14 +84585,6 @@ and expression 1 cxt f el ) ) - - | Array_copy e -> - P.group f 1 (fun _ -> - let cxt = expression 15 cxt f e in - P.string f ".slice"; - P.string f "()" ; - cxt - ) | Char_to_int e -> begin match e.expression_desc with | String_access (a,b) -> @@ -85138,7 +85122,6 @@ and statement_desc top cxt f (s : J.statement_desc) : Ext_pp_scope.t = | Length _ | Caml_block_set_length _ | Call _ - | Array_copy _ | Caml_block_tag _ | Seq _ | Dot _ @@ -88168,8 +88151,7 @@ class virtual map = Qualified (_, Runtime, Some "caml_int_compare") ]} *) - (** where we use a trick [== null ] *) - (* shallow copy, like [x.slice] *) (* js true/false*) + (** where we use a trick [== null ] *) (* js true/false*) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence [typeof] is an operator *) @@ -88377,7 +88359,6 @@ class virtual map = | Char_to_int _x -> let _x = o#expression _x in Char_to_int _x | Is_null_or_undefined _x -> let _x = o#expression _x in Is_null_or_undefined _x - | Array_copy _x -> let _x = o#expression _x in Array_copy _x | String_append (_x, _x_i1) -> let _x = o#expression _x in let _x_i1 = o#expression _x_i1 in String_append (_x, _x_i1) @@ -91290,7 +91271,6 @@ module Js_of_lam_record : sig val field : Lambda.field_dbg_info -> J.expression -> J.jsint ->J.expression -val copy : Js_exp_make.unary_op end = struct #1 "js_of_lam_record.ml" @@ -91345,12 +91325,6 @@ let field field_info e i = | Lambda.Fld_module s -> E.index ~comment:s e i -(** - used in [Pduprecord] - this is due to we encode record as an array, it is going to change - if we have another encoding -*) -let copy = E.array_copy end @@ -94147,8 +94121,7 @@ module Bs_warnings : sig * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type t = - | Unsafe_ffi_bool_type +type t = | Unsafe_poly_variant_type val prerr_bs_ffi_warning : Location.t -> t -> unit @@ -94186,9 +94159,7 @@ end = struct -type t = - | Unsafe_ffi_bool_type - +type t = | Unsafe_poly_variant_type (* for users write code like this: {[ external f : [`a of int ] -> string = ""]} @@ -94199,9 +94170,6 @@ type t = let to_string t = match t with - | Unsafe_ffi_bool_type - -> - "You are passing a OCaml bool type into JS, probably you want to pass Js.boolean" | Unsafe_poly_variant_type -> "Here a OCaml polymorphic variant type passed into JS, probably you forgot annotations like `[@bs.int]` or `[@bs.string]` " @@ -95296,7 +95264,7 @@ let translate loc (prim_name : string) and discarded it immediately This could be canceled *) - | _ -> E.array_copy a + | _ -> call Js_runtime_modules.array end | _ -> assert false end @@ -96239,27 +96207,18 @@ let translate loc | Pctconst ct -> begin match ct with - | Big_endian -> - if Sys.big_endian then E.caml_true - else E.caml_false + | Big_endian -> E.bool Sys.big_endian | Word_size -> E.small_int Sys.word_size - | Ostype_unix -> - if Sys.unix then E.caml_true else E.caml_false - | Ostype_win32 -> - if Sys.win32 then E.caml_true else E.caml_false - | Ostype_cygwin -> - if Sys.cygwin then E.caml_true else E.caml_false + | Ostype_unix -> E.bool Sys.unix + | Ostype_win32 -> E.bool Sys.win32 + | Ostype_cygwin -> E.bool Sys.cygwin end - (* | Psetglobal _ -> *) - (* assert false (\* already handled *\) *) - (* assert false *) | Pduprecord ((Record_regular - | Record_float ),_size) -> (* _size is the length of all_lables*) - begin match args with - | [e] -> Js_of_lam_record.copy e - | _ -> assert false - end + | Record_float ),_) -> + (* _size is the length of all_lables*) + (* TODO: In debug mode, need switch to *) + Lam_dispatch_primitive.translate loc "caml_array_dup" args | Pbigarrayref (unsafe, dimension, kind, layout) -> (* can be refined to @@ -106890,10 +106849,6 @@ let get_arg_type ~nolabel optional end, {ptyp with ptyp_attributes}) | (`Nothing, ptyp_attributes) -> begin match ptyp_desc with - | Ptyp_constr ({txt = Lident "bool"; _}, []) - -> - Bs_warnings.prerr_bs_ffi_warning ptyp.ptyp_loc Unsafe_ffi_bool_type; - Nothing | Ptyp_constr ({txt = Lident "unit"; _}, []) -> if nolabel then Extern_unit else Nothing | Ptyp_constr ({txt = Lident "array"; _}, [_])