-
Notifications
You must be signed in to change notification settings - Fork 550
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
Rust bindings to OCaml native objects #6545
Conversation
These do some low-level fiddling to make sure that we strictly stick to the allocations necessary. The result is unpleasant, but works.
Updated to add a couple of bindings that were missing. |
CamlTweedleFp(endo_q) | ||
} | ||
|
||
#[no_mangle] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does the annotation here differ from the one above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops! Fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very cool -- had a few qs
} | ||
|
||
#[ocaml::func] | ||
pub fn caml_tweedle_fp_is_square(x: CamlTweedleFpPtr) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed some functions take CamlTweedleFp
and some take CamlTweedleFpPtr
-- what determines that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CamlTweedleFp
is the representation, CamlTweedleFpPtr
is effectively a &CamlTweedleFp
where the reference points to the OCaml heap. We can write CamlTweedleFp
s, but reading them has to go through CamlTweedlePtr
to handle the fact that the OCaml GC can relocate the data.
@@ -0,0 +1,171 @@ | |||
use crate::tweedle_dee::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the srses special?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mirrors what we did in the previous bindings, where we have 1 long-lived SRS and its references are used in any keys loaded with it. IIRC it's several MBs too, so not ideal to store in the OCaml heap as a custom blob.
Deploy preview for mina-staging ready! Built with commit 7c215a8 |
This PR implements rust bindings allocated directly on the OCaml heap.
Vec<_> <-> _ array
. We are careful to avoid passing non-OCaml-heapVec<_>
s as OCaml objects, since they appear 'small' to the OCaml GC (they are effectively a small wrapper around a pointer) but may point to an arbitrarily large amount of memory in the rust heap.value
kindGiven the size of this PR, it may be valuable to review commit-by-commit. Excepting a few tidying up PRs, the vast majority add the bindings for a single type or type family (e.g. fields, groups, urs, etc.).
To test the bindings in utop with dune, I have found it useful to add printers for the fields, as below.
Sample output (verification key parsing bindings test):
Checklist: