New Release
bs-platform
5.2.0/6.2.0 is released, it contains several major enhancement
that we would like to share with you.
You can install it via npm i -g bs-platform@5.2.0
Local module compiled into object
OCaml has an advanced module system for people to structure large scale applications, it supports first class module and higher-order module system which is unique compared to other ML-like languages such as F# and Haskell.
In previous versions, BuckleScript compiled local modules into a JS array whereby global modules (module produced by a file)were transformed into JS objects.
When a local module is compiled into a JS array, the field name is stripped away, which makes debugging and JS interop difficult. To make the debugging experience better, we instrumented the array with field names in debug mode, this mitigated the debugging issue, but still present challenges for JS interop.
In this release, the compiler generates uniform representation for global module and local module -- idiomatic JS object, this makes OCaml's module system more valuable to JS target.
Below is an image showing the diff in this release
As you can see, the id
module changed from an array into an JS object.
Pattern match code generation with annotations
BuckleScript aims to generate readable code.
OCaml has a sophiscated pattern match compiler, it generates well optimized code, however, for complex pattern matching, the constructor name is lost on native backend, this is also one of the very few case where we generate magic number in JS backend, this makes debugging particularly challenging for large complex pattern match.
In this release, we made such information available to JS backend so that we annotate the generated JS code with its names.
Below is an image showing the diff in this release
In the future, we will explore if we can produce such annotation in the runtime without losing efficiency.
Code generation improvement in various places
We care about the generated code quality, and will always keep improving it regardless how good it is.
In this release, we improved the code generation in quite a lot of places including lazy evaluation, if branches and pattern match.
In particular, we added a data-flow pass to eliminate non-necessary staticfail case.
Important bug fixes
This release also comes with a couple of important bug fixes, in particular, #3805 the stale build issue and #3823 the interaction with reason langauge service.
Upcoming breaking changes
In next release, we plan to remove deprecated getters.
A detailed list of changes is available here
Happy hacking!