diff --git a/circuits/plonk-15-wires/src/gate.rs b/circuits/plonk-15-wires/src/gate.rs index 7e7aaed0fe..6ad1988938 100644 --- a/circuits/plonk-15-wires/src/gate.rs +++ b/circuits/plonk-15-wires/src/gate.rs @@ -117,7 +117,7 @@ impl JointLookup { )] #[cfg_attr( feature = "ocaml_types", - derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::OcamlEnum) + derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Enum) )] #[cfg_attr(test, derive(proptest_derive::Arbitrary))] pub enum GateType { @@ -423,10 +423,9 @@ pub mod caml { use super::*; use crate::wires::caml::CamlWire; use itertools::Itertools; - use ocaml_gen::OcamlGen; use std::convert::TryInto; - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlCircuitGate { pub row: ocaml::Int, pub typ: GateType, diff --git a/circuits/plonk-15-wires/src/nolookup/scalars.rs b/circuits/plonk-15-wires/src/nolookup/scalars.rs index 80a9292471..c61c12df02 100644 --- a/circuits/plonk-15-wires/src/nolookup/scalars.rs +++ b/circuits/plonk-15-wires/src/nolookup/scalars.rs @@ -102,14 +102,13 @@ impl Default for RandomOracles { #[cfg(feature = "ocaml_types")] pub mod caml { use super::*; - use ocaml_gen::OcamlGen; use oracle::sponge::caml::CamlScalarChallenge; // // CamlLookupEvaluations // - #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlLookupEvaluations { pub sorted: Vec>, pub aggreg: Vec, @@ -155,7 +154,7 @@ pub mod caml { // CamlProofEvaluations // - #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlProofEvaluations { pub w: ( Vec, @@ -279,7 +278,7 @@ pub mod caml { // RandomOracles <-> CamlRandomOracles // - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlRandomOracles { pub joint_combiner: (CamlScalarChallenge, CamlF), pub beta: CamlF, diff --git a/circuits/plonk-15-wires/src/wires.rs b/circuits/plonk-15-wires/src/wires.rs index 71d3d48f54..1dd228969c 100644 --- a/circuits/plonk-15-wires/src/wires.rs +++ b/circuits/plonk-15-wires/src/wires.rs @@ -58,10 +58,9 @@ impl FromBytes for Wire { #[cfg(feature = "ocaml_types")] pub mod caml { use super::*; - use ocaml_gen::OcamlGen; use std::convert::TryInto; - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlWire { pub row: ocaml::Int, pub col: ocaml::Int, diff --git a/circuits/plonk/src/scalars.rs b/circuits/plonk/src/scalars.rs index addd439700..aa5c8a3ce8 100644 --- a/circuits/plonk/src/scalars.rs +++ b/circuits/plonk/src/scalars.rs @@ -75,14 +75,13 @@ impl RandomOracles { #[cfg(feature = "ocaml_types")] pub mod caml { use super::*; - use ocaml_gen::OcamlGen; use oracle::sponge::caml::CamlScalarChallenge; // // ProofEvaluations <-> CamlProofEvaluations // - #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlProofEvaluations { pub l: Vec, pub r: Vec, @@ -134,7 +133,7 @@ pub mod caml { // RandomOracles <-> CamlRandomOracles // - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlRandomOracles { pub beta: CamlF, pub gamma: CamlF, diff --git a/dlog/commitment/src/commitment.rs b/dlog/commitment/src/commitment.rs index 3a7a8756e7..835fea4578 100644 --- a/dlog/commitment/src/commitment.rs +++ b/dlog/commitment/src/commitment.rs @@ -1165,11 +1165,10 @@ mod tests { #[cfg(feature = "ocaml_types")] pub mod caml { use super::*; - use ocaml_gen::OcamlGen; // polynomial commitment - #[derive(Clone, Debug, ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(Clone, Debug, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlPolyComm { pub unshifted: Vec, pub shifted: Option, @@ -1229,7 +1228,7 @@ pub mod caml { // opening proof - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlOpeningProof { pub lr: Vec<(G, G)>, // vector of rounds of L & R commitments pub delta: G, diff --git a/dlog/plonk-15-wires/src/prover.rs b/dlog/plonk-15-wires/src/prover.rs index 49c95eed7d..8ad2196af3 100644 --- a/dlog/plonk-15-wires/src/prover.rs +++ b/dlog/plonk-15-wires/src/prover.rs @@ -709,10 +709,9 @@ where pub mod caml { use super::*; use commitment_dlog::commitment::caml::{CamlOpeningProof, CamlPolyComm}; - use ocaml_gen::OcamlGen; use plonk_15_wires_circuits::nolookup::scalars::caml::CamlProofEvaluations; - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlProverProof { pub commitments: CamlProverCommitments, pub proof: CamlOpeningProof, @@ -723,7 +722,7 @@ pub mod caml { pub prev_challenges: Vec<(Vec, CamlPolyComm)>, } - #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlProverCommitments { // polynomial commitments pub w_comm: ( diff --git a/dlog/plonk/src/prover.rs b/dlog/plonk/src/prover.rs index 2874666ea8..3f61944af9 100644 --- a/dlog/plonk/src/prover.rs +++ b/dlog/plonk/src/prover.rs @@ -434,7 +434,6 @@ where pub mod caml { use super::*; use commitment_dlog::commitment::caml::{CamlOpeningProof, CamlPolyComm}; - use ocaml_gen::OcamlGen; use plonk_circuits::scalars::caml::CamlProofEvaluations; // @@ -442,7 +441,7 @@ pub mod caml { // /// The ocaml type for ProverCommitments - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlProverCommitments { pub l_comm: CamlPolyComm, pub r_comm: CamlPolyComm, @@ -487,7 +486,7 @@ pub mod caml { // ProverProof <-> CamlProverProof // - #[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlProverProof { pub commitments: CamlProverCommitments, pub proof: CamlOpeningProof, diff --git a/ocaml/ocaml-gen/README.md b/ocaml/ocaml-gen/README.md index 2ce5e594d8..3195c26e0e 100644 --- a/ocaml/ocaml-gen/README.md +++ b/ocaml/ocaml-gen/README.md @@ -49,44 +49,38 @@ decl_module!(w, env, "ImportantType", { To allow the previous example to work, you must derive the correct functions on your types and functions. To do that, you can use the [ocaml-derive](./derive) crate. -To allow generation of bindings on structs, use [OCamlGen](): +To allow generation of bindings on structs, use [Struct](): ```rust -use ocaml_gen::OcamlGen; - -#[OcamlGen] +#[ocaml_gen::Struct] struct MyType { // ... } ``` -To allow generation of bindings on enums, use [OcamlEnum](): +To allow generation of bindings on enums, use [ocaml_gen::Enum](): ```rust -use ocaml_gen::OcamlEnum; - -#[OcamlEnum] +#[ocaml_gen::Enum] enum MyType { // ... } ``` -To allow generation of bindings on functions, use [ocaml_gen](): +To allow generation of bindings on functions, use [ocaml_gen::func](): ```rust -#[ocaml_gen] +#[ocaml_gen::func] #[ocaml::func] // if you use the crate ocaml-rs' macro, it must appear after pub fn your_function(arg1: String) { //... } ``` -To allow generation of bindings on custom types, use [OCamlCustomType](): +To allow generation of bindings on custom types, use [ocaml_gen::CustomType](): ```rust -use ocaml_gen::OCamlCustomType; - -#[OCamlCustomType] +#[ocaml_gen::CustomType] struct MyCustomType { // ... } diff --git a/ocaml/ocaml-gen/derive/src/lib.rs b/ocaml/ocaml-gen/derive/src/lib.rs index d848b278bf..5af3e0ecf7 100644 --- a/ocaml/ocaml-gen/derive/src/lib.rs +++ b/ocaml/ocaml-gen/derive/src/lib.rs @@ -19,7 +19,7 @@ use syn::{ /// For example: /// /// ``` -/// #[ocaml_gen] +/// #[ocaml_gen::func] /// #[ocaml::func] /// pub fn something(arg1: String) { /// //... @@ -27,7 +27,7 @@ use syn::{ /// ``` /// #[proc_macro_attribute] -pub fn ocaml_gen(_attribute: TokenStream, item: TokenStream) -> TokenStream { +pub fn func(_attribute: TokenStream, item: TokenStream) -> TokenStream { let item_fn: syn::ItemFn = syn::parse(item).unwrap(); let rust_name = &item_fn.sig.ident; @@ -94,27 +94,26 @@ pub fn ocaml_gen(_attribute: TokenStream, item: TokenStream) -> TokenStream { } // -// OcamlEnum +// Enum // -/// The OcamlEnum derive macro. +/// The Enum derive macro. /// It generates implementations of ToOCaml and OCamlBinding on an enum type. /// The type must implement [ocaml::IntoValue] and [ocaml::FromValue] /// For example: /// /// ``` -/// use ocaml_gen::OcamlEnum; +/// use ocaml_gen::Enum; /// -/// #[OcamlEnum] +/// #[Enum] /// enum MyType { /// // ... /// } /// ``` /// -#[proc_macro_derive(OcamlEnum)] +#[proc_macro_derive(Enum)] pub fn derive_ocaml_enum(item: TokenStream) -> TokenStream { - let item_enum: syn::ItemEnum = - syn::parse(item).expect("only enum are supported with OcamlEnum"); + let item_enum: syn::ItemEnum = syn::parse(item).expect("only enum are supported with Enum"); // // ocaml_desc @@ -346,27 +345,25 @@ pub fn derive_ocaml_enum(item: TokenStream) -> TokenStream { } // -// OcamlGen +// Struct // -/// The OcamlGen derive macro. +/// The Struct derive macro. /// It generates implementations of ToOCaml and OCamlBinding on a struct. /// The type must implement [ocaml::IntoValue] and [ocaml::FromValue] /// For example: /// /// ``` -/// use ocaml_gen::OcamlGen; -/// -/// #[OcamlGen] +/// #[ocaml_gen::Struct] /// struct MyType { /// // ... /// } /// ``` /// -#[proc_macro_derive(OcamlGen)] +#[proc_macro_derive(Struct)] pub fn derive_ocaml_gen(item: TokenStream) -> TokenStream { let item_struct: syn::ItemStruct = - syn::parse(item).expect("only structs are supported with OCamlGen"); + syn::parse(item).expect("only structs are supported with Struct"); let name = &item_struct.ident; let generics = &item_struct.generics.params; let fields = &item_struct.fields; @@ -624,15 +621,15 @@ pub fn derive_ocaml_gen(item: TokenStream) -> TokenStream { /// For example: /// /// ``` -/// use ocaml_gen::OCamlCustomType; +/// use ocaml_gen::CustomType; /// -/// #[OCamlCustomType] +/// #[CustomType] /// struct MyCustomType { /// // ... /// } /// ``` /// -#[proc_macro_derive(OCamlCustomType)] +#[proc_macro_derive(CustomType)] pub fn derive_ocaml_custom(item: TokenStream) -> TokenStream { let item_struct: syn::ItemStruct = syn::parse(item).expect("only structs are supported at the moment"); @@ -677,7 +674,7 @@ pub fn derive_ocaml_custom(item: TokenStream) -> TokenStream { if new_type { let ty_name = rename.unwrap_or(#ocaml_name); let ty_id = ::unique_id(); - env.new_custom_type(ty_id, ty_name); + env.new_type(ty_id, ty_name); } let name = ::ocaml_desc(env, &[]); diff --git a/ocaml/ocaml-gen/src/lib.rs b/ocaml/ocaml-gen/src/lib.rs index 1ec3d9699c..6a439ead83 100644 --- a/ocaml/ocaml-gen/src/lib.rs +++ b/ocaml/ocaml-gen/src/lib.rs @@ -44,12 +44,6 @@ impl Env { }; } - /// Declares a new custom type. Unlike [new_type] this can be called several times with the same type. - pub fn new_custom_type(&mut self, ty: u128, name: &'static str) { - self.locations - .insert(ty, (self.current_module.clone(), name)); - } - /// retrieves a type that was declared previously pub fn get_type(&self, ty: u128, name: &str) -> String { let (type_path, type_name) = self.locations.get(&ty).expect(&format!( @@ -118,9 +112,9 @@ impl Env { // /// OCamlBinding is the trait implemented by types to generate their OCaml bindings. -/// It is usually derived automatically via the [OcamlGen] macro, -/// or the [OCamlCustomType] macro for custom types. -/// For functions, refer to the [ocaml_gen] macro. +/// It is usually derived automatically via the [Struct] macro, +/// or the [CustomType] macro for custom types. +/// For functions, refer to the [func] macro. pub trait OCamlBinding { /// will generate the OCaml bindings for a type (called root type). /// It takes the current environment [Env], @@ -129,8 +123,8 @@ pub trait OCamlBinding { } /// OCamlDesc is the trait implemented by types to facilitate generation of their OCaml bindings. -/// It is usually derived automatically via the [OcamlGen] macro, -/// or the [OCamlCustomType] macro for custom types. +/// It is usually derived automatically via the [Struct] macro, +/// or the [CustomType] macro for custom types. pub trait OCamlDesc { /// describes the type in OCaml, given the current environment [Env] /// and the list of generic type parameters of the root type diff --git a/ocaml/tests/src/lib.rs b/ocaml/tests/src/lib.rs index 6420992aba..cd9a07b43b 100644 --- a/ocaml/tests/src/lib.rs +++ b/ocaml/tests/src/lib.rs @@ -1,13 +1,13 @@ -#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::OcamlGen)] +#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct SingleTuple(String); -#[ocaml_gen::ocaml_gen] +#[ocaml_gen::func] #[ocaml::func] pub fn new() -> SingleTuple { SingleTuple(String::from("Hello")) } -#[ocaml_gen::ocaml_gen] +#[ocaml_gen::func] #[ocaml::func] pub fn print(s: SingleTuple) { println!("{}", s.0); diff --git a/oracle/src/sponge.rs b/oracle/src/sponge.rs index 7fe73d5fd7..bc0d2724ad 100644 --- a/oracle/src/sponge.rs +++ b/oracle/src/sponge.rs @@ -215,13 +215,12 @@ where #[cfg(feature = "ocaml_types")] pub mod caml { use super::*; - use ocaml_gen::OcamlGen; // // ScalarChallenge <-> CamlScalarChallenge // - #[derive(Debug, Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)] + #[derive(Debug, Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)] pub struct CamlScalarChallenge(pub CamlF); impl From> for CamlScalarChallenge