Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into anmonteiro/try-pp
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Dec 4, 2023
2 parents 50f5265 + b976091 commit 5cc9ada
Show file tree
Hide file tree
Showing 300 changed files with 7,430 additions and 7,794 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/opam-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- ubuntu-latest
# - windows-latest # for some reason windows build is not picking dune 3.5
ocaml-compiler:
- 5.1.x
- ocaml-variants.5.1.1+trunk

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -65,8 +65,8 @@ jobs:
- name: Install all deps
working-directory: melange-opam-template
run: |
opam pin add reason-react-ppx.dev --dev-repo
opam pin add reason-react.dev --dev-repo
opam pin add reason-react-ppx.dev git+https://github.com/reasonml/reason-react#anmonteiro/melange-v3
opam pin add reason-react.dev git+https://github.com/reasonml/reason-react#anmonteiro/melange-v3
npm install
- name: Build basic template
Expand Down
6 changes: 0 additions & 6 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,4 @@ jscomp/test/*/*/*
jscomp/stdlib/*
jscomp/stdlib/*/*

jscomp/core/js_fold.ml
jscomp/core/js_record_map.ml
jscomp/core/js_record_fold.ml
jscomp/core/js_record_iter.ml

rescript-syntax/*
jscomp/js_parser/*
53 changes: 53 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,61 @@ Unreleased
1. Exception ID `RE_EXN_ID` to `MEL_EXN_ID`
2. `BS_PRIVATE_NESTED_SOME_NONE` option marker to
`MEL_PRIVATE_NESTED_SOME_NONE`
- BREAKING(runtime): unify pipe-first / pipe-last libraries in `Js` modules
([#731](https://github.com/melange-re/melange/issues/731),
[#893](https://github.com/melange-re/melange/pull/893),
[#895](https://github.com/melange-re/melange/pull/895),
[#899](https://github.com/melange-re/melange/pull/899))
- Modules ending with `2` (e.g. `Js.String2`, `Js.Array2`,
`Js.TypedArray2`) are no longer available in Melange
- The functions in their corresponding modules now take labeled arguments,
allowing them to be used with both `|.` and `|>`.
- BREAKING(runtime): remove deprecated functions from `Js.*` modules
([#897](https://github.com/melange-re/melange/pull/897))
- Consistently handle empty payloads in externals:
([#852](https://github.com/melange-re/melange/pull/852))
- Fix crash when pattern matching in the presence of complex constant inlining
([#871](https://github.com/melange-re/melange/pull/871))
- Support renaming modules in the output JS with `@mel.as`
([#879](https://github.com/melange-re/melange/pull/879))
- Support `@mel.as` in `@mel.obj` labelled arguments
([#834](https://github.com/melange-re/melange/pull/834))
- Fix error location for empty string interpolation in `{j| .. |j}`
([#888](https://github.com/melange-re/melange/pull/888),
[#890](https://github.com/melange-re/melange/pull/890))
- Add `Js.Obj.assign` to merge 2 JS objects immutably
([#900](https://github.com/melange-re/melange/pull/900),
[#795](https://github.com/melange-re/melange/pull/795))
- Turn off warning 20 (`ignored-extra-argument`) for `%mel.raw` application
([#915](https://github.com/melange-re/melange/pull/915))
- Deprecate non-namespaced FFI attributes such as `@string` or `@obj` in favor
of e.g. `@mel.string` and `@mel.obj`
([#923](https://github.com/melange-re/melange/pull/923))
- Improve error messages returned by `melange.ppx`
([#924](https://github.com/melange-re/melange/pull/924),
[#928](https://github.com/melange-re/melange/pull/928),
[#931](https://github.com/melange-re/melange/pull/931),
[#936](https://github.com/melange-re/melange/pull/936))
- Improve error messages in the Melange compiler core
([#941](https://github.com/melange-re/melange/pull/941))
- Fix a typo in `Node.node_module` (pa{r,}rent)
[#929](https://github.com/melange-re/melange/pull/929)
- BREAKING(runtime): Remove `Js.null_undefined` in favor of `Js.nullable`
([#930](https://github.com/melange-re/melange/pull/930))
- BREAKING(core): require OCaml 5.1.1
([#926](https://github.com/melange-re/melange/pull/926))
- BREAKING(ppx): disallow attribute payload in `[@mel.new]` in favor of the
external primiative string
([#938](https://github.com/melange-re/melange/pull/938))
- Don't process `[@mel.config]` twice
([#940](https://github.com/melange-re/melange/pull/940/))
- BREAKING(ppx): remove `@mel.splice` in favor of `@mel.variadic`
([#943](https://github.com/melange-re/melange/pull/943))
- Introduce an `unprocessed` alert to detect unprocessed Melange code, hinting
users to preprocess with `melange.ppx`
([#911](https://github.com/melange-re/melange/pull/911),
[#945](https://github.com/melange-re/melange/pull/945),
[#947](https://github.com/melange-re/melange/pull/947))

2.1.0 2023-10-22
---------------
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ test:

.PHONY: opam-create-switch
opam-create-switch: ## Create opam switch
opam switch create . 5.1.0 -y --no-install
opam switch create . ocaml-variants.5.1.1+trunk -y --no-install

.PHONY: opam-install-test
opam-install-test: ## Install test dependencies
opam pin add js_of_ocaml-compiler --dev-repo -y
opam pin add js_of_ocaml --dev-repo -y
opam pin add merlin-lib git+https://github.com/voodoos/merlin#5.1.1-upgrade
opam pin add merlin git+https://github.com/voodoos/merlin#5.1.1-upgrade
opam pin add melange.dev . --with-test -y
opam pin add melange-playground.dev . --with-test -y

Expand Down
17 changes: 4 additions & 13 deletions bin/melc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,8 @@ let main: Melc_cli.t -> _ Cmdliner.Term.ret
List.rev_append include_dirs !Clflags.include_dirs;
List.iter ~f:Warnings.parse_alert_option alerts;

begin match warnings with
| [] -> ()
| first :: rest ->
(* If more than one `-w` arguments are present, we insert `"-20"` between
them to give a chance for the last one to turn it off. This also
happens to cover the common case of Dune, which explicitly passes
"+20" (so we override it). *)
Melc_warnings.parse_warnings ~warn_error:false first;
Melc_warnings.parse_warnings ~warn_error:false "-20";
List.iter ~f:(Melc_warnings.parse_warnings ~warn_error:false) rest;
end;
List.iter warnings ~f:(fun w ->
Melc_warnings.parse_warnings ~warn_error:false w);

Option.iter
(fun output_name -> Clflags.output_name := Some output_name)
Expand Down Expand Up @@ -415,14 +406,14 @@ let file_level_flags_handler (e : Parsetree.expression option) =
( List.map ~f:(fun (e: Parsetree.expression) ->
match e.pexp_desc with
| Pexp_constant (Pconst_string(name,_,_)) -> name
| _ -> Location.raise_errorf ~loc:e.pexp_loc "string literal expected" ) args)
| _ -> Location.raise_errorf ~loc:e.pexp_loc "Flags must be a literal array of strings") args)
in
let argv = Melc_cli.normalize_argv (Array.of_list (Sys.argv.(0) :: args)) in
(match Cmdliner.Cmd.eval ~argv melc_cmd with
| c when c = Cmdliner.Cmd.Exit.ok -> ()
| _c -> Location.raise_errorf ~loc:pexp_loc "Invalid configuration")
| Some e ->
Location.raise_errorf ~loc:e.pexp_loc "string array expected"
Location.raise_errorf ~loc:e.pexp_loc "Flags must be a literal array of strings"

let () =
Melangelib.Initialization.Global.run ();
Expand Down
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
(>= 20201214))
pp
(reason-react-ppx
(and :with-test :post))))
(and :with-test :post))
(merlin :with-test)))

(package
(name melange-playground)
Expand Down
20 changes: 10 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 33 additions & 25 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,44 @@
};
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}".appendOverlays [
(self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_1;
})
];
pkgs = nixpkgs.legacyPackages."${system}".extend (self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_1.overrideScope' (oself: osuper: {
ocaml = osuper.ocaml.overrideAttrs (_: {
src = super.fetchFromGitHub {
owner = "ocaml";
repo = "ocaml";
rev = "eee78bf992a2b3e1e99af5e2af1c6ae5ba291ff1";
hash = "sha256-PViNwld8Za6F5v8np3x8cP70JXpTrcIkgodPuJGpfyo=";
};
});
});
});

melange = pkgs.callPackage ./nix {
nix-filter = nix-filter.lib;
melange-compiler-libs-vendor-dir = melange-compiler-libs;
};
in

rec {
packages = {
inherit melange;
default = melange;
melange-playground = pkgs.ocamlPackages.callPackage ./nix/melange-playground.nix {
packages =
let
melange = pkgs.callPackage ./nix {
nix-filter = nix-filter.lib;
melange-compiler-libs-vendor-dir = melange-compiler-libs;
};
in
{
inherit melange;
nix-filter = nix-filter.lib;
melange-compiler-libs-vendor-dir = melange-compiler-libs;
default = melange;
melange-playground = pkgs.ocamlPackages.callPackage ./nix/melange-playground.nix {
inherit melange;
nix-filter = nix-filter.lib;
melange-compiler-libs-vendor-dir = melange-compiler-libs;
};
};
};

melange-shell = opts:
pkgs.callPackage ./nix/shell.nix ({ inherit packages; } // opts);
in
{
inherit packages;
devShells = {
default = pkgs.callPackage ./nix/shell.nix {
inherit packages;
};
release = pkgs.callPackage ./nix/shell.nix {
default = melange-shell { };
release = melange-shell {
release-mode = true;
inherit packages;
};
};
}));
Expand Down
5 changes: 3 additions & 2 deletions jscomp/common/classify_function.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +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. *)

open Import
module Parser_flow = Js_parser.Parser_flow
module Parser_env = Js_parser.Parser_env
module Flow_ast = Js_parser.Flow_ast
Expand All @@ -30,10 +31,10 @@ let rec is_obj_literal (x : _ Flow_ast.Expression.t) : bool =
match snd x with
| Identifier (_, { name = "undefined"; _ }) | Literal _ -> true
| Unary { operator = Minus; argument; _ } -> is_obj_literal argument
| Object { properties; _ } -> List.for_all is_literal_kv properties
| Object { properties; _ } -> List.for_all ~f:is_literal_kv properties
| Array { elements; _ } ->
List.for_all
(fun x ->
~f:(fun x ->
match x with
| Flow_ast.Expression.Array.Expression x -> is_obj_literal x
| _ -> false)
Expand Down
1 change: 0 additions & 1 deletion jscomp/common/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(library
(name melange_ffi)
(package melange)
(flags :standard -open Melange_compiler_libs)
(modules_without_implementation js_raw_info lam_tag_info)
(libraries melstd melange_compiler_libs js_parser))

Expand Down
50 changes: 50 additions & 0 deletions jscomp/common/external_ffi_attributes.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
(* Copyright (C) 2023- Authors of Melange
*
* 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. *)

open Import

let external_attrs =
[|
"get";
"set";
"get_index";
"return";
"obj";
"val";
"module";
"scope";
"variadic";
"send";
"new";
"set_index";
(* TODO(anmonteiro): re-enable when we enable gentype *)
(* Literals.gentype_import; *)
|]

let has_mel_attributes attrs =
List.exists
~f:(fun txt ->
String.starts_with txt ~prefix:"mel."
|| Array.exists ~f:(fun (x : string) -> txt = x) external_attrs)
attrs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* Copyright (C) 2017 Authors of ReScript
(* Copyright (C) 2023- Authors of Melange
*
* 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
Expand All @@ -22,8 +22,4 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

val out_ident : Format.formatter -> Outcometree.out_ident -> unit
(** This function is used to
reverse namespace printing to
avoid namespace leaking
*)
val has_mel_attributes : string list -> bool
Loading

0 comments on commit 5cc9ada

Please sign in to comment.