Skip to content

Commit aef71a7

Browse files
committed
[ocaml-gen] rename macros to more helpful names
1 parent 0999b1f commit aef71a7

File tree

12 files changed

+50
-60
lines changed

12 files changed

+50
-60
lines changed

circuits/plonk-15-wires/src/gate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,9 @@ pub mod caml {
423423
use super::*;
424424
use crate::wires::caml::CamlWire;
425425
use itertools::Itertools;
426-
use ocaml_gen::OcamlGen;
427426
use std::convert::TryInto;
428427

429-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
428+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
430429
pub struct CamlCircuitGate<F> {
431430
pub row: ocaml::Int,
432431
pub typ: GateType,

circuits/plonk-15-wires/src/nolookup/scalars.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ impl<F: Field> Default for RandomOracles<F> {
102102
#[cfg(feature = "ocaml_types")]
103103
pub mod caml {
104104
use super::*;
105-
use ocaml_gen::OcamlGen;
106105
use oracle::sponge::caml::CamlScalarChallenge;
107106

108107
//
109108
// CamlLookupEvaluations<CamlF>
110109
//
111110

112-
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
111+
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
113112
pub struct CamlLookupEvaluations<CamlF> {
114113
pub sorted: Vec<Vec<CamlF>>,
115114
pub aggreg: Vec<CamlF>,
@@ -155,7 +154,7 @@ pub mod caml {
155154
// CamlProofEvaluations<CamlF>
156155
//
157156

158-
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
157+
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
159158
pub struct CamlProofEvaluations<CamlF> {
160159
pub w: (
161160
Vec<CamlF>,
@@ -279,7 +278,7 @@ pub mod caml {
279278
// RandomOracles<F> <-> CamlRandomOracles<CamlF>
280279
//
281280

282-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
281+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
283282
pub struct CamlRandomOracles<CamlF> {
284283
pub joint_combiner: (CamlScalarChallenge<CamlF>, CamlF),
285284
pub beta: CamlF,

circuits/plonk-15-wires/src/wires.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ impl FromBytes for Wire {
5858
#[cfg(feature = "ocaml_types")]
5959
pub mod caml {
6060
use super::*;
61-
use ocaml_gen::OcamlGen;
6261
use std::convert::TryInto;
6362

64-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
63+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
6564
pub struct CamlWire {
6665
pub row: ocaml::Int,
6766
pub col: ocaml::Int,

circuits/plonk/src/scalars.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,13 @@ impl<F: Field> RandomOracles<F> {
7575
#[cfg(feature = "ocaml_types")]
7676
pub mod caml {
7777
use super::*;
78-
use ocaml_gen::OcamlGen;
7978
use oracle::sponge::caml::CamlScalarChallenge;
8079

8180
//
8281
// ProofEvaluations<F> <-> CamlProofEvaluations<CamlF>
8382
//
8483

85-
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
84+
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
8685
pub struct CamlProofEvaluations<F> {
8786
pub l: Vec<F>,
8887
pub r: Vec<F>,
@@ -134,7 +133,7 @@ pub mod caml {
134133
// RandomOracles<F> <-> CamlRandomOracles<CamlF>
135134
//
136135

137-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
136+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
138137
pub struct CamlRandomOracles<CamlF> {
139138
pub beta: CamlF,
140139
pub gamma: CamlF,

dlog/commitment/src/commitment.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1164,11 +1164,10 @@ mod tests {
11641164
#[cfg(feature = "ocaml_types")]
11651165
pub mod caml {
11661166
use super::*;
1167-
use ocaml_gen::OcamlGen;
11681167

11691168
// polynomial commitment
11701169

1171-
#[derive(Clone, Debug, ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
1170+
#[derive(Clone, Debug, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
11721171
pub struct CamlPolyComm<CamlG> {
11731172
pub unshifted: Vec<CamlG>,
11741173
pub shifted: Option<CamlG>,
@@ -1228,7 +1227,7 @@ pub mod caml {
12281227

12291228
// opening proof
12301229

1231-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
1230+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
12321231
pub struct CamlOpeningProof<G, F> {
12331232
pub lr: Vec<(G, G)>, // vector of rounds of L & R commitments
12341233
pub delta: G,

dlog/plonk-15-wires/src/prover.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,9 @@ where
682682
pub mod caml {
683683
use super::*;
684684
use commitment_dlog::commitment::caml::{CamlOpeningProof, CamlPolyComm};
685-
use ocaml_gen::OcamlGen;
686685
use plonk_15_wires_circuits::nolookup::scalars::caml::CamlProofEvaluations;
687686

688-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
687+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
689688
pub struct CamlProverProof<CamlG, CamlF> {
690689
pub commitments: CamlProverCommitments<CamlG>,
691690
pub proof: CamlOpeningProof<CamlG, CamlF>,
@@ -696,7 +695,7 @@ pub mod caml {
696695
pub prev_challenges: Vec<(Vec<CamlF>, CamlPolyComm<CamlG>)>,
697696
}
698697

699-
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
698+
#[derive(Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
700699
pub struct CamlProverCommitments<CamlG> {
701700
// polynomial commitments
702701
pub w_comm: (

dlog/plonk/src/prover.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,15 @@ where
434434
pub mod caml {
435435
use super::*;
436436
use commitment_dlog::commitment::caml::{CamlOpeningProof, CamlPolyComm};
437-
use ocaml_gen::OcamlGen;
437+
use ocaml_gen::Struct;
438438
use plonk_circuits::scalars::caml::CamlProofEvaluations;
439439

440440
//
441441
// CamlProverCommitments<CamlG> <-> ProverCommitments<G>
442442
//
443443

444444
/// The ocaml type for ProverCommitments
445-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
445+
#[derive(ocaml::IntoValue, ocaml::FromValue, Struct)]
446446
pub struct CamlProverCommitments<CamlG> {
447447
pub l_comm: CamlPolyComm<CamlG>,
448448
pub r_comm: CamlPolyComm<CamlG>,
@@ -487,7 +487,7 @@ pub mod caml {
487487
// ProverProof<G> <-> CamlProverProof<CamlG, CamlF>
488488
//
489489

490-
#[derive(ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
490+
#[derive(ocaml::IntoValue, ocaml::FromValue, Struct)]
491491
pub struct CamlProverProof<CamlG, CamlF> {
492492
pub commitments: CamlProverCommitments<CamlG>,
493493
pub proof: CamlOpeningProof<CamlG, CamlF>,

ocaml/ocaml-gen/README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -49,44 +49,44 @@ decl_module!(w, env, "ImportantType", {
4949
To allow the previous example to work, you must derive the correct functions on your types and functions.
5050
To do that, you can use the [ocaml-derive](./derive) crate.
5151

52-
To allow generation of bindings on structs, use [OCamlGen]():
52+
To allow generation of bindings on structs, use [Struct]():
5353

5454
```rust
55-
use ocaml_gen::OcamlGen;
55+
use ocaml_gen::Struct;
5656

57-
#[OcamlGen]
57+
#[Struct]
5858
struct MyType {
5959
// ...
6060
}
6161
```
6262

63-
To allow generation of bindings on enums, use [OcamlEnum]():
63+
To allow generation of bindings on enums, use [ocaml_gen::Enum]():
6464

6565
```rust
66-
use ocaml_gen::OcamlEnum;
66+
use ocaml_gen::Enum;
6767

68-
#[OcamlEnum]
68+
#[Enum]
6969
enum MyType {
7070
// ...
7171
}
7272
```
7373

74-
To allow generation of bindings on functions, use [ocaml_gen]():
74+
To allow generation of bindings on functions, use [ocaml_gen::func]():
7575

7676
```rust
77-
#[ocaml_gen]
77+
#[ocaml_gen::func]
7878
#[ocaml::func] // if you use the crate ocaml-rs' macro, it must appear after
7979
pub fn your_function(arg1: String) {
8080
//...
8181
}
8282
```
8383

84-
To allow generation of bindings on custom types, use [OCamlCustomType]():
84+
To allow generation of bindings on custom types, use [ocaml_gen::CustomType]():
8585

8686
```rust
87-
use ocaml_gen::OCamlCustomType;
87+
use ocaml_gen::CustomType;
8888

89-
#[OCamlCustomType]
89+
#[CustomType]
9090
struct MyCustomType {
9191
// ...
9292
}

ocaml/ocaml-gen/derive/src/lib.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ use syn::{
1919
/// For example:
2020
///
2121
/// ```
22-
/// #[ocaml_gen]
22+
/// #[ocaml_gen::func]
2323
/// #[ocaml::func]
2424
/// pub fn something(arg1: String) {
2525
/// //...
2626
/// }
2727
/// ```
2828
///
2929
#[proc_macro_attribute]
30-
pub fn ocaml_gen(_attribute: TokenStream, item: TokenStream) -> TokenStream {
30+
pub fn func(_attribute: TokenStream, item: TokenStream) -> TokenStream {
3131
let item_fn: syn::ItemFn = syn::parse(item).unwrap();
3232

3333
let rust_name = &item_fn.sig.ident;
@@ -94,27 +94,26 @@ pub fn ocaml_gen(_attribute: TokenStream, item: TokenStream) -> TokenStream {
9494
}
9595

9696
//
97-
// OcamlEnum
97+
// Enum
9898
//
9999

100-
/// The OcamlEnum derive macro.
100+
/// The Enum derive macro.
101101
/// It generates implementations of ToOCaml and OCamlBinding on an enum type.
102102
/// The type must implement [ocaml::IntoValue] and [ocaml::FromValue]
103103
/// For example:
104104
///
105105
/// ```
106-
/// use ocaml_gen::OcamlEnum;
106+
/// use ocaml_gen::Enum;
107107
///
108-
/// #[OcamlEnum]
108+
/// #[Enum]
109109
/// enum MyType {
110110
/// // ...
111111
/// }
112112
/// ```
113113
///
114-
#[proc_macro_derive(OcamlEnum)]
114+
#[proc_macro_derive(Enum)]
115115
pub fn derive_ocaml_enum(item: TokenStream) -> TokenStream {
116-
let item_enum: syn::ItemEnum =
117-
syn::parse(item).expect("only enum are supported with OcamlEnum");
116+
let item_enum: syn::ItemEnum = syn::parse(item).expect("only enum are supported with Enum");
118117

119118
//
120119
// ocaml_desc
@@ -346,27 +345,25 @@ pub fn derive_ocaml_enum(item: TokenStream) -> TokenStream {
346345
}
347346

348347
//
349-
// OcamlGen
348+
// Struct
350349
//
351350

352-
/// The OcamlGen derive macro.
351+
/// The Struct derive macro.
353352
/// It generates implementations of ToOCaml and OCamlBinding on a struct.
354353
/// The type must implement [ocaml::IntoValue] and [ocaml::FromValue]
355354
/// For example:
356355
///
357356
/// ```
358-
/// use ocaml_gen::OcamlGen;
359-
///
360-
/// #[OcamlGen]
357+
/// #[ocaml_gen::Struct]
361358
/// struct MyType {
362359
/// // ...
363360
/// }
364361
/// ```
365362
///
366-
#[proc_macro_derive(OcamlGen)]
363+
#[proc_macro_derive(Struct)]
367364
pub fn derive_ocaml_gen(item: TokenStream) -> TokenStream {
368365
let item_struct: syn::ItemStruct =
369-
syn::parse(item).expect("only structs are supported with OCamlGen");
366+
syn::parse(item).expect("only structs are supported with Struct");
370367
let name = &item_struct.ident;
371368
let generics = &item_struct.generics.params;
372369
let fields = &item_struct.fields;
@@ -624,15 +621,15 @@ pub fn derive_ocaml_gen(item: TokenStream) -> TokenStream {
624621
/// For example:
625622
///
626623
/// ```
627-
/// use ocaml_gen::OCamlCustomType;
624+
/// use ocaml_gen::CustomType;
628625
///
629-
/// #[OCamlCustomType]
626+
/// #[CustomType]
630627
/// struct MyCustomType {
631628
/// // ...
632629
/// }
633630
/// ```
634631
///
635-
#[proc_macro_derive(OCamlCustomType)]
632+
#[proc_macro_derive(CustomType)]
636633
pub fn derive_ocaml_custom(item: TokenStream) -> TokenStream {
637634
let item_struct: syn::ItemStruct =
638635
syn::parse(item).expect("only structs are supported at the moment");

ocaml/ocaml-gen/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ impl Env {
118118
//
119119

120120
/// OCamlBinding is the trait implemented by types to generate their OCaml bindings.
121-
/// It is usually derived automatically via the [OcamlGen] macro,
122-
/// or the [OCamlCustomType] macro for custom types.
123-
/// For functions, refer to the [ocaml_gen] macro.
121+
/// It is usually derived automatically via the [Struct] macro,
122+
/// or the [CustomType] macro for custom types.
123+
/// For functions, refer to the [func] macro.
124124
pub trait OCamlBinding {
125125
/// will generate the OCaml bindings for a type (called root type).
126126
/// It takes the current environment [Env],
@@ -129,8 +129,8 @@ pub trait OCamlBinding {
129129
}
130130

131131
/// OCamlDesc is the trait implemented by types to facilitate generation of their OCaml bindings.
132-
/// It is usually derived automatically via the [OcamlGen] macro,
133-
/// or the [OCamlCustomType] macro for custom types.
132+
/// It is usually derived automatically via the [Struct] macro,
133+
/// or the [CustomType] macro for custom types.
134134
pub trait OCamlDesc {
135135
/// describes the type in OCaml, given the current environment [Env]
136136
/// and the list of generic type parameters of the root type

ocaml/tests/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::OcamlGen)]
1+
#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
22
pub struct SingleTuple(String);
33

4-
#[ocaml_gen::ocaml_gen]
4+
#[ocaml_gen::func]
55
#[ocaml::func]
66
pub fn new() -> SingleTuple {
77
SingleTuple(String::from("Hello"))
88
}
99

10-
#[ocaml_gen::ocaml_gen]
10+
#[ocaml_gen::func]
1111
#[ocaml::func]
1212
pub fn print(s: SingleTuple) {
1313
println!("{}", s.0);

oracle/src/sponge.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,12 @@ where
215215
#[cfg(feature = "ocaml_types")]
216216
pub mod caml {
217217
use super::*;
218-
use ocaml_gen::OcamlGen;
219218

220219
//
221220
// ScalarChallenge<F> <-> CamlScalarChallenge<CamlF>
222221
//
223222

224-
#[derive(Debug, Clone, ocaml::IntoValue, ocaml::FromValue, OcamlGen)]
223+
#[derive(Debug, Clone, ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
225224
pub struct CamlScalarChallenge<CamlF>(pub CamlF);
226225

227226
impl<F, CamlF> From<ScalarChallenge<F>> for CamlScalarChallenge<CamlF>

0 commit comments

Comments
 (0)