tizoc / ocaml-interop

OCaml<->Rust FFI with an emphasis on safety.
MIT License
135 stars 22 forks source link

Switch to a caller-rooted arguments calling convention for Rust exported functions #16

Closed tizoc closed 3 years ago

tizoc commented 3 years ago

Changes

Continued in #17

tizoc commented 3 years ago

@zshipko I'm making some big changes to the calling convention here, but the result will be a far simpler model that will not require macros to call OCaml functions (which are required for handling all the lifetime-related dance). I don't think it should have much impact on how ocaml-derive handles exported functions.

tl;dr is that now every Rust function exposed to OCaml receives rooted (&OCamlRooted<T>) arguments, and every function imported from OCaml will have to be called with rooted arguments too. For the time being this sill probably incur a small overhead, but if the OCaml runtime/compiler adds support for this calling convention, that should go away.

Another change is that exceptions will not be converted into Errs anymore, but instead panic by default. I have to figure out an abstraction that lets the user handle these exceptions when required. The idea here is that the OCaml-side should present any failure situation by returning Result.t values instead of raising exceptions, and any exception that is raised from the OCaml-side will be considered as unexpected.