-
Notifications
You must be signed in to change notification settings - Fork 470
Add BS JS Playground reason support #3976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BS JS Playground reason support #3976
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments, also there are several things that needs to be addressed:
- there are unnecessary changes to
bsb_native.ml
andbsb.ml
that makes this PR hard to review - refmt error catching needs to be implemented before merging
- shake_compile doesn't work with reason
lib/4.06.1/unstable/bsb_native.ml
Outdated
"\n\ | ||
\n\ | ||
let () = Js.log \"Hello, BuckleScript\"")]) ; | ||
Dir (".vscode", [ | ||
File ("tasks.json", | ||
Dir (".vscode", [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea on what's causing this spaces... is it using some kind of formatter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, so it seems like the spaces are included in the jscomp/bsb/bsb_templates
and ever since these files have never been checked in then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped the files from this PR, since it is not related
This looks good to me |
An update on point 1) where I asked if it's the right way. To put everything in perspective number wise, here are some facts: (Numbers are extracted by the day of this writing)
Current build:
Conclusion: |
Basically ready for review, but Reason needs to merge the PR regarding bspacking refmt first to have the docs synced up with the actual Reason repo. Next steps:
|
jscomp/main/jsoo_main.ml
Outdated
"type" , inject @@ Js.string "error" | ||
|] | ||
) | ||
|
||
let () = | ||
Bs_conditional_initial.setup_env (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me in general.
Can we make a separate file instead of enriching such file, like reason_main.ml, the reason is that
currently this is file is buildable, when reason linked in this file may not be easily buildable, we can have two files : one with vanilla ocaml which has less deps, the other has reason which is larger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean by "when reason is linked, this file may not be easily buildable"? Do you mean because of the reliability of the Reason code?
But yes, we can totally do a "jsoo_reason_main.ml" file exposing the ocaml + reason interface as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general we don't compile packed files(to make compile time less for productivity) during dev but we compile jsoo_main.ml during dev. A separate file would help save some compilation time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bobzhang So I would create a file jscomp/main/jsoo_refmt_main.ml
. How would I configure ninja, or whatever part is responsible, to build this file the way you want it? I am not even sure how this is supposed to save compilation time. It looks like it is as fast as without reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryyppy just add a new file to main and run ./scripts/ninja.js config.
I think the best course of action would be jsoo_refmt_main.ml reusing functions from jsoo_main.ml instead of duplicating everything.
jscomp/main/jsoo_main.ml
Outdated
@@ -180,7 +188,12 @@ let dir_directory d = | |||
let () = | |||
dir_directory "/static/cmis" | |||
|
|||
let make_compiler name impl = | |||
module Converter = Refmt_api.Migrate_parsetree.Convert(Refmt_api.Migrate_parsetree.OCaml_404)(Refmt_api.Migrate_parsetree.OCaml_406) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is reason developed against 404? Maybe a good time to bump into 406 as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we open an issue on Reason to let them know that BS v7 and above won't have any active 4.02 builds anymore? Not sure what Reason planned to support on the OCaml side, but maybe they consider to raise the minimum requirement to 4.06?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, if they raise to 406 then such conversion is free?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently there seems to be a plan to upgrade. I created an issue to verify this:
reason#2496
I pushed some new changes adding the new file |
@bobzhang Added a I am a little bit hesitant to do bigger refactors since afaik we don't have any integration tests for the javascript bundle yet. I wanted to address tests in a later PR to make sure everything works in the future. |
CONTRIBUTING.md
Outdated
@@ -312,6 +312,53 @@ load the data. Right now we don't provide any instructions inside here yet, but | |||
[here's how the official ReasonML playground did | |||
it](https://github.com/reasonml/reasonml.github.io/blob/source/website/setupSomeArtifacts.js#L65). | |||
|
|||
### Upgrading the Reason version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryyppy Thanks for this work documenting the process! One question / suggestion :)
I started reading this section as part of the larger "Contributing to the BS Playground Bundle" above, but got confused when 2 versions of refmt are discussed. My main doubt was "why does the BS playground need two versions of refmt? Wouldn't refmt_api be enough?".
Then I understood (maybe wrongly?) that refmt_api
is what is used in the playground, and refmt_main3
is what BS uses when it runs natively, so it's not used in the playground (that was the confusing part).
If that assumption is right, maybe it'd be worth making the whole "Upgrading the Reason version" section an h2 (##) instead of h3, so that it "escapes" the "Contributing to the BS Playground Bundle" above and stands on its own, as an explanation on how these 2 packed files are generated, and how to keep Reason versions in sync with BS.
Maybe also rename the section to "Upgrading the Reason version for both native- and JavaScript-compiled versions of BS".
I hope that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I lifted the "Reason upgrading" section to an H2 and made it kinda independent from the Playground header. I hope it is more clear now?
Also syncs reason_binary
This PR add specific error handling for refmt_api so it would show the correct location of the syntax error
This will restore the original `jsoo_main.ml` and introduce an enhanced `jsoo_refmt_main` with the `Refmt_Api` dependency built in. Also adds a rule to `jscomp/snapshot.ninja` to build bytecode for the new `jsoo_refmt_main.ml` file, so we can `repl.js` it into a bundle file. `repl.js` will build the new jsoo_refmt_main bytecode target instead.
6fc6b41
to
4f9e376
Compare
Rebased to newest master to be able to merge |
Related to #3857 |
This PR is an attempt to add refmt_api to the jsoo_main to be able to parse and interpret Reason code without independently compiling Reason to
refmt.js
and wire everything up ourselves.I added CONTRIBUTION docs to describe the build workflow for creating bspacked
refmt_api.ml
andrefmt_binary.ml
files. The docs are only valid when reason#2495 is merged though.The cool thing is that we could potentially have a properly synced up Reason version in the
reason_api
bundle, giving us something like this in the browser:^ this is exciting, since it enables us to display this information in the Playground UI
There are still some open questions for this though (please help us out here @bobzhang):
Is this the right way to do it? Adding refmt_api will presumably cause the resulting-> See another comment belowexports.js
file to grow. I have no perspective on how much the difference is to shippingrefmt.js
independentlyShould we take the chance and refactor the public api (-> We will discuss this in another PRwindow.ocaml
/window.reason
) to something more unified such aswindow.bucklescript
?all based on previous work of @thangngoc89
Sidenote:
[email protected] apparently has syntax regressions which need to be addressed before any further official releases!