diff --git a/blog/posts/melange-4-is-here.md b/blog/posts/melange-4-is-here.md new file mode 100644 index 000000000..96dba6ced --- /dev/null +++ b/blog/posts/melange-4-is-here.md @@ -0,0 +1,105 @@ +--- +title: Melange 4.0 is here +date: 2024-05-22 +author: Antonio Monteiro +gravatar: 45c2052f50f561b9dc2cae59c777aecd794f57269fa317f9c9c3365c2e00d16f +twitter: '@_anmonteiro' +--- + +Today, we're introducing Melange 4.0, the latest version of our backend for the +OCaml compiler that emits JavaScript. + +Melange is now compatible with OCaml 5.2! In this release, Melange starts +emitting more ES6 constructs, supports more JavaScript builtins, improves error +handling, and makes using Dune virtual libraries fully supported. Read on for +more details. + +--- + +## Embracing OCaml 5.2 + +OCaml 5.2 was released just last week. With Melange 4, you can now leverage all +the power and enhancements in this latest OCaml version. We've upgraded the +OCaml type checker and the standard library to match OCaml 5.2's, ensuring you +can select a 5.2-compatible Melange in your projects. + +This does **not** mean Melange is only compatible with OCaml 5.2. As previously +mentioned in the [Melange 3 +announcement](./announcing-melange-3#multiple-ocaml-version-releases), each +Melange version ships one release for every compiler version that it supports; +for OCaml 5.1, this would correspond to Melange `4.0.0-51`. + +## Full Support for Dune Virtual Libraries + +Melange now fully supports [Dune virtual +libraries](https://dune.readthedocs.io/en/stable/variants.html), which requires +Dune 3.15.2. There were a few bumps in road when we thought it wouldn't be +possible to support this use case in Melange. We were thankfully proven wrong +([#1067](https://github.com/melange-re/melange/pull/1067)), and we think that +virtual libraries can become an interesting way to write libraries that work +across Melange and native OCaml, sharing a common interface. + +## Emitting ES6 and Enhanced JavaScript Interop + +In this release, Melange starts emitting ES6, particularly: + +- Melange 4.0 emits `let` instead of `var`, and `const` where possible + ([#1019](https://github.com/melange-re/melange/pull/1019), + [#1059](https://github.com/melange-re/melange/pull/1059)). +- Emitting `let` allowed us to remove a bit of legacy code related to compiling + `for` loops, taking advantage of `let`'s lexical scoping. + ([#1020](https://github.com/melange-re/melange/pull/1020)) + +In our effort to expand the API surface area for JavaScript interoperability, +we've added new bindings to a few more JavaScript features in the `melange.js` +library (whose main entrypoint is the `Js` module): + +- **Js.Bigint**: [#1044](https://github.com/melange-re/melange/pull/1044) added + bindings to work with `BigInt`; +- The **Js.Set** and **Js.Map** modules now bind to even more methods available + in these JavaScript data structures + ([#1047](https://github.com/melange-re/melange/pull/1047), + [#1101](https://github.com/melange-re/melange/pull/1101)). +- **JS Iterators**: We introduced minimal bindings for JavaScript iterators, + making it easier to work with iterable objects, which some other modules' + methods can now return + ([#1060](https://github.com/melange-re/melange/pull/1060)). +- **WeakMap and WeakSet**: Bindings for these weakly referenced collections + have also been added + ([#1058](https://github.com/melange-re/melange/pull/1058)). + +## Improved Error Handling and Code Generation + +In this release, we've also made significant improvements in how Melange +handles errors and generates JavaScript code: + +- Instead of throwing JavaScript objects with Melange exception payloads, we + now emit a Melange-specific error (`throw new MelangeError(..)`) for more + consistent error handling + ([#1036](https://github.com/melange-re/melange/pull/1036)). + - An interesting corollary to this change is that catching Melange errors + from external JavaScript only needs to check `instanceof MelangeError`. + +## Additional Fixes & Enhancements + +- **Slimmer Executable**: We've removed unnecessary internal code from + `melange-compiler-libs`, making the Melange compiled executable smaller in + size and faster to build + ([#1075](https://github.com/melange-re/melange/pull/1075)). +- **Float Operations**: Fixed runtime primitives for `Float.{min,max}` and + related functions, ensuring more accurate mathematical operations + ([#1050](https://github.com/melange-re/melange/pull/1050)). +- **Warning 51 (`wrong-tailcall-expectation`)**: Melange 4 ships with support + for enabling warning 51 and triggering the warning when + [`[@tailcall]`](https://ocaml.org/manual/5.2/attributes.html#ss:builtin-attributes) + is used ([#1075](https://github.com/melange-re/melange/pull/1075)). + +## Conclusion + +The [Melange 4.0 +changelog](https://github.com/melange-re/melange/blob/main/Changes.md#400-2024-05-15) +lists all the changes that made it to this release. + +Thanks for reading and stay tuned for more updates. Happy hacking! + + diff --git a/flake.lock b/flake.lock index 2bcb845a4..eecf1847c 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -26,11 +26,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1684225565, - "narHash": "sha256-Pj75M8cWGJumPuqLGUe1XFQEcrlCeH6zvtGqOXzAE4U=", + "lastModified": 1716431845, + "narHash": "sha256-e08DsEux7CHGHnxN7Qpat5KZcnQGHA9Q4jgEKi68JjY=", "owner": "nix-ocaml", "repo": "nix-overlays", - "rev": "9a29b315228574accfe25224e0842027bc691c50", + "rev": "721abcd302af2a503ce23e7b7079bd800aa473ee", "type": "github" }, "original": { @@ -41,17 +41,17 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1684193874, - "narHash": "sha256-mYTCtTQMcWLBa7r5TxFrwGIb3MQ8QjalaDs1dRuMfHw=", + "lastModified": 1716395399, + "narHash": "sha256-X+99WjSwbxQ7X+CTyqZQZqeqGe8nbfAFz+tgK2r3O/g=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "d38127eb1361b79417f4dfb1719e5fe0d6a326ca", + "rev": "bc5dc89513caa16788f6379962e50383cf3f70b0", "type": "github" }, "original": { "owner": "NixOS", "repo": "nixpkgs", - "rev": "d38127eb1361b79417f4dfb1719e5fe0d6a326ca", + "rev": "bc5dc89513caa16788f6379962e50383cf3f70b0", "type": "github" } }, diff --git a/flake.nix b/flake.nix index ba7e17e30..da01f134b 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ buildInputs = with python3Packages; [ mkdocs mkdocs-print-site-plugin + pkgs.yarn ]; }; };