From 36c8d42076e8857b63ffe179efae4a54aecf226d Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 19 Oct 2023 16:43:14 -0700 Subject: [PATCH 1/4] feat: remove `Belt` dependency from Stdlib --- jscomp/others/belt_Result.ml | 2 +- jscomp/others/belt_Result.mli | 2 +- jscomp/others/dune | 2 +- jscomp/stdlib/camlinternalOO.cppo.ml | 69 ---------------------------- jscomp/stdlib/dune | 2 +- jscomp/stdlib/stdlib.cppo.ml | 2 +- jscomp/stdlib/stdlib.cppo.mli | 2 +- 7 files changed, 6 insertions(+), 75 deletions(-) diff --git a/jscomp/others/belt_Result.ml b/jscomp/others/belt_Result.ml index 02ac3b3754..ddf70c3be0 100644 --- a/jscomp/others/belt_Result.ml +++ b/jscomp/others/belt_Result.ml @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type ('a, 'b) t = Ok of 'a | Error of 'b +type ('a, 'b) t = ('a, 'b) Stdlib.result = Ok of 'a | Error of 'b let getExn = function Ok x -> x | Error _ -> raise Not_found diff --git a/jscomp/others/belt_Result.mli b/jscomp/others/belt_Result.mli index 0f10b012e1..bdbf805c99 100644 --- a/jscomp/others/belt_Result.mli +++ b/jscomp/others/belt_Result.mli @@ -41,7 +41,7 @@ ]} *) -type ('a, 'b) t = Ok of 'a | Error of 'b +type ('a, 'b) t = ('a, 'b) Stdlib.result = Ok of 'a | Error of 'b val getExn : ('a, 'b) t -> 'a (** diff --git a/jscomp/others/dune b/jscomp/others/dune index 3998a7a024..832976a2ca 100644 --- a/jscomp/others/dune +++ b/jscomp/others/dune @@ -4,7 +4,7 @@ (public_name melange.belt) (preprocess (pps melange.ppx -unsafe)) - (libraries melange.js) + (libraries melange) (modules :standard \ diff --git a/jscomp/stdlib/camlinternalOO.cppo.ml b/jscomp/stdlib/camlinternalOO.cppo.ml index fcd08ab77a..d3cf836b04 100644 --- a/jscomp/stdlib/camlinternalOO.cppo.ml +++ b/jscomp/stdlib/camlinternalOO.cppo.ml @@ -96,26 +96,14 @@ let public_method_label s : tag = (**** Sparse array ****) module Vars = -#ifdef BS - Belt.Map.String -#else Map.Make(struct type t = string let compare (x:t) y = compare x y end) -#endif type vars = int Vars.t module Meths = -#ifdef BS - Belt.Map.String -#else Map.Make(struct type t = string let compare (x:t) y = compare x y end) -#endif type meths = label Meths.t module Labs = -#ifdef BS - Belt.Map.Int -#else Map.Make(struct type t = label let compare (x:t) y = compare x y end) -#endif type labs = bool Labs.t (* The compiler assumes that the first field of this structure is [size]. *) @@ -196,16 +184,6 @@ let new_method table = index let get_method_label table name = -#ifdef BS - match Js.undefinedToOption (Meths.getUndefined table.methods_by_name name) - with - | Some x -> x - | None -> - let label = new_method table in - table.methods_by_name <- Meths.set table.methods_by_name name label; - table.methods_by_label <- Labs.set table.methods_by_label label true; - label -#else try Meths.find name table.methods_by_name with Not_found -> @@ -213,7 +191,6 @@ let get_method_label table name = table.methods_by_name <- Meths.add name label table.methods_by_name; table.methods_by_label <- Labs.add label true table.methods_by_label; label -#endif let get_method_labels table names = Array.map (get_method_label table) names @@ -221,11 +198,7 @@ let get_method_labels table names = let set_method table label element = incr method_count; if -#ifdef BS - Labs.getExn table.methods_by_label label -#else Labs.find label table.methods_by_label -#endif then put table label element else @@ -249,31 +222,12 @@ let narrow table vars virt_meths concr_meths = table.vars, virt_meth_labs, vars) :: table.previous_states; table.vars <- -#ifdef BS - Vars.reduceU table.vars Vars.empty - (fun[@u] tvars lab info -> - if List.mem lab vars then Vars.set tvars lab info else tvars); -#else Vars.fold (fun lab info tvars -> if List.mem lab vars then Vars.add lab info tvars else tvars) table.vars Vars.empty; -#endif let by_name = ref Meths.empty in let by_label = ref Labs.empty in -#ifdef BS - List.iter2 (fun met label -> - by_name := Meths.set !by_name met label; - by_label := - Labs.set !by_label label - (Labs.getWithDefault table.methods_by_label label true) - ) concr_meths concr_meth_labs; - List.iter2 - (fun met label -> - by_name := Meths.set !by_name met label; - by_label := Labs.set !by_label label false; - ) virt_meths virt_meth_labs; -#else List.iter2 (fun met label -> by_name := Meths.add met label !by_name; @@ -287,7 +241,6 @@ let narrow table vars virt_meths concr_meths = by_name := Meths.add met label !by_name; by_label := Labs.add label false !by_label) virt_meths virt_meth_labs; -#endif table.methods_by_name <- !by_name; table.methods_by_label <- !by_label; table.hidden_meths <- @@ -304,11 +257,7 @@ let widen table = table.previous_states <- List.tl table.previous_states; table.vars <- List.fold_left -#ifdef BS - (fun s v -> Vars.set s v (Vars.getExn table.vars v)) -#else (fun s v -> Vars.add v (Vars.find v table.vars) s) -#endif saved_vars vars; table.methods_by_name <- by_name; table.methods_by_label <- by_label; @@ -325,20 +274,11 @@ let new_slot table = index let new_variable table name = -#ifdef BS - match Js.undefinedToOption (Vars.getUndefined table.vars name : int Js.undefined) with - | Some x -> x - | None -> - let index = new_slot table in - if name <> "" then table.vars <- Vars.set table.vars name index ; - index -#else try Vars.find name table.vars with Not_found -> let index = new_slot table in if name <> "" then table.vars <- Vars.add name index table.vars; index -#endif let to_array arr = if arr = Obj.magic 0 then [||] else arr @@ -357,11 +297,7 @@ let new_methods_variables table meths vals = let get_variable table name = try -#ifdef BS - (Vars.getExn table.vars name) -#else Vars.find name table.vars -#endif with Not_found -> assert false let get_variables table names = @@ -389,13 +325,8 @@ let create_table public_methods = Array.iteri (fun i met -> let lab = i*2+2 in -#ifdef BS - table.methods_by_name <- Meths.set table.methods_by_name met lab ; - table.methods_by_label <- Labs.set table.methods_by_label lab true ) -#else table.methods_by_name <- Meths.add met lab table.methods_by_name; table.methods_by_label <- Labs.add lab true table.methods_by_label) -#endif public_methods; table diff --git a/jscomp/stdlib/dune b/jscomp/stdlib/dune index be8b9a0dd1..bf163da76a 100644 --- a/jscomp/stdlib/dune +++ b/jscomp/stdlib/dune @@ -32,7 +32,7 @@ (modes melange) (preprocess (pps melange.ppx)) - (libraries melange.js melange.belt) + (libraries melange.js) (stdlib (modules_before_stdlib CamlinternalFormatBasics CamlinternalAtomic) (internal_modules Camlinternal*)) diff --git a/jscomp/stdlib/stdlib.cppo.ml b/jscomp/stdlib/stdlib.cppo.ml index d3a6c2ec78..89dba407fd 100644 --- a/jscomp/stdlib/stdlib.cppo.ml +++ b/jscomp/stdlib/stdlib.cppo.ml @@ -324,7 +324,7 @@ external decr : int ref -> unit = "%decr" (* Result type *) -type ('a,'b) result = ('a, 'b) Belt.Result.t = Ok of 'a | Error of 'b +type ('a,'b) result = Ok of 'a | Error of 'b (* String conversion functions *) diff --git a/jscomp/stdlib/stdlib.cppo.mli b/jscomp/stdlib/stdlib.cppo.mli index 7403179f62..739a605eca 100644 --- a/jscomp/stdlib/stdlib.cppo.mli +++ b/jscomp/stdlib/stdlib.cppo.mli @@ -1382,7 +1382,7 @@ external decr : int ref -> unit = "%decr" (** {1 Result type} *) (** @since 4.03 *) -type ('a,'b) result = ('a, 'b) Belt.Result.t = Ok of 'a | Error of 'b +type ('a,'b) result = Ok of 'a | Error of 'b (** {1 Operations on format strings} *) From 971ac69df249a7d50209e4a24527cc02963d05ad Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 19 Oct 2023 17:10:03 -0700 Subject: [PATCH 2/4] chore: add changelog entry --- Changes.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Changes.md b/Changes.md index 61e50a0966..36902a995c 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,10 @@ +Unreleased +--------------- + +- Remove `Belt` as a dependency of `Stdlib` + ([#796](https://github.com/melange-re/melange/pull/796)) + + 2.1.0 2023-10-22 --------------- From 02080e496b20e23d48b8517f7b3d5bbcb3be0936 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 19 Oct 2023 17:10:09 -0700 Subject: [PATCH 3/4] fix: test --- test/blackbox-tests/belt-and-runtime.t | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/blackbox-tests/belt-and-runtime.t b/test/blackbox-tests/belt-and-runtime.t index eae2ee40ef..6423ddfcee 100644 --- a/test/blackbox-tests/belt-and-runtime.t +++ b/test/blackbox-tests/belt-and-runtime.t @@ -49,9 +49,6 @@ Now es6 $ cat > ./_build/default/melange/node_modules/melange.js/package.json < { "type": "module" } > EOF - $ cat > ./_build/default/melange/node_modules/melange.belt/package.json < { "type": "module" } - > EOF $ cd _build/default $ node ./melange/x.js From bd8ff78820b83dda99a2d1165994076e61c97df1 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 19 Oct 2023 17:22:58 -0700 Subject: [PATCH 4/4] fix runtime tests --- jscomp/test/dist/jscomp/test/ocaml_re_test.js | 92 +++++++++---------- jscomp/test/dune | 4 +- test/blackbox-tests/belt-and-runtime.t | 7 +- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/jscomp/test/dist/jscomp/test/ocaml_re_test.js b/jscomp/test/dist/jscomp/test/ocaml_re_test.js index c425deb11e..085617f4d6 100644 --- a/jscomp/test/dist/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/dist/jscomp/test/ocaml_re_test.js @@ -3373,21 +3373,39 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }; } }; - var regexp$p = function (_left) { - while(true) { - var left = _left; - if (!accept(/* '|' */124)) { - return left; + var piece = function (param) { + var r = atom(undefined); + if (accept(/* '*' */42)) { + return greedy_mod(repn(r, 0, undefined)); + } + if (accept(/* '+' */43)) { + return greedy_mod(repn(r, 1, undefined)); + } + if (accept(/* '?' */63)) { + return greedy_mod(repn(r, 0, 1)); + } + if (!accept(/* '{' */123)) { + return r; + } + var i$1 = integer(undefined); + if (i$1 !== undefined) { + var j = accept(/* ',' */44) ? integer(undefined) : i$1; + if (!accept(/* '}' */125)) { + throw { + RE_EXN_ID: Parse_error, + Error: new Error() + }; } - _left = alt$1({ - hd: left, - tl: { - hd: branch$p(/* [] */0), - tl: /* [] */0 - } - }); - continue ; - }; + if (j !== undefined && j < i$1) { + throw { + RE_EXN_ID: Parse_error, + Error: new Error() + }; + } + return greedy_mod(repn(r, i$1, j)); + } + i.contents = i.contents - 1 | 0; + return r; }; var branch$p = function (_left) { while(true) { @@ -3483,39 +3501,21 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { continue ; }; }; - var piece = function (param) { - var r = atom(undefined); - if (accept(/* '*' */42)) { - return greedy_mod(repn(r, 0, undefined)); - } - if (accept(/* '+' */43)) { - return greedy_mod(repn(r, 1, undefined)); - } - if (accept(/* '?' */63)) { - return greedy_mod(repn(r, 0, 1)); - } - if (!accept(/* '{' */123)) { - return r; - } - var i$1 = integer(undefined); - if (i$1 !== undefined) { - var j = accept(/* ',' */44) ? integer(undefined) : i$1; - if (!accept(/* '}' */125)) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - if (j !== undefined && j < i$1) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; + var regexp$p = function (_left) { + while(true) { + var left = _left; + if (!accept(/* '|' */124)) { + return left; } - return greedy_mod(repn(r, i$1, j)); - } - i.contents = i.contents - 1 | 0; - return r; + _left = alt$1({ + hd: left, + tl: { + hd: branch$p(/* [] */0), + tl: /* [] */0 + } + }); + continue ; + }; }; var $$char = function (param) { if (i.contents === l) { diff --git a/jscomp/test/dune b/jscomp/test/dune index f59a1b7e05..17c0af8cc8 100644 --- a/jscomp/test/dune +++ b/jscomp/test/dune @@ -11,7 +11,7 @@ (library (name melange_runtime_tests) (modes melange) - (libraries test_runner melange.dom) + (libraries test_runner melange.dom melange.belt) (wrapped false) (preprocess (pps melange.ppx)) @@ -29,7 +29,7 @@ (library (name melange_tests_re_res) (modes melange) - (libraries test_runner melange.dom) + (libraries test_runner melange.dom melange.belt) (wrapped false) (preprocess (pps melange.ppx reason-react-ppx)) diff --git a/test/blackbox-tests/belt-and-runtime.t b/test/blackbox-tests/belt-and-runtime.t index 6423ddfcee..e8c3422ff0 100644 --- a/test/blackbox-tests/belt-and-runtime.t +++ b/test/blackbox-tests/belt-and-runtime.t @@ -17,7 +17,7 @@ Try commonjs first > (melange.emit > (target melange) > (alias melange) - > (libraries melange) + > (libraries melange melange.belt) > (emit_stdlib false) > (module_systems commonjs)) > EOF @@ -35,7 +35,7 @@ Now es6 > (melange.emit > (target melange) > (alias melange) - > (libraries melange) + > (libraries melange melange.belt) > (emit_stdlib false) > (module_systems es6)) > EOF @@ -49,6 +49,9 @@ Now es6 $ cat > ./_build/default/melange/node_modules/melange.js/package.json < { "type": "module" } > EOF + $ cat > ./_build/default/melange/node_modules/melange.belt/package.json < { "type": "module" } + > EOF $ cd _build/default $ node ./melange/x.js