From 4b284fbdfcc4e4f0434c38cbd43ef032e7668f41 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 26 Feb 2024 16:09:01 -0800 Subject: [PATCH 1/4] adapt to slimmed-down melange-compiler-libs --- bin/melc.ml | 4 +--- jscomp/common/lam_constant.mli | 2 -- jscomp/common/lam_tag_info.mli | 2 -- jscomp/core/ast_config.mli | 2 -- jscomp/core/ast_io.cppo.ml | 14 +++++++------ jscomp/core/ast_io.mli | 1 - jscomp/core/builtin_ast_mapper.ml | 2 -- jscomp/core/builtin_ast_mapper.mli | 2 -- jscomp/core/import.ml | 3 --- jscomp/core/js_implementation.mli | 2 -- jscomp/core/mel_ast_invariant.mli | 2 -- jscomp/core/meldep.mli | 1 - jscomp/core/ml_binary.mli | 2 -- jscomp/core/pparse_driver.mli | 1 - jscomp/core/record_attributes_check.ml | 5 ++--- playground/mel_playground.ml | 6 +++--- ppx/melange_ppx.ml | 4 ++-- vendor/dune | 29 +------------------------- vendor/melange-compiler-libs | 2 +- 19 files changed, 18 insertions(+), 68 deletions(-) diff --git a/bin/melc.ml b/bin/melc.ml index 917171d38a..245afb25dd 100644 --- a/bin/melc.ml +++ b/bin/melc.ml @@ -111,9 +111,7 @@ let apply_lazy ~source ~target = output_value oc ast | Impl ast -> let ast: Ppxlib_ast__.Versions.OCaml_current.Ast.Parsetree.structure = - let ast: Melange_compiler_libs.Parsetree.structure = - apply ~kind:Ml_binary.Ml ast - in + let ast = apply ~kind:Ml_binary.Ml ast in let ppxlib_ast: Melange_ast_version.Ast.Parsetree.structure = Obj.magic ast in diff --git a/jscomp/common/lam_constant.mli b/jscomp/common/lam_constant.mli index 8fe11f3f62..4ba2dbe647 100644 --- a/jscomp/common/lam_constant.mli +++ b/jscomp/common/lam_constant.mli @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - type pointer_info = | None | Pt_constructor of { diff --git a/jscomp/common/lam_tag_info.mli b/jscomp/common/lam_tag_info.mli index 102679995d..daced6fd18 100644 --- a/jscomp/common/lam_tag_info.mli +++ b/jscomp/common/lam_tag_info.mli @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - (* Similiar to {!Lambda.tag_info} In particular, it reduces some branches e.g, diff --git a/jscomp/core/ast_config.mli b/jscomp/core/ast_config.mli index 149d4fbb5d..5a9377ccfa 100644 --- a/jscomp/core/ast_config.mli +++ b/jscomp/core/ast_config.mli @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - val add_structure : string -> (Parsetree.expression option -> unit) -> unit val add_signature : string -> (Parsetree.expression option -> unit) -> unit val iter_on_mel_config_stru : Parsetree.structure -> unit diff --git a/jscomp/core/ast_io.cppo.ml b/jscomp/core/ast_io.cppo.ml index 1760244b7c..776b297e2b 100644 --- a/jscomp/core/ast_io.cppo.ml +++ b/jscomp/core/ast_io.cppo.ml @@ -37,8 +37,8 @@ module type OCaml_version = Ppxlib_ast.OCaml_version module Intf_or_impl = struct type t = - | Intf of Melange_compiler_libs.Parsetree.signature - | Impl of Melange_compiler_libs.Parsetree.structure + | Intf of Parsetree.signature + | Impl of Parsetree.structure module Convert = Ppxlib_ast.Convert @@ -49,7 +49,7 @@ module Intf_or_impl = struct fun stru -> let melange_stru = let ocaml_51_stru = Convert.copy_structure stru in - (Obj.magic ocaml_51_stru : Melange_compiler_libs.Parsetree.structure) + (Obj.magic ocaml_51_stru : Parsetree.structure) in Impl melange_stru @@ -57,7 +57,7 @@ module Intf_or_impl = struct fun sig_ -> let melange_sig = let ocaml_51_sig = Convert.copy_signature sig_ in - (Obj.magic ocaml_51_sig : Melange_compiler_libs.Parsetree.signature) + (Obj.magic ocaml_51_sig : Parsetree.signature) in Intf melange_sig end @@ -126,7 +126,8 @@ let from_channel ch ~input_kind : (t, read_error) result = match Find_version.from_magic s with | Intf (module Input_version : OCaml_version) -> let input_name : string = input_value ch in - Location.set_input_name input_name; + Ocaml_common.Location.input_name := input_name; + Location.input_name := input_name; let ast = input_value ch in let module Input_to_ppxlib = Convert (Input_version) (Ppxlib_ast.Selected_ast) @@ -140,7 +141,8 @@ let from_channel ch ~input_kind : (t, read_error) result = } | Impl (module Input_version : OCaml_version) -> let input_name : string = input_value ch in - Location.set_input_name input_name; + Location.input_name := input_name; + Ocaml_common.Location.input_name := input_name; let ast = input_value ch in let module Input_to_ppxlib = Convert (Input_version) (Ppxlib_ast.Selected_ast) diff --git a/jscomp/core/ast_io.mli b/jscomp/core/ast_io.mli index 5637cf7857..361f0095db 100644 --- a/jscomp/core/ast_io.mli +++ b/jscomp/core/ast_io.mli @@ -22,7 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US. *) -open Import module Melange_ast_version : Ppxlib_ast.OCaml_version module Compiler_version = Ppxlib_ast.Compiler_version diff --git a/jscomp/core/builtin_ast_mapper.ml b/jscomp/core/builtin_ast_mapper.ml index c715ad49dd..e0279248b0 100644 --- a/jscomp/core/builtin_ast_mapper.ml +++ b/jscomp/core/builtin_ast_mapper.ml @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature = Ast_config.iter_on_mel_config_sigi ast; Mel_ast_invariant.emit_external_warnings_on_signature ast; diff --git a/jscomp/core/builtin_ast_mapper.mli b/jscomp/core/builtin_ast_mapper.mli index 6441a0f2bb..82c063351c 100644 --- a/jscomp/core/builtin_ast_mapper.mli +++ b/jscomp/core/builtin_ast_mapper.mli @@ -22,7 +22,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - val rewrite_signature : Parsetree.signature -> Parsetree.signature val rewrite_structure : Parsetree.structure -> Parsetree.structure diff --git a/jscomp/core/import.ml b/jscomp/core/import.ml index 9cacd2cdbd..3b305e76f8 100644 --- a/jscomp/core/import.ml +++ b/jscomp/core/import.ml @@ -1,6 +1,3 @@ include Melstd include Melange_compiler_libs -include struct - module Path = Melstd.Path -end diff --git a/jscomp/core/js_implementation.mli b/jscomp/core/js_implementation.mli index 485a260193..0a70090e8d 100644 --- a/jscomp/core/js_implementation.mli +++ b/jscomp/core/js_implementation.mli @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - (** High level compilation module *) val interface : diff --git a/jscomp/core/mel_ast_invariant.mli b/jscomp/core/mel_ast_invariant.mli index faed70228f..3e11ed37f4 100644 --- a/jscomp/core/mel_ast_invariant.mli +++ b/jscomp/core/mel_ast_invariant.mli @@ -22,7 +22,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - val emit_external_warnings_on_structure : Parsetree.structure -> unit val emit_external_warnings_on_signature : Parsetree.signature -> unit diff --git a/jscomp/core/meldep.mli b/jscomp/core/meldep.mli index 686f44bf56..e532a8500a 100644 --- a/jscomp/core/meldep.mli +++ b/jscomp/core/meldep.mli @@ -22,7 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import module Set_string = Depend.String.Set val read_parse_and_extract : 'a Ml_binary.kind -> 'a -> Set_string.t diff --git a/jscomp/core/ml_binary.mli b/jscomp/core/ml_binary.mli index b954ee8ed2..8e75069d77 100644 --- a/jscomp/core/ml_binary.mli +++ b/jscomp/core/ml_binary.mli @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -open Import - type _ kind = Ml : Parsetree.structure kind | Mli : Parsetree.signature kind val magic_of_kind : 'a kind -> string diff --git a/jscomp/core/pparse_driver.mli b/jscomp/core/pparse_driver.mli index cac4f70009..3006c4888d 100644 --- a/jscomp/core/pparse_driver.mli +++ b/jscomp/core/pparse_driver.mli @@ -1,4 +1,3 @@ -open Import val parse_implementation : string -> Parsetree.structure val parse_interface : string -> Parsetree.signature diff --git a/jscomp/core/record_attributes_check.ml b/jscomp/core/record_attributes_check.ml index c7736464f5..1aaeb007d2 100644 --- a/jscomp/core/record_attributes_check.ml +++ b/jscomp/core/record_attributes_check.ml @@ -165,9 +165,8 @@ let check_duplicated_labels = | Some ({ txt = s; _ } as l) -> if String.Set.mem coll s - (*use coll to make check a bit looser - allow cases like [ x : int [@as "x"]] - *) + (* use coll to make check a bit looser + allow cases like [ x : int [@as "x"]] *) then Some l else check_duplicated_labels_aux rest diff --git a/playground/mel_playground.ml b/playground/mel_playground.ml index 359a7dbf9c..e82f54302d 100644 --- a/playground/mel_playground.ml +++ b/playground/mel_playground.ml @@ -30,12 +30,12 @@ module Melange_OCaml_version = Ast_io.Melange_ast_version module Melange_ast = struct external to_ppxlib : - Melange_compiler_libs.Parsetree.structure -> + Parsetree.structure -> Melange_OCaml_version.Ast.Parsetree.structure = "%identity" external from_ppxlib : Melange_OCaml_version.Ast.Parsetree.structure -> - Melange_compiler_libs.Parsetree.structure = "%identity" + Parsetree.structure = "%identity" end let warnings_collected : Location.report list ref = ref [] @@ -326,7 +326,7 @@ let () = ~impl:(fun buf : Melange_OCaml_version.Ast.Parsetree.structure -> Melange_ast.to_ppxlib - (Melange_compiler_libs.Parse.implementation buf)) + (Parse.implementation buf)) (Js.to_string code)) ); ( "compileRE", Js.wrap_meth_callback (fun _ code -> diff --git a/ppx/melange_ppx.ml b/ppx/melange_ppx.ml index 3c8a1c09cf..9584887340 100644 --- a/ppx/melange_ppx.ml +++ b/ppx/melange_ppx.ml @@ -619,7 +619,7 @@ module Mapper = struct | Some attr, Pexp_constant (Pconst_string (s, loc, Some dec)) -> ( match Melange_ffi.Utf8_string.transform ~loc ~delim:dec - (Melange_compiler_libs.Ast_helper.Exp.constant + (Ocaml_common.Ast_helper.Exp.constant (Pconst_string (s, loc, Some dec))) s with @@ -827,7 +827,7 @@ module Mapper = struct | Pexp_constant (Pconst_string (s, loc, Some dec)) -> ( match Melange_ffi.Utf8_string.transform ~loc ~delim:dec - (Melange_compiler_libs.Ast_helper.Exp.constant + (Ocaml_common.Ast_helper.Exp.constant (Pconst_string (s, loc, Some dec))) s with diff --git a/vendor/dune b/vendor/dune index 9e2fa498c5..db37a297b1 100644 --- a/vendor/dune +++ b/vendor/dune @@ -22,31 +22,4 @@ (package melange) (flags -w -9) (libraries menhirLib melange_wrapper) - (modules_without_implementation annot outcometree parsetree)) - (ocamllex - (modules lexer) - (mode fallback)) - (menhir - (modules parser) - ; flag reference: - ; https://github.com/ocaml/ocaml/blob/f0a1be6f0/Makefile.menhir#L76-L82 - (flags - --lalr - --explain - --dump - --require-aliases - --strict - --table - -lg - 1 - -la - 1 - --unused-token - COMMENT - --unused-token - DOCSTRING - --unused-token - EOL - --unused-token - GREATERRBRACKET - --fixed-exception)))) + (modules_without_implementation annot)))) diff --git a/vendor/melange-compiler-libs b/vendor/melange-compiler-libs index f9fc9bca65..107b831293 160000 --- a/vendor/melange-compiler-libs +++ b/vendor/melange-compiler-libs @@ -1 +1 @@ -Subproject commit f9fc9bca658c1b2cfb3846136549a87e112f89c5 +Subproject commit 107b831293b9646e5641be4f95ab9f6f541bc104 From e80d7816d8808054c13ff61e1557f1c120a7e186 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 26 Feb 2024 16:18:43 -0800 Subject: [PATCH 2/4] update flake.lock --- flake.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/flake.lock b/flake.lock index 92fb924349..030cce761e 100644 --- a/flake.lock +++ b/flake.lock @@ -28,11 +28,11 @@ ] }, "locked": { - "lastModified": 1707270273, - "narHash": "sha256-j3UD9YDr6+nSI+pPoSXPNtx4fkioXVz6cuY6kapPomI=", + "lastModified": 1708992522, + "narHash": "sha256-+q9z75GOxp4sGCO7d96ZD7cXRYrqWDSGFEDDzxcT/Zs=", "owner": "melange-re", "repo": "melange-compiler-libs", - "rev": "f9fc9bca658c1b2cfb3846136549a87e112f89c5", + "rev": "107b831293b9646e5641be4f95ab9f6f541bc104", "type": "github" }, "original": { @@ -64,11 +64,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1707805436, - "narHash": "sha256-sIqSJEw5YQ1bzdvcmI1gT2iKi8BKo6k2hqUjhhMO0NE=", + "lastModified": 1708983886, + "narHash": "sha256-Wnw1GQLCDhgD9Nak2ydgQzdofMUxjDZNDZnUk/nRKTI=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "4798f032adaac2dea14e1d720d39b2b781ca769b", + "rev": "66d7ac4e97e2acbbf9225f165d045f035b5a5734", "type": "github" }, "original": { @@ -79,17 +79,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1707758094, - "narHash": "sha256-p7hfbRaCTyDsIfcNb0pCCDypCj8RvTW2VMVyVcJK0xk=", + "lastModified": 1708954320, + "narHash": "sha256-n3LXNMlz7ORCjfIrIUo19a844Fec2+yg7k6NspdVCxs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3560d1c8269d0091b9aae10731b5e85274b7bbc1", + "rev": "94cda73bf2fd675de987db7c3ac81e861b892266", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "3560d1c8269d0091b9aae10731b5e85274b7bbc1", + "rev": "94cda73bf2fd675de987db7c3ac81e861b892266", "type": "github" } }, From 7d2fb88d9c682f4425ead631e5ad953579f8b020 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 26 Feb 2024 16:21:55 -0800 Subject: [PATCH 3/4] chore: add changelog entry --- Changes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changes.md b/Changes.md index f8272bfe47..e1ca82f334 100644 --- a/Changes.md +++ b/Changes.md @@ -28,6 +28,9 @@ Unreleased [#658](https://github.com/melange-re/melange/issues/658)) - core: print lambda IR after TRMC pass when `--drawlambda` is passed ([#1072](https://github.com/melange-re/melange/pull/1072)) +- core: remove unnecessary internal code from melange-compiler-libs, slimming + down the melange executable and speeding up the build + ([#1075](https://github.com/melange-re/melange/pull/1075)) 3.0.0 2024-01-28 --------------- From 72ff6e0b40b1b03acbe4f86c01f70636ab2203d6 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Mon, 26 Feb 2024 16:26:08 -0800 Subject: [PATCH 4/4] fix: make test dune version-agnostic --- test/blackbox-tests/virtual-lib-compilation.t | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/test/blackbox-tests/virtual-lib-compilation.t b/test/blackbox-tests/virtual-lib-compilation.t index 48f194441b..3d91c4f95c 100644 --- a/test/blackbox-tests/virtual-lib-compilation.t +++ b/test/blackbox-tests/virtual-lib-compilation.t @@ -44,17 +44,7 @@ > let () = print_endline Vlib.hello > EOF - $ dune build @mel --display=short - ocamldep vlib/.vlib.objs/virt.intf.d - ocamldep impl_melange/.impl_melange.objs/virt.impl.d - ocamldep vlib/.vlib.objs/vlib.impl.d - melc vlib/.vlib.objs/melange/virt.{cmi,cmti} - melc vlib/.vlib.objs/melange/vlib.{cmi,cmj,cmt} - melc impl_melange/.impl_melange.objs/melange/virt.{cmj,cmt} - melc output/vlib/vlib.js - melc .output.mobjs/melange/melange__X.{cmi,cmj,cmt} - melc output/impl_melange/virt.js - melc output/x.js + $ dune build @mel $ output=_build/default/output/x.js $ node "$output"