diff --git a/jscomp/bsb/bsb_templates.ml b/jscomp/bsb/bsb_templates.ml index 68f291022b..fa7f9074de 100644 --- a/jscomp/bsb/bsb_templates.ml +++ b/jscomp/bsb/bsb_templates.ml @@ -462,11 +462,13 @@ let root = OCamlRes.Res.([ Dir ("react", [ File ("webpack.config.js", "const path = require('path');\n\ + const outputDir = path.join(__dirname, \"build/\");\n\ \n\ module.exports = {\n\ \ entry: './src/Index.bs.js',\n\ \ output: {\n\ - \ path: path.join(__dirname, \"build\"),\n\ + \ path: outputDir,\n\ + \ publicPath: outputDir,\n\ \ filename: 'Index.js',\n\ \ },\n\ };\n\ diff --git a/jscomp/core/js_exp_make.ml b/jscomp/core/js_exp_make.ml index adc105f3f8..3530b274cf 100644 --- a/jscomp/core/js_exp_make.ml +++ b/jscomp/core/js_exp_make.ml @@ -1301,6 +1301,13 @@ let js_bool ?comment x : t = let is_undef ?comment x = triple_equal ?comment x undefined +let for_sure_js_null_undefined_boolean (x : t) = + match x.expression_desc with + | Var (Id ({name = "undefined" | "null"} as id)) + -> Ext_ident.is_js id + | Bool _ -> true + | _ -> false + let is_null_undefined ?comment (x: t) : t = match x.expression_desc with | Var (Id ({name = "undefined" | "null"} as id)) diff --git a/jscomp/core/js_exp_make.mli b/jscomp/core/js_exp_make.mli index ad0b7832d8..46c7dda26b 100644 --- a/jscomp/core/js_exp_make.mli +++ b/jscomp/core/js_exp_make.mli @@ -296,5 +296,6 @@ val is_nil : unary_op val js_bool : ?comment:string -> bool -> t val is_undef : unary_op +val for_sure_js_null_undefined_boolean : J.expression -> bool val is_null_undefined : unary_op val not_implemented : ?comment:string -> string -> t diff --git a/jscomp/core/lam.ml b/jscomp/core/lam.ml index 2a898783bf..613bbad2eb 100644 --- a/jscomp/core/lam.ml +++ b/jscomp/core/lam.ml @@ -55,6 +55,8 @@ type meth_kind = Lambda.meth_kind type constant = | Const_js_null | Const_js_undefined + | Const_js_true + | Const_js_false | Const_int of int | Const_char of char | Const_string of string (* use record later *) @@ -1127,8 +1129,10 @@ let if_ (a : t) (b : t) c = if x <> 0L then b else c | (Const_nativeint x) -> if x <> 0n then b else c + | Const_js_false | Const_js_null | Const_js_undefined -> c + | Const_js_true | Const_string _ | Const_float _ | Const_unicode _ @@ -1818,7 +1822,10 @@ let convert exports lam : _ * _ = prim ~primitive:Pdebugger ~args:[] loc | _ when s = "#null" -> Lconst (Const_js_null) - + | _ when s = "#true" -> + Lconst (Const_js_true) + | _ when s = "#false" -> + Lconst (Const_js_false) | _ when s = "#undefined" -> Lconst (Const_js_undefined) | _ when s = "#init_mod" -> diff --git a/jscomp/core/lam.mli b/jscomp/core/lam.mli index c1d1f49633..033830c3ec 100644 --- a/jscomp/core/lam.mli +++ b/jscomp/core/lam.mli @@ -54,6 +54,8 @@ type function_kind type constant = | Const_js_null | Const_js_undefined + | Const_js_true + | Const_js_false | Const_int of int | Const_char of char | Const_string of string diff --git a/jscomp/core/lam_analysis.ml b/jscomp/core/lam_analysis.ml index 251d26d8f8..e15ac3a32d 100644 --- a/jscomp/core/lam_analysis.ml +++ b/jscomp/core/lam_analysis.ml @@ -318,6 +318,7 @@ and size_constant x = | Const_immstring _ | Const_pointer _ | Const_js_null | Const_js_undefined + | Const_js_true | Const_js_false -> 1 | Const_block (_, _, str) -> List.fold_left (fun acc x -> acc + size_constant x ) 0 str diff --git a/jscomp/core/lam_compile_const.ml b/jscomp/core/lam_compile_const.ml index 5147ef9873..bdbc2a5f96 100644 --- a/jscomp/core/lam_compile_const.ml +++ b/jscomp/core/lam_compile_const.ml @@ -33,6 +33,8 @@ module E = Js_exp_make let rec translate (x : Lam.constant ) : J.expression = match x with + | Const_js_true -> E.js_bool true + | Const_js_false -> E.js_bool false | Const_js_null -> E.nil | Const_js_undefined -> E.undefined | Const_int i -> E.int (Int32.of_int i) diff --git a/jscomp/core/lam_dispatch_primitive.ml b/jscomp/core/lam_dispatch_primitive.ml index d2a735a0c7..4aa6237789 100644 --- a/jscomp/core/lam_dispatch_primitive.ml +++ b/jscomp/core/lam_dispatch_primitive.ml @@ -673,10 +673,20 @@ let translate loc (prim_name : string) -> call Js_runtime_modules.obj_runtime + | "caml_equal" -> + begin match args with + | [a1;b1] when + E.for_sure_js_null_undefined_boolean a1 || E.for_sure_js_null_undefined_boolean b1 + -> + E.int_comp Ceq a1 b1 + (* FIXME address_equal *) + | _ -> + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison ; + call Js_runtime_modules.obj_runtime + end | "caml_min" | "caml_max" - | "caml_compare" - | "caml_equal" + | "caml_compare" | "caml_notequal" | "caml_greaterequal" | "caml_greaterthan" diff --git a/jscomp/core/lam_print.ml b/jscomp/core/lam_print.ml index 25039daad6..53d8bf3f3d 100644 --- a/jscomp/core/lam_print.ml +++ b/jscomp/core/lam_print.ml @@ -19,6 +19,8 @@ open Types let rec struct_const ppf (cst : Lam.constant) = match cst with + | Const_js_true -> fprintf ppf "#true" + | Const_js_false -> fprintf ppf "#false" | Const_js_null -> fprintf ppf "#null" | Const_js_undefined -> fprintf ppf "#undefined" | (Const_int n) -> fprintf ppf "%i" n diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index 9359cc1384..6e4bbef483 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -79,8 +79,8 @@ type (+'a, +'e) promise (* tag::predefined_js_values[]*) -external true_ : boolean = "true" [@@bs.val] -external false_ : boolean = "false" [@@bs.val] +external true_ : boolean = "#true" +external false_ : boolean = "#false" external null : 'a null = "#null" (* The same as {!Js.Null.empty} will be compiled as [null]*) external undefined : 'a undefined = "#undefined" diff --git a/jscomp/runtime/js.mli b/jscomp/runtime/js.mli index 534cfb482c..240d038fb5 100644 --- a/jscomp/runtime/js.mli +++ b/jscomp/runtime/js.mli @@ -93,8 +93,8 @@ type (+'a, +'e) promise *) -external true_ : boolean = "true" [@@bs.val] -external false_ : boolean = "false" [@@bs.val] +external true_ : boolean = "#true" +external false_ : boolean = "#false" external null : 'a null = "#null" (** The same as [empty] in {!Js.Null} will be compiled as [null]*) diff --git a/jscomp/test/bs_hashtbl_string_test.js b/jscomp/test/bs_hashtbl_string_test.js index 92131546b6..86d57875c5 100644 --- a/jscomp/test/bs_hashtbl_string_test.js +++ b/jscomp/test/bs_hashtbl_string_test.js @@ -190,7 +190,9 @@ function bench4() { for(var i$2 = 0; i$2 <= 1000000; ++i$2){ Bs_HashMapString.remove(table, "" + i$2); } - if (table.size) { + if (Bs_HashMapString.isEmpty(table)) { + return 0; + } else { throw [ Caml_builtin_exceptions.assert_failure, [ @@ -199,8 +201,6 @@ function bench4() { 2 ] ]; - } else { - return 0; } } @@ -231,7 +231,9 @@ function bench5() { Bs_HashMap.remove(table, i$2); } console.timeEnd("bs_hashtbl_string_test.ml 141"); - if (table.size) { + if (Bs_HashMap.isEmpty(table)) { + return 0; + } else { throw [ Caml_builtin_exceptions.assert_failure, [ @@ -240,8 +242,6 @@ function bench5() { 2 ] ]; - } else { - return 0; } } diff --git a/jscomp/test/bs_poly_set_test.js b/jscomp/test/bs_poly_set_test.js index 95cccdb28c..be9735dc5b 100644 --- a/jscomp/test/bs_poly_set_test.js +++ b/jscomp/test/bs_poly_set_test.js @@ -180,14 +180,14 @@ var m$2 = { data: Bs_SortedSetDict.empty }; -b("File \"bs_poly_set_test.ml\", line 82, characters 4-11", Caml_obj.caml_equal(Bs_SortedSetDict.minUndefined(m$2.data), undefined)); +b("File \"bs_poly_set_test.ml\", line 82, characters 4-11", +(Bs_SortedSetDict.minUndefined(m$2.data) === undefined)); var m$3 = { cmp: IntCmp[/* cmp */0], data: Bs_SortedSetDict.empty }; -b("File \"bs_poly_set_test.ml\", line 83, characters 4-11", Caml_obj.caml_equal(Bs_SortedSetDict.maxUndefined(m$3.data), undefined)); +b("File \"bs_poly_set_test.ml\", line 83, characters 4-11", +(Bs_SortedSetDict.maxUndefined(m$3.data) === undefined)); function testIterToList(xs) { var v = [/* [] */0]; diff --git a/jscomp/test/ffi_test.js b/jscomp/test/ffi_test.js index 50b53d3b13..0f53901dff 100644 --- a/jscomp/test/ffi_test.js +++ b/jscomp/test/ffi_test.js @@ -5,10 +5,6 @@ function u() { return xx(3); } -var a = true; - -var b = false; - var Textarea = /* module */[]; var Int32Array = /* module */[]; @@ -25,6 +21,10 @@ function f() { return v[0]; } +var a = true; + +var b = false; + var c = null; var d = undefined; @@ -38,4 +38,4 @@ exports.Textarea = Textarea; exports.Int32Array = Int32Array; exports.v = v; exports.f = f; -/* a Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/gpr496_test.js b/jscomp/test/gpr496_test.js index 473a42cd65..69dc80cf36 100644 --- a/jscomp/test/gpr496_test.js +++ b/jscomp/test/gpr496_test.js @@ -45,13 +45,13 @@ var expected = /* tuple */[ expected_007 ]; -var u_000 = Caml_obj.caml_equal(true, false); +var u_000 = +(true === false); -var u_001 = Caml_obj.caml_equal(false, true); +var u_001 = +(false === true); -var u_002 = Caml_obj.caml_equal(false, false); +var u_002 = +(false === false); -var u_003 = Caml_obj.caml_equal(true, true); +var u_003 = +(true === true); var u_004 = Caml_obj.caml_compare(false, true); diff --git a/jscomp/test/js_bool_test.js b/jscomp/test/js_bool_test.js index f5cf336f92..048d087382 100644 --- a/jscomp/test/js_bool_test.js +++ b/jscomp/test/js_bool_test.js @@ -38,7 +38,7 @@ var suites_000 = /* tuple */[ (function () { return /* Eq */Block.__(0, [ u, - f(true) + /* true */1 ]); }) ]; @@ -59,7 +59,7 @@ var suites_001 = /* :: */[ (function () { return /* Eq */Block.__(0, [ /* false */0, - +(f(true) === (true)) + +(/* true */1 === (true)) ]); }) ], @@ -72,6 +72,14 @@ var suites = /* :: */[ suites_001 ]; +function ff(u) { + if (u === true) { + return 1; + } else { + return 2; + } +} + Mt.from_pair_suites("js_bool_test.ml", suites); exports.f = f; @@ -81,4 +89,5 @@ exports.f3 = f3; exports.u = u; exports.v = v; exports.suites = suites; -/* f3 Not a pure module */ +exports.ff = ff; +/* u Not a pure module */ diff --git a/jscomp/test/js_bool_test.ml b/jscomp/test/js_bool_test.ml index ca484d09e9..d0a379fcc1 100644 --- a/jscomp/test/js_bool_test.ml +++ b/jscomp/test/js_bool_test.ml @@ -23,6 +23,8 @@ let suites = Mt.[ Eq( false, (f Js.true_ = [%bs.raw {|true|} ] (* not type check*)))); ] -(* let f u = Js.unsafe_js_expr u *) +let ff u = + if u = Js.true_ then 1 + else 2 ;; Mt.from_pair_suites __FILE__ suites diff --git a/jscomp/test/js_null_undefined_test.js b/jscomp/test/js_null_undefined_test.js index fb2d672c03..544ff57dd9 100644 --- a/jscomp/test/js_null_undefined_test.js +++ b/jscomp/test/js_null_undefined_test.js @@ -242,7 +242,7 @@ var suites_001 = /* :: */[ /* tuple */[ "undefined = empty", (function () { - return /* Ok */Block.__(4, [Caml_obj.caml_equal(undefined, undefined)]); + return /* Ok */Block.__(4, [+(undefined === undefined)]); }) ], /* :: */[ diff --git a/lib/bsb.ml b/lib/bsb.ml index d3af9cf327..b436d2a579 100644 --- a/lib/bsb.ml +++ b/lib/bsb.ml @@ -13394,11 +13394,13 @@ let root = OCamlRes.Res.([ Dir ("react", [ File ("webpack.config.js", "const path = require('path');\n\ + const outputDir = path.join(__dirname, \"build/\");\n\ \n\ module.exports = {\n\ \ entry: './src/Index.bs.js',\n\ \ output: {\n\ - \ path: path.join(__dirname, \"build\"),\n\ + \ path: outputDir,\n\ + \ publicPath: outputDir,\n\ \ filename: 'Index.js',\n\ \ },\n\ };\n\ diff --git a/lib/js/bs_SortArrayInt.js b/lib/js/bs_SortArrayInt.js index d29139d438..4d98f5c4d0 100644 --- a/lib/js/bs_SortArrayInt.js +++ b/lib/js/bs_SortArrayInt.js @@ -22,26 +22,6 @@ function sortedLengthAuxMore(xs, _prec, _acc, len) { }; } -function sortedLengthAuxLess(xs, _prec, _acc, len) { - while(true) { - var acc = _acc; - var prec = _prec; - if (acc >= len) { - return acc; - } else { - var v = xs[acc]; - if (prec < v) { - _acc = acc + 1 | 0; - _prec = v; - continue ; - - } else { - return acc; - } - } - }; -} - function strictlySortedLength(xs) { var len = xs.length; if (len === 0 || len === 1) { @@ -50,7 +30,27 @@ function strictlySortedLength(xs) { var x0 = xs[0]; var x1 = xs[1]; if (x0 < x1) { - return sortedLengthAuxLess(xs, x1, 2, len); + var xs$1 = xs; + var _prec = x1; + var _acc = 2; + var len$1 = len; + while(true) { + var acc = _acc; + var prec = _prec; + if (acc >= len$1) { + return acc; + } else { + var v = xs$1[acc]; + if (prec < v) { + _acc = acc + 1 | 0; + _prec = v; + continue ; + + } else { + return acc; + } + } + }; } else if (x0 > x1) { return -sortedLengthAuxMore(xs, x1, 2, len) | 0; } else { @@ -59,25 +59,24 @@ function strictlySortedLength(xs) { } } -function isSortedAux(a, _i, last_bound) { - while(true) { - var i = _i; - if (i === last_bound) { - return /* true */1; - } else if (a[i] <= a[i + 1 | 0]) { - _i = i + 1 | 0; - continue ; - - } else { - return /* false */0; - } - }; -} - function isSorted(a) { var len = a.length; if (len) { - return isSortedAux(a, 0, len - 1 | 0); + var a$1 = a; + var _i = 0; + var last_bound = len - 1 | 0; + while(true) { + var i = _i; + if (i === last_bound) { + return /* true */1; + } else if (a$1[i] <= a$1[i + 1 | 0]) { + _i = i + 1 | 0; + continue ; + + } else { + return /* false */0; + } + }; } else { return /* true */1; } @@ -348,40 +347,6 @@ function stableSort(a) { return b; } -function binarySearchAux(arr, _lo, _hi, key) { - while(true) { - var hi = _hi; - var lo = _lo; - var mid = (lo + hi | 0) / 2 | 0; - var midVal = arr[mid]; - if (key === midVal) { - return mid; - } else if (key < midVal) { - if (hi === mid) { - if (arr[lo] === key) { - return lo; - } else { - return -(hi + 1 | 0) | 0; - } - } else { - _hi = mid; - continue ; - - } - } else if (lo === mid) { - if (arr[hi] === key) { - return hi; - } else { - return -(hi + 1 | 0) | 0; - } - } else { - _lo = mid; - continue ; - - } - }; -} - function binarySearch(sorted, key) { var len = sorted.length; if (len) { @@ -393,7 +358,41 @@ function binarySearch(sorted, key) { if (key > hi) { return -(len + 1 | 0) | 0; } else { - return binarySearchAux(sorted, 0, len - 1 | 0, key); + var arr = sorted; + var _lo = 0; + var _hi = len - 1 | 0; + var key$1 = key; + while(true) { + var hi$1 = _hi; + var lo$1 = _lo; + var mid = (lo$1 + hi$1 | 0) / 2 | 0; + var midVal = arr[mid]; + if (key$1 === midVal) { + return mid; + } else if (key$1 < midVal) { + if (hi$1 === mid) { + if (arr[lo$1] === key$1) { + return lo$1; + } else { + return -(hi$1 + 1 | 0) | 0; + } + } else { + _hi = mid; + continue ; + + } + } else if (lo$1 === mid) { + if (arr[hi$1] === key$1) { + return hi$1; + } else { + return -(hi$1 + 1 | 0) | 0; + } + } else { + _lo = mid; + continue ; + + } + }; } } } else { @@ -401,25 +400,12 @@ function binarySearch(sorted, key) { } } -var A = 0; - -var cutoff = 5; - -exports.A = A; -exports.sortedLengthAuxMore = sortedLengthAuxMore; -exports.sortedLengthAuxLess = sortedLengthAuxLess; exports.strictlySortedLength = strictlySortedLength; -exports.isSortedAux = isSortedAux; exports.isSorted = isSorted; -exports.cutoff = cutoff; -exports.merge = merge; -exports.union = union; -exports.intersect = intersect; -exports.diff = diff; -exports.insertionSort = insertionSort; -exports.sortTo = sortTo; exports.stableSortInPlace = stableSortInPlace; exports.stableSort = stableSort; -exports.binarySearchAux = binarySearchAux; exports.binarySearch = binarySearch; +exports.union = union; +exports.intersect = intersect; +exports.diff = diff; /* No side effect */ diff --git a/lib/whole_compiler.ml b/lib/whole_compiler.ml index 6e4eb86292..92e5b7982f 100644 --- a/lib/whole_compiler.ml +++ b/lib/whole_compiler.ml @@ -66602,6 +66602,8 @@ type function_kind type constant = | Const_js_null | Const_js_undefined + | Const_js_true + | Const_js_false | Const_int of int | Const_char of char | Const_string of string @@ -66960,6 +66962,8 @@ type meth_kind = Lambda.meth_kind type constant = | Const_js_null | Const_js_undefined + | Const_js_true + | Const_js_false | Const_int of int | Const_char of char | Const_string of string (* use record later *) @@ -68032,8 +68036,10 @@ let if_ (a : t) (b : t) c = if x <> 0L then b else c | (Const_nativeint x) -> if x <> 0n then b else c + | Const_js_false | Const_js_null | Const_js_undefined -> c + | Const_js_true | Const_string _ | Const_float _ | Const_unicode _ @@ -68723,7 +68729,10 @@ let convert exports lam : _ * _ = prim ~primitive:Pdebugger ~args:[] loc | _ when s = "#null" -> Lconst (Const_js_null) - + | _ when s = "#true" -> + Lconst (Const_js_true) + | _ when s = "#false" -> + Lconst (Const_js_false) | _ when s = "#undefined" -> Lconst (Const_js_undefined) | _ when s = "#init_mod" -> @@ -71115,6 +71124,7 @@ val is_nil : unary_op val js_bool : ?comment:string -> bool -> t val is_undef : unary_op +val for_sure_js_null_undefined_boolean : J.expression -> bool val is_null_undefined : unary_op val not_implemented : ?comment:string -> string -> t @@ -72423,6 +72433,13 @@ let js_bool ?comment x : t = let is_undef ?comment x = triple_equal ?comment x undefined +let for_sure_js_null_undefined_boolean (x : t) = + match x.expression_desc with + | Var (Id ({name = "undefined" | "null"} as id)) + -> Ext_ident.is_js id + | Bool _ -> true + | _ -> false + let is_null_undefined ?comment (x: t) : t = match x.expression_desc with | Var (Id ({name = "undefined" | "null"} as id)) @@ -72517,6 +72534,8 @@ open Types let rec struct_const ppf (cst : Lam.constant) = match cst with + | Const_js_true -> fprintf ppf "#true" + | Const_js_false -> fprintf ppf "#false" | Const_js_null -> fprintf ppf "#null" | Const_js_undefined -> fprintf ppf "#undefined" | (Const_int n) -> fprintf ppf "%i" n @@ -86597,6 +86616,7 @@ and size_constant x = | Const_immstring _ | Const_pointer _ | Const_js_null | Const_js_undefined + | Const_js_true | Const_js_false -> 1 | Const_block (_, _, str) -> List.fold_left (fun acc x -> acc + size_constant x ) 0 str @@ -93078,6 +93098,8 @@ module E = Js_exp_make let rec translate (x : Lam.constant ) : J.expression = match x with + | Const_js_true -> E.js_bool true + | Const_js_false -> E.js_bool false | Const_js_null -> E.nil | Const_js_undefined -> E.undefined | Const_int i -> E.int (Int32.of_int i) @@ -95220,10 +95242,20 @@ let translate loc (prim_name : string) -> call Js_runtime_modules.obj_runtime + | "caml_equal" -> + begin match args with + | [a1;b1] when + E.for_sure_js_null_undefined_boolean a1 || E.for_sure_js_null_undefined_boolean b1 + -> + E.int_comp Ceq a1 b1 + (* FIXME address_equal *) + | _ -> + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison ; + call Js_runtime_modules.obj_runtime + end | "caml_min" | "caml_max" - | "caml_compare" - | "caml_equal" + | "caml_compare" | "caml_notequal" | "caml_greaterequal" | "caml_greaterthan"