-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
playground: make jsoo_main compile #538
Conversation
Managed to print the internals of the cryptic
So it seems for some reason the Melange stdlib is not being "linked" in the resulting Line 45 in 6944289
But still get the same error. |
I don't think this mean that the stdlib was not linked in, but rather that the CMI of the stdlib was not found by the type checker |
Look at |
@hhugo thanks for the pointers! I started remembering now that I have to set up a process where the cmis and cmjs for the libraries used are placed somewhere, so they can be loaded in the static "pseudo" file system that jsoo uses at runtime. I found the relevant part of the process in rescript repo, where I understand that for the pseudo file system to work, besides preparing the cm*s like mentioned above, the jsoo build of melange should ignore the
|
I got over the Stdlib errors by loading the There is now some error the second time the compiler is invoked that I will investigate next:
|
There is probably some |
I could track it down to this line, where the lambda exports and the "meta exports" differ in length. Noticed there is something missing in the |
Upgraded compiler libs in #591 so you should get them if you rebase. |
This reverts commit 9cbe9c5.
I think the PR is in a state where it could be reviewed, before adding more functionality to the playground build, like Reason syntax or custom libraries cmi/js. The only item from the todo list in the description that I couldn't find a fix for are the warnings. I saw there a line in the melange runtime lib that has a value Otherwise, the following works:
|
jscomp/main/jsoo_main.ml
Outdated
let ast = Ppx_entry.rewrite_implementation ast in | ||
let ast = Js_implementation.Ppx_entry.rewrite_implementation ast in | ||
let ast = | ||
Melange_ppxlib_ast.Of_ppxlib.copy_structure |
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 changed a bit in #604
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 am not sure what is the right way to convert these asts now, using a lot of magic... 529df6a
there's a bit of a conflict with #615, you should be good just moving your files to |
@anmonteiro All the review comments were tackled. I mainly have doubts about the changes required after #604, there is too much magic but that seems to be the way these conversions are done now, and I am not sure how to do it otherwise. |
Ah, I also added some test for the playground to avoid having to run all these commands in Node manually every time anything changes. I couldn't find a way to have this test run with all the other tests, as the only way to set an env var for the |
bin/jsoo_main.ml
Outdated
let converted = | ||
Convert.copy_structure (Ppxlib.Driver.map_structure ppxlib_ast) | ||
in | ||
(Obj.magic converted : Parsetree.structure) |
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'm pretty sure this is wrong. You probably copied it from melc.ml
.
This is applying the PPXes and converting the preprocessed AST to the current switch version. Also Parsetree.structure
isn't what you think it is because you open
ed Melange_compiler_libs
globally.
In the playground, we just need this AST version to be the Melange_compiler_libs parsetree, I think? so we might not need to make the copy at all?
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 just pushed 53dc2dc fixing this
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.
You probably copied it from melc.ml.
Yes.
In the playground, we just need this AST version to be the Melange_compiler_libs parsetree, I think? so we might not need to make the copy at all?
Just curious, I noticed you left the copy_structure
calls, why does ppxlib need them?
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.
Ppxlib has its own version of the AST. So we need to convert from the melange version to its internal AST version and back. Right now that’s 4.14 so we technically don’t need these. But it’s better to avoid bugs when ppxlib bumps AST versions.
The I haven't found a way to abstract over these that I'm happy with, so I've been repeating slight variations of the same code (now present in 3 places IIRC). I'll clean it up soon. |
Let's do this. |
A humble start, just make
Jsoo_main
compile in a jsoo executable. As this part of the code is never exercised in ci, it had rotten quite a bit.Now, it can be loaded from node, but instantly triggers a cryptic runtime error the moment you try to compile anything.
Repro:
TODO
Not sure if all should be part of this PR, or some parts can be deferred.
BS_BROWSER
: not sure how to set env var only for a dune executableWarning: integer overflow: integer 0x100000000 (4294967296) truncated to 0x0 (0); the generated code might be incorrect.
error_of_exn
returnsSome
Jsoo_main
to ci to prevent future rotdune build --profile=prod jscomp/main/jsoo_main.bc.js
crashes (maybe related toBS_BROWSER
)melange.ppx
and the "internal" ppx apply to the input code