mirage/ocaml-cstruct

make to/of_string functions (%%cenum) optional

Closed this issue · 2 comments

The definition:

[%%cenum
type foo64 =
  | ONE64
  | TWO64
  | THREE64
  [@@uint64_t]
]

currently generates

int_to_foo64 : int -> foo64 option
foo64_to_int : foo64 -> int
foo64_to_string : foo64 -> string
string_to_foo64 : string -> foo64 option

Where often only the int_to_foo64/foo64_to_int are used. Can we introduce a [@@string] to provide these conversions? Doing so reduces the binary size drastically (since there don't need to be the literal strings anymore).

There is already a [@@sexp], which emits two more functions:

foo64_of_sexp : foo64 -> Sexplib.Sexp.t
sexp_of_foo64 : Sexplib.Sexp.t -> foo64

And depends on the string functionality (thus, [@@sexp] should imply [@@string]).

avsm commented

This should be fixed by the DCO patch to the compiler...

I will close this issue -- there's no activity since 4 years, and I simply removed all my uses of ppx_cstruct due to code size and dependency cone (and don't recommend it's usage).