-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Labels
enhancementNew feature or requestNew feature or request
Description
WIP
Motivation
ocaml-rs already solves a bunch of things that are planned in ocaml-interop
, and ocaml-interop
already provides a safe API that could benefit ocaml-rs
. The idea her is to figure out what would be necessary for "sandwiching" ocaml-interop
in-between ocaml-sys
and ocaml-rs
's higher level APIs.
What ocaml-interop
solves for ocaml-rs
- Lifetimes and proper abstractions to enforce correct usage of OCaml values across OCaml allocations
- More accurate types for OCaml values.
ocaml-rs
represents OCaml values asValue
,ocaml-interop
usesOCaml<T>
. - More fine-grained definitions for OCaml values, this removes a whole class of errors (so there is no need to validate operations performed on an OCaml value, because you know it is of the correct type), and also allows for the definition of new operations for new types.
- Multiple ways to convert a value (
ocaml-rs
has a 1-on-1 mapping between Rust and OCaml values, inocaml-interop
there is more flexibility and control on what can convert into what).
What ocaml-rs
solves for ocaml-interop
- Derivers for structs/enums (
ocaml-interop
uses macros to define how to map between Rust structs/enums and OCaml records/variants) - Support for custom blocks.
- Support for bigarrays.
- Rust panic handling
- OCaml exceptions from the Rust side, handling
Err
results to produce OCaml exceptions - Annotations for exported functions (
ocaml-interop
uses a wrapper macro for this) - Support for bytecode OCaml
Ideas for the future
- Starting from the current
ocaml-rs
derivers, and combined withocaml-interop
's representation of OCaml values, implementations for interacting with OCaml records/variants could be generated forderive
annotated structs so that allocations that result from OCaml->Rust conversions can be avoided, or controlled with more granularity.
Modifications Summary
Additions
WIP
ocaml-sys
: a macro likeocaml_frame
fromocaml-interop
but for plainValue
s to replacecaml_param
?
Changes
WIP
ocaml-rs
:Value
would become a re-export ofocaml-interop
sOCaml<'a, T>
.ocaml-rs
: Exported functions would have an implicitocaml_frame
instead of ancaml_body
.
Deprecations / Removals
WIP
ocaml-sys
:caml_param
andcaml_body
macros.ocaml_frame
macro fromocaml-interop
should be used instead (maybe a lower-level version that works usingRawOCaml
values could be implemented and added toocaml-sys
).ocaml-rs
:List
,Array
, etc types get replaced byOCaml<OCamlList<T>>
, etc types fromocaml-interop
.ocaml-interop
: most (all?) macros related to mapping between Rust<->OCaml Structs/Enums/RecordsVariants. Not needed when theocaml-rs
derivers exist (doesn't cover all the cases that the macros cover, but those are probably better handled by intermediary conversions anyway).ocaml-interop
:ocaml_export
macro, not needed when the function annotations fromocaml-rs
exist.
Other
- Would be great if the OCaml version changes fragility situation could be improved somehow (
ocaml-rs
does a good job already, but it core OCaml could help us here, that would be great, because the OCaml runtime seems to be going through a bunch of changes lately). - At the moment, no synchronization is made by
ocaml-interop
(norocaml-rs
?) for accessing the OCaml runtime, and is left for the user to handle. Having a solution baked into the libraries would be good.
jozanza
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request