You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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.
The text was updated successfully, but these errors were encountered: