Skip to content
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

Nativeint type does not exist in melange, causing difficulties with porting native ocaml libs #1148

Open
Josef-Thorne-A opened this issue Jun 29, 2024 · 1 comment

Comments

@Josef-Thorne-A
Copy link

In my quest to port sexplib0, ppx_sexp_conv and other ppx librarie to work at least reasonably well with Melange, I've encountered a significant roadblock. This roadblock would potentially apply to porting other libraries

The nativeint type from the ocaml standard library is unsupported by Melange. I assume this is because it doesn't make sense within the realm of Javascript interpreters.

This is fine for most cases, but if nativeint is required by a third party library it will cause the compiler to complain a lot about the missing/undefined type. Vendoring the library and removing the nativeint functions works fine for libraries which few or no other libraries depend on, but for libraries like sexplib0 which has a lot of dependents this quickly contaminates the entire dependency graph.

For this reason it would be good if we could "fake" or "spoof" the nativeint type, preferably with some kind of warning?

We could try defining a Nativeint module and type in our standard library that behind the scenes either uses an int64 or does some black magic to make the math come out exactly the same as a nativeint. It would probably be good to have Melange spit out some warnings in the former case since it would probably cause some unexpected behavior if you're trying to do super precise integer arithmetic with melange generated code.

Looking at the ocaml stdlib nativeint module, it doesn't look like it uses an abstract type, but nativeint is rather a primitive. I suspect that nativeint using libraries might complain in that case if we tried to fool them into using melange-nativeint, but it could be still worth a try.

@Josef-Thorne-A Josef-Thorne-A changed the title Nativeint type does not exist in melange Nativeint type does not exist in melange, causing difficulties with porting native ocaml libs Jun 29, 2024
@Josef-Thorne-A
Copy link
Author

Related to #164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant