Issue 58134
Summary The OCaml bindings heavily use naked pointers, which have been deprecated in OCaml 4.11 and will not be supported in OCaml 5
Labels new issue
Assignees
Reporter alan-j-hu
    When modifying the LLVM OCaml bindings, I noticed that the code uses naked pointers (pointers to memory outside the OCaml heap that are not wrapped in a special block). For just one example, see

https://github.com/llvm/llvm-project/blob/0a9756fc15c57dc94146e65d251d7a3d941ae78a/llvm/bindings/ocaml/llvm/llvm_ocaml.c#L203

An `LLVMContextRef` is directly returned.

[Since OCaml 4.11, naked pointers have been deprecated. They will not be supported in OCaml 5](https://v2.ocaml.org/manual/intfc.html#ss:c-outside-head), which will move to a new runtime. The recommended solution is to either wrap the pointer in an OCaml block (heap allocation) with an `Abstract_tag` or `Custom_tag`; the GC will not scan the elements of these blocks.

Furthermore, the LLVM bindings contain many resource cleanup functions, such as https://github.com/llvm/llvm-project/blob/0a9756fc15c57dc94146e65d251d7a3d941ae78a/llvm/bindings/ocaml/llvm/llvm.mli#L454 among many others. OCaml blocks with the `Custom_tag` [support finalization functions](https://v2.ocaml.org/manual/intfc.html#s%3Ac-custom). It would be worth it to make use of this feature if removing naked pointers.

I am willing to rewrite the OCaml bindings to use blocks instead of naked pointers, but this is a rather big task, so I wanted to post an issue first and hear the input of LLVM experts. I know that the OCaml OPAM maintainers manually track package build status, so they might also be interested.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to