···11+## v0.11
22+33+- Depend on ppxlib instead of (now deprecated) ppx\_core, ppx\_driver and
44+ ppx\_metaquot.
55+66+## v0.10
77+88+- Added new `[@@deriving sexp]` record-field attribute, `[@sexp.omit_nil]`, for
99+ a field that is omitted if its sexp representation is `()`.
1010+1111+- Improved `[%sexp_of: 'a]` and `[%of_sexp: 'a]` to not expose variable names
1212+ intended for internal use.
1313+1414+## v0.9
1515+1616+## 113.43.00
1717+1818+- Fix generator for polymorphic types where var names clashes with type name: `type 't t = ...`
1919+2020+## 113.33.00
2121+2222+- Clean up the documentation for sexplib, modernizing it to include
2323+ `ppx_sexp_conv`, and breaking up the documentation between sexplib and
2424+ `ppx_sexp_conv`. Also changed the formatting to use org-mode, so it
2525+ will render properly on github. Markdown doesn't render well by
2626+ default, unless you use quite different conventions about linebeaks.
2727+2828+## 113.24.00
2929+3030+- Trying to improve the tests in ppx\_sexp\_conv because they are a mess.
3131+ At least all tests are automatic now. And more things are tested like
3232+ the sexpification of exceptions.
3333+3434+- Update to follow `Type_conv` and `Ppx_core` evolution.
3535+3636+- Make ppx\_sexp\_conv correctly handle aliases to polymorphic variants:
3737+3838+ type t = ` `A ` `@@deriving sexp`
3939+ type u = t `@@deriving sexp`
4040+ type v = ` u | `B ` `@@deriving sexp`
4141+4242+ Before, `v_of_sexp` would never manage to read `B. This problem is
4343+ now fixed if you use `sexp_poly` on `u` instead of `sexp`, and if you
4444+ don't, you get an "unbound value __u_of_sexp__". People should use
4545+ `sexp_poly` when they have a polymorphic variant type that is not
4646+ syntactically a polymorphic variant, but in practice it's simpler to
4747+ replace `sexp` by `sexp_poly` when faced with the error above.
4848+4949+ The need for `sexp_poly` should happen only in one new case: an
5050+ implementation says `type u = t `@@deriving sexp`` but the interface
5151+ says `type u = ``A` `@@deriving sexp``. (the old case where it was
5252+ already needed is when you have an interface that says `type u = t
5353+ `@@deriving sexp`` and in some other implementation you try to say
5454+ `type t = ` That_module.t | `A ` `@@deriving sexp``).
+67
vendor/opam/ppx_sexp_conv/CONTRIBUTING.md
···11+This repository contains open source software that is developed and
22+maintained by [Jane Street][js].
33+44+Contributions to this project are welcome and should be submitted via
55+GitHub pull requests.
66+77+Signing contributions
88+---------------------
99+1010+We require that you sign your contributions. Your signature certifies
1111+that you wrote the patch or otherwise have the right to pass it on as
1212+an open-source patch. The rules are pretty simple: if you can certify
1313+the below (from [developercertificate.org][dco]):
1414+1515+```
1616+Developer Certificate of Origin
1717+Version 1.1
1818+1919+Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
2020+1 Letterman Drive
2121+Suite D4700
2222+San Francisco, CA, 94129
2323+2424+Everyone is permitted to copy and distribute verbatim copies of this
2525+license document, but changing it is not allowed.
2626+2727+2828+Developer's Certificate of Origin 1.1
2929+3030+By making a contribution to this project, I certify that:
3131+3232+(a) The contribution was created in whole or in part by me and I
3333+ have the right to submit it under the open source license
3434+ indicated in the file; or
3535+3636+(b) The contribution is based upon previous work that, to the best
3737+ of my knowledge, is covered under an appropriate open source
3838+ license and I have the right under that license to submit that
3939+ work with modifications, whether created in whole or in part
4040+ by me, under the same open source license (unless I am
4141+ permitted to submit under a different license), as indicated
4242+ in the file; or
4343+4444+(c) The contribution was provided directly to me by some other
4545+ person who certified (a), (b) or (c) and I have not modified
4646+ it.
4747+4848+(d) I understand and agree that this project and the contribution
4949+ are public and that a record of the contribution (including all
5050+ personal information I submit with it, including my sign-off) is
5151+ maintained indefinitely and may be redistributed consistent with
5252+ this project or the open source license(s) involved.
5353+```
5454+5555+Then you just add a line to every git commit message:
5656+5757+```
5858+Signed-off-by: Joe Smith <joe.smith@email.com>
5959+```
6060+6161+Use your real name (sorry, no pseudonyms or anonymous contributions.)
6262+6363+If you set your `user.name` and `user.email` git configs, you can sign
6464+your commit automatically with git commit -s.
6565+6666+[dco]: http://developercertificate.org/
6767+[js]: https://opensource.janestreet.com/
+21
vendor/opam/ppx_sexp_conv/LICENSE.md
···11+The MIT License
22+33+Copyright (c) 2015--2025 Jane Street Group, LLC <opensource-contacts@janestreet.com>
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
···11+#+TITLE: ppx_sexp_conv
22+33+* [@@deriving sexp]
44+55+=ppx_sexp_conv= is a PPX syntax extension that generates code for
66+converting OCaml types to and from s-expressions, as defined in the
77+[[https://github.com/janestreet/sexplib][=sexplib=]] library. S-expressions are defined by the following type:
88+99+#+begin_src ocaml
1010+type sexp = Atom of string | List of sexp list
1111+#+end_src
1212+1313+and are rendered as parenthesized lists of strings, /e.g./ =(This (is
1414+an) (s expression))=.
1515+1616+=ppx_sexp_conv= fits into the [[https://github.com/whitequark/ppx_deriving][=ppx_deriving=]] framework, so you can
1717+invoke it the same way you invoke any other deriving plug-in. Thus,
1818+we can write
1919+2020+#+begin_src ocaml
2121+type int_pair = (int * int) [@@deriving sexp]
2222+#+end_src
2323+2424+to get two values defined automatically, =sexp_of_int_pair= and
2525+=int_pair_of_sexp=. If we only want one direction, we can write one
2626+of the following.
2727+2828+#+begin_src ocaml
2929+type int_pair = (int * int) [@@deriving sexp_of]
3030+type int_pair = (int * int) [@@deriving of_sexp]
3131+#+end_src
3232+3333+These sexp-converters depend on having a set of converters for basic
3434+values (/e.g./, =int_of_sexp=) already in scope. This can be done by
3535+writing:
3636+3737+#+begin_src ocaml
3838+open Sexplib.Std
3939+#+end_src
4040+4141+If you're using [[https://github.com/janestreet/core][=Core=]], you can get the same effect with =open Core=.
4242+4343+It's also possible to construct converters based on type expressions,
4444+/i.e./:
4545+4646+#+begin_src ocaml
4747+ [%sexp_of: (int * string) list] [1,"one"; 2,"two"]
4848+ |> Sexp.to_string;;
4949+ => "((1 one) (2 two))"
5050+5151+ [%sexp_of: (int * string) list] [1,"one"; 2,"two"]
5252+ |> [%of_sexp: (int * string) list];;
5353+ => [1,"one"; 2,"two"]
5454+#+end_src
5555+5656+For =%sexp_of=, we can also omit the conversion of some types by
5757+putting underscores for that type name.
5858+5959+#+begin_src ocaml
6060+ [%sexp_of: (int * _) list] [1,"one"; 2,"two"]
6161+ |> Sexp.to_string;;
6262+ => "((1 _)(2 _))"
6363+#+end_src
6464+6565+Converters for the implicit unboxed version of a record can be derived with the =~unboxed=
6666+flag. For example,
6767+6868+#+begin_src ocaml
6969+ type t = { x : int } [@@deriving sexp ~unboxed]
7070+#+end_src
7171+7272+will give us =sexp_of_t= and =t_of_sexp=, as expected, along with
7373+=t_u_of_sexp : sexp -> t#= and =sexp_of_t_u : t# -> sexp=.
7474+7575+* [@@deriving sexp_grammar]
7676+7777+If =ppx_sexp_conv= can derive =of_sexp=, it can also generate a description of
7878+the sexps that the resulting =t_of_sexp= would accept. This is the sexp grammar.
7979+See =Sexplib0.Sexp_grammar= for details. Use =[@@deriving sexp_grammar]= to derive
8080+the grammar for a type.
8181+8282+It is possible to construct sexp grammars directly from type expressions, e.g.,
8383+8484+#+BEGIN_SRC ocaml
8585+[%sexp_grammar: (int, bool array) Either.t Base.Map.M(String).t]
8686+#+END_SRC
8787+8888+** Tagging grammars
8989+9090+Use =[@sexp_grammar.tag key = value]=, where =(key : string)= and =(value :
9191+Sexp.t)=, to annotate a grammar with a tag that can be inspected at runtime.
9292+9393+** Custom grammars
9494+9595+Use =[@sexp_grammar.custom grammar]= to override a type's sexp grammar with
9696+=grammar=.
9797+9898+** Stub grammars
9999+100100+Annotate a type with =[@sexp_grammar.any]= to use a stub grammar that accepts
101101+any sexp. Alternately, write =[@sexp_grammar.any desc]= where =(desc : string)=
102102+to use =desc= as a human-readable description for the stub grammar.
103103+104104+* Conversion rules
105105+106106+In the following, we'll review the serialization rules for different
107107+OCaml types.
108108+109109+** Basic types
110110+111111+Basic types are represented as atoms. For numbers like =int=,
112112+=int32=, =int64=, =float=, the string in the atom is what is accepted
113113+the standard ocaml functions =int_of_string=, =Int32.of_string=, etc.
114114+For the types =char= or =string=, the string in the atom is
115115+respectively a one character string or the string itself.
116116+117117+** Lists and arrays
118118+119119+OCaml-lists and arrays are represented as s-expression lists.
120120+121121+** Tuples and unit
122122+123123+OCaml tuples are treated as lists of values in the same order as in
124124+the tuple. The type =unit= is treated like a 0-tuple. /e.g./:
125125+126126+#+begin_src ocaml
127127+ (3.14, "foo", "bar bla", 27) => (3.14 foo "bar bla" 27)
128128+#+end_src
129129+130130+** Options
131131+132132+With options, =None= is treated as a zero-element list, and =Some= is
133133+treated as a singleton list, as shown below.
134134+135135+#+begin_src ocaml
136136+None => ()
137137+Some value => (value)
138138+#+end_src
139139+140140+We also support reading options following the ordinary rules for
141141+variants /i.e./:
142142+143143+#+begin_src ocaml
144144+None => None
145145+Some value => (Some value)
146146+#+end_src
147147+148148+The rules for variants are described below.
149149+150150+** Records
151151+152152+Records are represented as lists of lists, where each inner list is a
153153+key-value pair. Each pair consists of the name of the record field
154154+(first element), and its value (second element). /e.g./:
155155+156156+#+begin_src ocaml
157157+ { foo = (3,4);
158158+ bar = "some string"; }
159159+ => ((foo (3 4)) (bar "some string"))
160160+#+end_src
161161+162162+Type specifications of records allow the use of several attributes. The
163163+attribute =sexp.option= indicates that an =option= record field should be optional, while
164164+the attribute =sexp.or_null= indicates that an =or_null= record field should be optional.
165165+/e.g./:
166166+167167+#+begin_src ocaml
168168+ type t =
169169+ { x : int option;
170170+ y : int option [@sexp.option];
171171+ z : int or_null [@sexp.or_null];
172172+ } [@@deriving sexp]
173173+#+end_src
174174+175175+The following examples show how this works.
176176+177177+#+begin_src ocaml
178178+ { x = Some 1; y = Some 2; } => ((x (1)) (y 2))
179179+ { x = None ; y = None; } => ((x ()))
180180+#+end_src
181181+182182+Note that, when present, an optional value is represented as the bare
183183+value, rather than explicitly as an option.
184184+185185+The attribute =sexp.bool= indicates that a boolean record field is shown
186186+as either present or absent, but not as containing a value.
187187+188188+#+begin_src ocaml
189189+ type t = { enabled : bool [@sexp.bool] } [@@deriving sexp]
190190+191191+ { enabled = true } => ((enabled))
192192+ { enabled = false } => ()
193193+#+end_src
194194+195195+The attributes =sexp.list= and =sexp.array= indicate that a list or array record
196196+field, respectively, can be omitted when it is empty.
197197+198198+#+begin_src ocaml
199199+ type t =
200200+ { arr : int array [@sexp.array]
201201+ ; lst : int list [@sexp.list]
202202+ }
203203+ [@@deriving sexp]
204204+205205+ { arr = [||]; lst = [] } => ()
206206+ { arr = [|1;2|]; lst = [3;4] } => ((arr (1 2)) (lst (3 4)))
207207+#+end_src
208208+209209+*** Defaults
210210+211211+More complex default values can be specified explicitly using several
212212+constructs, /e.g./:
213213+214214+#+begin_src ocaml
215215+ type t =
216216+ { a : int [@default 42];
217217+ b : int [@default 3] [@sexp_drop_default (=)];
218218+ c : int [@default 3] [@sexp_drop_if fun x -> x = 3];
219219+ d : int Queue.t [@sexp.omit_nil]
220220+ } [@@deriving sexp]
221221+#+end_src
222222+223223+The =@default= annotation lets one specify a default value to be
224224+selected if the field is not specified, when converting from an
225225+s-expression. The =@sexp_drop_default= annotation implies that the
226226+field will be dropped when generating the s-expression if the value
227227+being serialized is equal to the default according to the specified equality
228228+function. =@sexp_drop_if= is like =@sexp_drop_default=, except that
229229+it lets you specify the condition under which the field is dropped.
230230+Finally, =@sexp.omit_nil= means to treat a missing field as if it
231231+has value =List []= when reading, and drop the field if it has value
232232+=List []= when writing.
233233+234234+**** Specifying equality for [@sexp_drop_default]
235235+236236+The equality used by [@sexp_drop_default] is customizable. There
237237+are several ways to specify the equality function:
238238+239239+#+begin_src ocaml
240240+ type t =
241241+ { a : u [@default u0] [@sexp_drop_default (=)]; (* explicit user-provided function *)
242242+ b : u [@default u0] [@sexp_drop_default.compare]; (* uses [%compare.equal: u] *)
243243+ c : u [@default u0] [@sexp_drop_default.equal]; (* uses [%equal: u] *)
244244+ d : u [@default u0] [@sexp_drop_default.sexp]; (* compares sexp representations *)
245245+ e : u [@default u0] [@sexp_drop_default]; (* deprecated. uses polymorphic equality. *)
246246+ } [@@deriving sexp]
247247+#+end_src
248248+249249+*** Allowing extra fields
250250+251251+The =@sexp.allow_extra_fields= annotation lets one specify that the
252252+sexp-converters should silently ignore extra fields, instead of
253253+raising. This applies only to the record to which the annotation is
254254+attached, and not to deeper sexp converters that may be called during
255255+conversion of a sexp to the record.
256256+257257+#+begin_src ocaml
258258+ type t = { a: int } [@@deriving sexp]
259259+ ((a 0)(b b)) => exception
260260+261261+ type t = { a: int } [@@deriving sexp] [@@sexp.allow_extra_fields]
262262+ ((a 0)(b b)) => {a = 0}
263263+264264+ type t = A of { a : int } [@sexp.allow_extra_fields] [@@deriving sexp]
265265+ (A (a 0)(b b)) => A {a = 0}
266266+#+end_src
267267+268268+** Variants
269269+270270+Constant constructors in variants are represented as
271271+strings. Constructors with arguments are represented as lists, the
272272+first element being the constructor name, the rest being its
273273+arguments. Constructors may also be started in lowercase in
274274+S-expressions, but will always be converted to uppercase when
275275+converting from OCaml values.
276276+277277+For example:
278278+279279+#+begin_src ocaml
280280+ type t = A | B of int * float * t [@@deriving sexp]
281281+ B (42, 3.14, B (-1, 2.72, A)) => (B 42 3.14 (B -1 2.72 A))
282282+#+end_src
283283+284284+The above example also demonstrates recursion in data structures.
285285+286286+Variants support the attribute =sexp.list= when a clause has a single
287287+list as its argument.
288288+289289+#+begin_src ocaml
290290+ type t =
291291+ | A of int list
292292+ | B of int list [@sexp.list]
293293+294294+ A [1; 2; 3] => (A (1 2 3))
295295+ B [1; 2; 3] => (B 1 2 3)
296296+#+end_src
297297+298298+*** Inline records
299299+300300+Constructors with inline records are represented as lists, the first element
301301+being the constructor name, the rest being the record fields, represented the
302302+same way as in record types, but without being wrapped in an extra layer of
303303+parentheses.
304304+305305+#+begin_src ocaml
306306+ type t = A of { x : int }
307307+308308+ A { x = 8 } => (A (x 8))
309309+#+end_src
310310+311311+** Polymorphic variants
312312+313313+Polymorphic variants behave almost the same as ordinary variants. The
314314+notable difference is that polymorphic variant constructors must
315315+always start with an either lower- or uppercase character, matching
316316+the way it was specified in the type definition. This is because
317317+OCaml distinguishes between upper and lowercase variant
318318+constructors. Note that type specifications containing unions of
319319+variant types are also supported by the S-expression converter, for
320320+example as in:
321321+322322+#+begin_src ocaml
323323+ type ab = [ `A | `B ] [@@deriving sexp]
324324+ type cd = [ `C | `D ] [@@deriving sexp]
325325+ type abcd = [ ab | cd ] [@@deriving sexp]
326326+#+end_src
327327+328328+However, because `ppx_sexp_conv` needs to generate additional code to
329329+support inclusions of polymorphic variants, `ppx_sexp_conv` needs to
330330+know when processing a type definition whether it might be included in
331331+a polymorphic variant. `ppx_sexp_conv` will only generate the extra
332332+code automatically in the common case where the type definition is
333333+syntactically a polymorphic variant like in the example
334334+above. Otherwise, you will need to indicate it by using `[@@deriving
335335+sexp_poly]` (resp `of_sexp_poly`) instead of `[@@deriving sexp]` (resp
336336+`of_sexp`):
337337+338338+#+begin_src ocaml
339339+ type ab = [ `A | `B ] [@@deriving sexp]
340340+ type alias_of_ab = ab [@@deriving sexp_poly]
341341+ type abcd = [ ab | `C | `D ] [@@deriving sexp]
342342+#+end_src
343343+344344+** Polymorphic values
345345+346346+There is nothing special about polymorphic values as long as there are
347347+conversion functions for the type parameters. /e.g./:
348348+349349+#+begin_src ocaml
350350+type 'a t = A | B of 'a [@@deriving sexp]
351351+type foo = int t [@@deriving sexp]
352352+#+end_src
353353+354354+In the above case the conversion functions will behave as if =foo= had
355355+been defined as a monomorphic version of =t= with ='a= replaced by
356356+=int= on the right hand side.
357357+358358+If a data structure is indeed polymorphic and you want to convert it,
359359+you will have to supply the conversion functions for the type
360360+parameters at runtime. If you wanted to convert a value of type ='a
361361+t= as in the above example, you would have to write something like
362362+this:
363363+364364+#+begin_src ocaml
365365+ sexp_of_t sexp_of_a v
366366+#+end_src
367367+368368+where =sexp_of_a=, which may also be named differently in this
369369+particular case, is a function that converts values of type ='a= to an
370370+S-expression. Types with more than one parameter require passing
371371+conversion functions for those parameters in the order of their
372372+appearance on the left hand side of the type definition.
373373+374374+** Opaque values
375375+376376+Opaque values are ones for which we do not want to perform
377377+conversions. This may be, because we do not have S-expression
378378+converters for them, or because we do not want to apply them in a
379379+particular type context. /e.g./ to hide large, unimportant parts of
380380+configurations. To prevent the preprocessor from generating calls to
381381+converters, simply apply the attribute =sexp.opaque= to the type. If the type
382382+is for a record field, it will likely need parentheses to avoid applying the
383383+attribute to the record field itself, /e.g./:
384384+385385+#+begin_src ocaml
386386+ type foo = int * (stuff [@sexp.opaque]) [@@deriving sexp]
387387+388388+ type bar =
389389+ { a : int
390390+ ; b : (stuff [@sexp.opaque])
391391+ }
392392+ [@@deriving sexp]
393393+#+end_src
394394+395395+Thus, there is no need to specify converters for type =stuff=, and if
396396+there are any, they will not be used in this particular context.
397397+Needless to say, it is not possible to convert such an S-expression
398398+back to the original value. Here is an example conversion:
399399+400400+#+begin_src ocaml
401401+ (42, some_stuff) => (42 <opaque>)
402402+#+end_src
403403+404404+** Phantom parameters
405405+406406+Phantom type parameters are ones which are marked to not actually appear on the
407407+right-hand side of the type definition, and are thus excluded from the derived
408408+=sexp_of= and =of_sexp= combinators. To prevent the preprocessor from including
409409+type parameters when deriving or calling combinators, add the attribute
410410+=sexp.phantom= to the type parameter itself. Here is an example:
411411+412412+#+begin_src ocaml
413413+ type ('a[@sexp.phantom], 'b) index = 'b
414414+ [@@deriving sexp]
415415+416416+ type 'a[@sexp.phantom] int_index = ('a[@sexp.phantom], int) index
417417+ [@@deriving sexp]
418418+#+end_src
419419+420420+The derived functions will have the following types. Note that none of them take
421421+a combinator for the phantom parameter as an argument.
422422+423423+#+begin_src ocaml
424424+val sexp_of_index : ('b -> Sexp.t) -> ('a, 'b) index -> Sexp.t
425425+val index_of_sexp : (Sexp.t -> 'b) -> Sexp.t -> ('a, 'b) index
426426+427427+val sexp_of_int_index : 'a int_index -> Sexp.t
428428+val int_index_of_sexp : Sexp.t -> 'a int_index
429429+#+end_src
430430+431431+** Exceptions
432432+433433+S-expression converters for exceptions can be automatically
434434+registered.
435435+436436+#+begin_src ocaml
437437+ module M = struct
438438+ exception Foo of int [@@deriving sexp]
439439+ end
440440+#+end_src
441441+442442+Such exceptions will be translated in a similar way as sum types, but
443443+their constructor will be prefixed with the fully qualified module
444444+path (here: =M.Foo=) so as to be able to discriminate between them
445445+without problems.
446446+447447+The user can then easily convert an exception matching the above one
448448+to an S-expression using =sexp_of_exn=. User-defined conversion
449449+functions can be registered, too, by calling =add_exn_converter=.
450450+This should make it very convenient for users to catch arbitrary
451451+exceptions escaping their program and pretty-printing them, including
452452+all arguments, as S-expressions. The library already contains
453453+mappings for all known exceptions that can escape functions in the
454454+OCaml standard library.
455455+456456+** Hash tables
457457+458458+The Stdlib's Hash tables, which are abstract values in OCaml, are
459459+represented as association lists, /i.e./ lists of key-value pairs,
460460+/e.g./:
461461+462462+#+begin_src scheme
463463+ ((foo 42) (bar 3))
464464+#+end_src
465465+466466+Reading in the above S-expression as hash table mapping strings to
467467+integers (=(string, int) Hashtbl.t=) will map =foo= to =42= and =bar=
468468+to =3=.
469469+470470+Note that the order of elements in the list may matter, because the
471471+OCaml-implementation of hash tables keeps duplicates. Bindings will
472472+be inserted into the hash table in the order of appearance. Therefore,
473473+the last binding of a key will be the "visible" one, the others are
474474+"hidden". See the OCaml documentation on hash tables for details.
475475+476476+* A note about signatures
477477+478478+In signatures, =ppx_sexp_conv= tries to generate an include of a named
479479+interface, instead of a list of value bindings.
480480+That is:
481481+482482+#+begin_src ocaml
483483+type 'a t [@@deriving sexp]
484484+#+end_src
485485+486486+will generate:
487487+488488+#+begin_src ocaml
489489+include Sexpable.S1 with type 'a t := 'a t
490490+#+end_src
491491+492492+instead of:
493493+494494+#+begin_src ocaml
495495+val t_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a t
496496+val sexp_of_t : ('a -> Sexp.t) -> 'a t -> Sexp.t
497497+#+end_src
498498+499499+There are however a number of limitations:
500500+- the type has to be named t
501501+- the type can only have up to 3 parameters
502502+- there shouldn't be any constraint on the type parameters
503503+504504+If these aren't met, then =ppx_sexp_conv= will simply generate a list of value
505505+bindings.
506506+507507+** Weird looking type errors
508508+509509+In some cases, a type can meet all the conditions listed above, in which case the
510510+rewriting will apply, but lead to a type error. This happens when the type [t]
511511+is an alias to a type which does have constraints on the parameters, for
512512+instance:
513513+514514+#+begin_src ocaml
515515+type 'a s constraint 'a = [> `read ]
516516+val sexp_of_s : ...
517517+val s_of_sexp : ...
518518+type 'a t = 'a s [@@deriving_inline sexp]
519519+include Sexpable.S1 with type 'a t := 'a t
520520+[@@@end]
521521+#+end_src
522522+523523+will give an error looking like:
524524+525525+#+begin_src
526526+Error: In this `with' constraint, the new definition of t
527527+ does not match its original definition in the constrained signature:
528528+ Type declarations do not match:
529529+ type 'a t = 'a t constraint 'a = [> `read ]
530530+ is not included in
531531+ type 'a t
532532+ File "sexpable.mli", line 8, characters 21-58: Expected declaration
533533+ Their constraints differ.
534534+#+end_src
535535+536536+To workaround that error, simply copy the constraint on the type which has the
537537+=[@@deriving]= annotation. This will force generating a list of value bindings.
538538+539539+* Deprecated syntax
540540+541541+Originally, ~ppx_sexp_conv~ used special types instead of attributes. Those
542542+types have been replaced with attributes. Here are the appropriate conversions
543543+to update from code using the old types to the new attributes.
544544+545545+546546+** Opaque types
547547+548548+Convert uses of ~sexp_opaque~ to uses of ~[@sexp.opaque]~. The ~[@sexp.opaque]~
549549+attribute usually needs explicit parentheses to clarify what type it annotate.
550550+551551+Before:
552552+553553+#+begin_src ocaml
554554+type t = int sexp_opaque list
555555+[@@deriving sexp]
556556+#+end_src
557557+558558+After:
559559+560560+#+begin_src ocaml
561561+type t = (int [@sexp.opaque]) list
562562+[@@deriving sexp]
563563+#+end_src
564564+565565+** Record fields
566566+567567+Convert uses of ~sexp_option~, ~sexp_list~, ~sexp_array~, and ~sexp_bool~ to
568568+uses of ~[@sexp.option]~, ~[@sexp.list]~, ~[@sexp.array]~, and ~[@sexp.bool]~ as
569569+appropriate. The attribute only specifies the modification, not the type, so you
570570+will need to use the regular types ~option~, ~list~, ~array~, and/or ~bool~ as
571571+well. Unlike ~[@sexp.opaque]~, these attributes do not need extra parentheses.
572572+573573+Before:
574574+575575+#+begin_src ocaml
576576+type t =
577577+ { a : int sexp_option
578578+ ; b : int sexp_list
579579+ ; c : int sexp_array
580580+ ; d : sexp_bool
581581+ }
582582+[@@deriving sexp]
583583+#+end_src
584584+585585+After:
586586+587587+#+begin_src ocaml
588588+type t =
589589+ { a : int option [@sexp.option]
590590+ ; b : int list [@sexp.list]
591591+ ; c : int array [@sexp.array]
592592+ ; d : bool [@sexp.bool]
593593+ }
594594+[@@deriving sexp]
595595+#+end_src
596596+597597+** Variant constructors
598598+599599+Convert uses of ~sexp_list~ in variants and polymorphic variants to uses of
600600+~[@sexp.list]~. You need to add the regular type ~list~ as well. Unlike
601601+~[@sexp.opaque]~, this attribute does not need extra parentheses.
602602+603603+Before:
604604+605605+#+begin_src ocaml
606606+type t = A of int sexp_list
607607+[@@deriving sexp]
608608+609609+type u = [`B of int sexp_list]
610610+[@@deriving sexp]
611611+#+end_src
612612+613613+After:
614614+615615+#+begin_src ocaml
616616+type t = A of int list [@sexp.list]
617617+[@@deriving sexp]
618618+619619+type u = [`B of int list [@sexp.list]]
620620+[@@deriving sexp]
621621+#+end_src
···11+open! Stdppx
22+open! Ppxlib
33+open Ast_builder.Default
44+open Helpers
55+66+let maybe_exclave ~loc expr ~stackify =
77+ match stackify with
88+ | false -> expr
99+ | true -> [%expr [%e expr]]
1010+;;
1111+1212+let maybe_constrain ~loc expr = function
1313+ | None -> expr
1414+ | Some cstr -> [%expr ([%e expr] : [%t cstr])]
1515+;;
1616+1717+module Reference = struct
1818+ type t =
1919+ { types : type_declaration list
2020+ ; binds : value_binding list list
2121+ ; ident : longident_loc
2222+ ; cstr : core_type option
2323+ ; args : (arg_label * expression) list
2424+ ; after_args : (arg_label * expression) list
2525+ }
2626+2727+ let bind t binds = { t with binds = binds :: t.binds }
2828+ let bind_types t types = { t with types = types @ t.types }
2929+3030+ let maybe_apply { types; binds; ident; cstr; args; after_args } ~loc maybe_arg =
3131+ let ident = pexp_ident ~loc ident in
3232+ let args =
3333+ match maybe_arg with
3434+ | None -> args @ after_args
3535+ | Some arg -> args @ [ Nolabel, arg ] @ after_args
3636+ in
3737+ let expr =
3838+ match args with
3939+ | [] -> maybe_constrain ~loc ident cstr
4040+ | _ -> pexp_apply ~loc ident args
4141+ in
4242+ with_types ~loc ~types (with_let ~loc ~binds expr)
4343+ ;;
4444+4545+ let apply t ~loc arg = maybe_apply t ~loc (Some arg)
4646+ let to_expression t ~loc = maybe_apply t ~loc None
4747+4848+ let to_value_expression t ~loc ~rec_flag ~values_being_defined ~stackify =
4949+ let may_refer_directly_to ident =
5050+ match rec_flag with
5151+ | Nonrecursive -> true
5252+ | Recursive -> not (String.Set.mem (Longident.name ident.txt) values_being_defined)
5353+ in
5454+ match t with
5555+ | { types = []; binds = []; ident; cstr; args = []; after_args = [] }
5656+ when may_refer_directly_to ident ->
5757+ maybe_constrain ~loc (pexp_ident ~loc ident) cstr
5858+ | _ -> fresh_lambda ~loc (fun ~arg -> maybe_exclave ~loc (apply t ~loc arg) ~stackify)
5959+ ;;
6060+end
6161+6262+module Lambda = struct
6363+ type t =
6464+ { types : type_declaration list
6565+ ; binds : value_binding list list
6666+ ; cases : cases
6767+ }
6868+6969+ let bind t binds = { t with binds = binds :: t.binds }
7070+ let bind_types t types = { t with types = types @ t.types }
7171+7272+ (* generic case: use [function] or [match] *)
7373+ let maybe_apply_generic ~loc ~types ~binds maybe_arg cases ~stackify =
7474+ let expr =
7575+ match maybe_arg with
7676+ | None ->
7777+ let cases =
7878+ List.map cases ~f:(fun case ->
7979+ { case with pc_rhs = maybe_exclave ~loc case.pc_rhs ~stackify })
8080+ in
8181+ pexp_function ~loc cases
8282+ | Some arg -> pexp_match ~loc arg cases
8383+ in
8484+ with_types ~loc ~types (with_let ~loc ~binds expr)
8585+ ;;
8686+8787+ (* zero cases: synthesize an "impossible" case, i.e. [| _ -> .] *)
8888+ let maybe_apply_impossible ~loc ~types ~binds maybe_arg ~stackify =
8989+ [ case ~lhs:(ppat_any ~loc) ~guard:None ~rhs:(pexp_unreachable ~loc) ]
9090+ |> maybe_apply_generic ~loc ~binds ~types maybe_arg ~stackify
9191+ ;;
9292+9393+ (* one case without guard: use [fun] or [let] *)
9494+ let maybe_apply_simple ~loc ~types ~binds maybe_arg pat body ~stackify =
9595+ let expr =
9696+ match maybe_arg with
9797+ | None -> pexp_fun ~loc Nolabel None pat (maybe_exclave ~loc body ~stackify)
9898+ | Some arg -> pexp_let ~loc Nonrecursive [ value_binding ~loc ~pat ~expr:arg ] body
9999+ in
100100+ with_types ~loc ~types (with_let ~loc ~binds expr)
101101+ ;;
102102+103103+ (* shared special-casing logic for [apply] and [to_expression] *)
104104+ let maybe_apply t ~loc maybe_arg ~stackify =
105105+ match t with
106106+ | { types; binds; cases = [] } ->
107107+ maybe_apply_impossible ~loc ~types ~binds maybe_arg ~stackify
108108+ | { types; binds; cases = [ { pc_lhs; pc_guard = None; pc_rhs } ] } ->
109109+ maybe_apply_simple ~loc ~types ~binds maybe_arg pc_lhs pc_rhs ~stackify
110110+ | { types; binds; cases } ->
111111+ maybe_apply_generic ~loc ~types ~binds maybe_arg cases ~stackify
112112+ ;;
113113+114114+ let apply t ~loc arg = maybe_apply t ~loc (Some arg) ~stackify:false
115115+ let to_expression t ~loc ~stackify = maybe_apply t ~loc None ~stackify
116116+117117+ let to_value_expression t ~loc ~stackify =
118118+ match t with
119119+ | { types = []; binds = []; cases = _ } ->
120120+ (* lambdas without [let] are already values *)
121121+ let expr = to_expression t ~loc ~stackify in
122122+ assert (is_value_expression expr);
123123+ expr
124124+ | _ -> fresh_lambda ~loc (fun ~arg -> maybe_exclave ~loc (apply t ~loc arg) ~stackify)
125125+ ;;
126126+end
127127+128128+type t =
129129+ | Reference of Reference.t
130130+ | Lambda of Lambda.t
131131+132132+let of_lambda cases = Lambda { types = []; binds = []; cases }
133133+134134+let of_reference_exn ~thunk expr =
135135+ let loc = expr.pexp_loc in
136136+ match Ppxlib_jane.Shim.Expression_desc.of_parsetree expr.pexp_desc ~loc with
137137+ | Pexp_ident ident ->
138138+ Reference { types = []; binds = []; ident; cstr = None; args = []; after_args = [] }
139139+ | Pexp_constraint ({ pexp_desc = Pexp_ident ident; _ }, cstr, _) ->
140140+ Reference { types = []; binds = []; ident; cstr; args = []; after_args = [] }
141141+ | Pexp_apply ({ pexp_desc = Pexp_ident ident; _ }, args) ->
142142+ Reference
143143+ { types = []
144144+ ; binds = []
145145+ ; ident
146146+ ; cstr = None
147147+ ; args
148148+ ; after_args = (if thunk then [ Nolabel, [%expr ()] ] else [])
149149+ }
150150+ | _ ->
151151+ Location.raise_errorf
152152+ ~loc:expr.pexp_loc
153153+ "ppx_sexp_conv: internal error.\n\
154154+ [Conversion.of_reference_exn] expected an identifier possibly applied to arguments.\n\
155155+ Instead, got:\n\
156156+ %s"
157157+ (Pprintast.string_of_expression expr)
158158+;;
159159+160160+let to_expression t ~loc ~stackify =
161161+ match t with
162162+ | Reference reference -> Reference.to_expression ~loc reference
163163+ | Lambda lambda -> Lambda.to_expression ~loc lambda ~stackify
164164+;;
165165+166166+let to_value_expression t ~loc ~rec_flag ~values_being_defined ~stackify =
167167+ match t with
168168+ | Reference reference ->
169169+ Reference.to_value_expression ~loc ~rec_flag ~values_being_defined reference ~stackify
170170+ | Lambda lambda -> Lambda.to_value_expression ~loc lambda ~stackify
171171+;;
172172+173173+let apply t ~loc e =
174174+ match t with
175175+ | Reference reference -> Reference.apply ~loc reference e
176176+ | Lambda lambda -> Lambda.apply ~loc lambda e
177177+;;
178178+179179+let bind t binds =
180180+ match t with
181181+ | Reference reference -> Reference (Reference.bind reference binds)
182182+ | Lambda lambda -> Lambda (Lambda.bind lambda binds)
183183+;;
184184+185185+let bind_types t types =
186186+ match t with
187187+ | Reference reference -> Reference (Reference.bind_types reference types)
188188+ | Lambda lambda -> Lambda (Lambda.bind_types lambda types)
189189+;;
190190+191191+module Apply_all = struct
192192+ type t =
193193+ { bindings : value_binding list
194194+ ; arguments : pattern list
195195+ ; converted : expression list
196196+ }
197197+end
198198+199199+let gen_symbols list ~prefix =
200200+ List.mapi list ~f:(fun i _ -> gen_symbol ~prefix:(prefix ^ Int.to_string i) ())
201201+;;
202202+203203+let zip list1 list2 =
204204+ List.fold_right2 list1 list2 ~init:[] ~f:(fun x y acc -> (x, y) :: acc)
205205+;;
206206+207207+let apply_all ts ~loc =
208208+ let arguments_names = gen_symbols ts ~prefix:"arg" in
209209+ let converted_names = gen_symbols ts ~prefix:"res" in
210210+ let bindings =
211211+ List.map
212212+ (zip ts (zip arguments_names converted_names))
213213+ ~f:(fun (t, (arg, conv)) ->
214214+ let expr = apply ~loc t (evar ~loc arg) in
215215+ value_binding ~loc ~pat:(pvar ~loc conv) ~expr)
216216+ in
217217+ ({ bindings
218218+ ; arguments = List.map arguments_names ~f:(pvar ~loc)
219219+ ; converted = List.map converted_names ~f:(evar ~loc)
220220+ }
221221+ : Apply_all.t)
222222+;;
+60
vendor/opam/ppx_sexp_conv/expander/conversion.mli
···11+open! Stdppx
22+open! Ppxlib
33+44+(** Sexp conversion function, expressed as either a single expression or as a collection
55+ of [match] cases. Expressing as cases rather than wrapping directly in [pexp_function]
66+ allows us to simplify some expressions built on this. *)
77+type t
88+99+(** Construct [t] from a list of pattern/expression cases. *)
1010+val of_lambda : cases -> t
1111+1212+(** Construct [t] from an identifier, possibly applied to arguments. Raise on any other
1313+ form of expression.
1414+1515+ If [thunk], then [expression] should evaluate to something with type [() -> 'a], and
1616+ [of_reference_exn ~thunk:true |> to_value_expression] will evaluate to something of
1717+ type ['a]. [thunk] should only ever be set when working with unboxed types, as this is
1818+ a trick for circumventing the lack of layout polymorphism ([() -> 'a] has layout value
1919+ even if ['a] is unboxed). *)
2020+val of_reference_exn : thunk:bool -> expression -> t
2121+2222+(** Convert [t] to an expression. *)
2323+val to_expression : t -> loc:location -> stackify:bool -> expression
2424+2525+(** Convert [t] to an expression that is a syntactic value, i.e. a constant, identifier,
2626+ or lambda expression that does no "work", can can be preallocated, and works in the
2727+ context of a [let rec]. *)
2828+val to_value_expression
2929+ : t
3030+ -> loc:location
3131+ -> rec_flag:rec_flag
3232+ -> values_being_defined:String.Set.t
3333+ -> stackify:bool
3434+ -> expression
3535+3636+(** Apply [t] to an argument. *)
3737+val apply
3838+ : t
3939+ -> loc:location
4040+ -> expression (** argument [t] is applied to *)
4141+ -> expression
4242+4343+(** Wrap [t] in [let]-bindings. *)
4444+val bind : t -> value_binding list -> t
4545+4646+(** Wrap [t] in [let open .. in] with type declarations. *)
4747+val bind_types : t -> type_declaration list -> t
4848+4949+module Apply_all : sig
5050+ type t =
5151+ { bindings : value_binding list
5252+ ; arguments : pattern list
5353+ ; converted : expression list
5454+ }
5555+end
5656+5757+(** Applies each [t] to a fresh variable, and binds the results to fresh variables.
5858+ Returns the corresponding [value_binding]s, patterns for the argument variables, and
5959+ expressions for the result variables. *)
6060+val apply_all : t list -> loc:location -> Apply_all.t
···11+open! Stdppx
22+open! Ppxlib
33+44+module Sig_generate_of_sexp : sig
55+ (** Given a type, produce the type of its [of_sexp] conversion. *)
66+ val type_of_of_sexp : loc:location -> core_type -> core_type
77+88+ (** Derive an [of_sexp] interface for a list of type declarations. *)
99+ val mk_sig
1010+ : poly:bool
1111+ -> loc:location
1212+ -> path:string
1313+ -> unboxed:bool
1414+ -> rec_flag * type_declaration list
1515+ -> portable:bool
1616+ -> signature_item list
1717+end
1818+1919+module Str_generate_of_sexp : sig
2020+ (** Given a type, produce a pattern for that type's [of_sexp] conversion. *)
2121+ val pat_of_of_sexp : loc:location -> core_type -> pattern
2222+2323+ (** Given a type, produce its [of_sexp] conversion. *)
2424+ val core_type_of_sexp : path:string -> core_type -> expression
2525+2626+ (** Derive an [of_sexp] implementation for a list of type declarations. *)
2727+ val tds_of_sexp
2828+ : loc:location
2929+ -> poly:bool
3030+ -> path:string
3131+ -> portable:bool
3232+ -> unboxed:bool
3333+ -> rec_flag * type_declaration list
3434+ -> structure_item list
3535+end
···11+open! Stdppx
22+open! Ppxlib
33+44+module Sig_generate_sexp_of : sig
55+ (** Given a type, produce the type of its [sexp_of] conversion. *)
66+ val type_of_sexp_of : loc:location -> core_type -> stackify:bool -> core_type
77+88+ (** Derive a [sexp_of] interface for a list of type declarations. *)
99+ val mk_sig
1010+ : loc:location
1111+ -> path:string
1212+ -> unboxed:bool
1313+ -> rec_flag * type_declaration list
1414+ -> stackify:bool
1515+ -> portable:bool
1616+ -> signature_item list
1717+1818+ (** Derive a [sexp_of] interface for an exception declaration. *)
1919+ val mk_sig_exn : loc:location -> path:string -> type_exception -> signature_item list
2020+end
2121+2222+module Str_generate_sexp_of : sig
2323+ (** Given a type, produce a pattern for that type's [sexp_of] conversion. *)
2424+ val pat_of_sexp_of : loc:location -> core_type -> stackify:bool -> pattern
2525+2626+ (** Given a type, produce its [sexp_of] conversion. *)
2727+ val sexp_of_core_type : core_type -> stackify:bool -> expression
2828+2929+ (** Derive a [sexp_of] implementation for a list of type declarations. *)
3030+ val sexp_of_tds
3131+ : loc:location
3232+ -> path:string
3333+ -> unboxed:bool
3434+ -> rec_flag * type_declaration list
3535+ -> stackify:bool
3636+ -> portable:bool
3737+ -> structure_item list
3838+3939+ (** Derive a [sexp_of] implementation for an exception declaration. *)
4040+ val sexp_of_exn : loc:location -> path:string -> type_exception -> structure_item list
4141+end
···11+(** Represents freshly generated names at ppx expansion time. *)
22+33+open! Stdppx
44+open Ppxlib
55+66+type t
77+88+(** Creates a new fresh name using the given string as a prefix. *)
99+val create : string -> loc:location -> t
1010+1111+(** [of_string_loc { loc; txt }] is equivalent to [create txt ~loc] *)
1212+val of_string_loc : string loc -> t
1313+1414+(** Extracts the freshly created name and its location. *)
1515+val to_string_loc : t -> string loc
1616+1717+(** Constructs an expression referring to the fresh name. *)
1818+val expression : t -> expression
1919+2020+(** Constructs a pattern binding the fresh name. *)
2121+val pattern : t -> pattern
+300
vendor/opam/ppx_sexp_conv/expander/helpers.ml
···11+open! Stdppx
22+open! Ppxlib
33+open Ast_builder.Default
44+55+let ( --> ) lhs rhs = case ~guard:None ~lhs ~rhs
66+77+(* Utility functions *)
88+99+let replace_variables_by_underscores =
1010+ let map =
1111+ object
1212+ inherit Ast_traverse.map as super
1313+1414+ method! core_type_desc t =
1515+ match Ppxlib_jane.Shim.Core_type_desc.of_parsetree t with
1616+ | Ptyp_var (_, jkind) ->
1717+ Ppxlib_jane.Shim.Core_type_desc.to_parsetree (Ptyp_any jkind)
1818+ | _ -> super#core_type_desc t
1919+ end
2020+ in
2121+ map#core_type
2222+;;
2323+2424+let make_rigid_types tps =
2525+ List.fold_left tps ~init:String.Map.empty ~f:(fun map (tp, jkind) ->
2626+ String.Map.update
2727+ tp.txt
2828+ (function
2929+ | None -> Some (Fresh_name.of_string_loc tp, jkind)
3030+ | Some (fresh, jkind) ->
3131+ (* Ignore duplicate names, the typechecker will raise after expansion. *)
3232+ Some (fresh, jkind))
3333+ map)
3434+;;
3535+3636+let find_rigid_type ~loc ~rigid_types name =
3737+ match String.Map.find_opt name rigid_types with
3838+ | Some (tp, jkind) -> Fresh_name.to_string_loc tp, jkind
3939+ | None ->
4040+ (* Ignore unbound type names, the typechecker will raise after expansion. *)
4141+ { txt = name; loc }, None
4242+;;
4343+4444+let find_rigid_type_constr ~loc ~rigid_types name =
4545+ let name, _jkind = find_rigid_type ~loc ~rigid_types name in
4646+ Ptyp_constr (Located.map_lident name, [])
4747+;;
4848+4949+let make_type_rigid ~rigid_types =
5050+ let map =
5151+ object
5252+ inherit Ast_traverse.map as super
5353+5454+ method! core_type ty =
5555+ match Ppxlib_jane.Shim.Core_type_desc.of_parsetree ty.ptyp_desc with
5656+ | Ptyp_var (name, _) ->
5757+ let ptyp_desc = find_rigid_type_constr ~loc:ty.ptyp_loc ~rigid_types name in
5858+ { ty with ptyp_desc }
5959+ | _ -> super#core_type ty
6060+ end
6161+ in
6262+ map#core_type
6363+;;
6464+6565+(* Generates the quantified type [ ! 'a .. 'z . (make_mono_type t ('a .. 'z)) ] or
6666+ [type a .. z. make_mono_type t (a .. z)] when [use_rigid_variables] is true.
6767+ Annotation are needed for non regular recursive datatypes and gadt when the return type
6868+ of constructors are constrained. Unfortunately, putting rigid variables everywhere does
6969+ not work because of certains types with constraints. We thus only use rigid variables
7070+ for sum types without constraints, which includes all GADTs. *)
7171+7272+type bound_var = string loc * Ppxlib_jane.jkind_annotation option
7373+7474+let tvars_of_core_type : core_type -> bound_var list =
7575+ let add_binding_to_list (bindings : bound_var list) (bound : bound_var) =
7676+ let { txt = bound_name; loc = _ }, _annot = bound in
7777+ match
7878+ List.exists bindings ~f:(fun b' ->
7979+ let { txt = bound_name'; loc = _ }, _annot' = b' in
8080+ String.equal bound_name bound_name')
8181+ with
8282+ | true -> bindings
8383+ | false -> bound :: bindings
8484+ in
8585+ let tvars =
8686+ object
8787+ inherit [bound_var list] Ast_traverse.fold as super
8888+8989+ method! core_type x acc =
9090+ let loc = x.ptyp_loc in
9191+ match Ppxlib_jane.Shim.Core_type_desc.of_parsetree x.ptyp_desc with
9292+ | Ptyp_var (bound_name, jkind) ->
9393+ add_binding_to_list acc ({ txt = bound_name; loc }, jkind)
9494+ | _ -> super#core_type x acc
9595+ end
9696+ in
9797+ fun typ -> List.rev (tvars#core_type typ [])
9898+;;
9999+100100+let constrained_function_binding
101101+ (* placing a suitably polymorphic or rigid type constraint on the pattern or body *)
102102+ (loc : Location.t)
103103+ (td : type_declaration)
104104+ (typ : core_type)
105105+ ~(tps : (string loc * Ppxlib_jane.jkind_annotation option) list)
106106+ ~(func_name : string)
107107+ ~portable
108108+ (body : expression)
109109+ =
110110+ let bound_vars = tvars_of_core_type typ in
111111+ let has_vars =
112112+ match bound_vars with
113113+ | [] -> false
114114+ | _ :: _ -> true
115115+ in
116116+ let pat =
117117+ let pat = pvar ~loc func_name in
118118+ if not has_vars
119119+ then pat
120120+ else (
121121+ let annot = Ppxlib_jane.Ast_builder.Default.ptyp_poly ~loc bound_vars typ in
122122+ ppat_constraint ~loc pat annot)
123123+ in
124124+ let body =
125125+ let use_rigid_variables =
126126+ match td.ptype_cstrs, td.ptype_kind with
127127+ | [], Ptype_variant _ -> true
128128+ | _ -> false
129129+ in
130130+ if use_rigid_variables
131131+ then (
132132+ let rigid_types = make_rigid_types tps in
133133+ List.fold_right
134134+ tps
135135+ ~f:(fun (tp, _) body ->
136136+ let name, jkind = find_rigid_type ~loc:tp.loc ~rigid_types tp.txt in
137137+ match jkind with
138138+ | None -> pexp_newtype ~loc name body
139139+ | Some jkind ->
140140+ Ppxlib_jane.Ast_builder.Default.pexp_newtype ~loc name (Some jkind) body)
141141+ ~init:(pexp_constraint ~loc body (make_type_rigid ~rigid_types typ)))
142142+ else if has_vars
143143+ then body
144144+ else pexp_constraint ~loc body typ
145145+ in
146146+ Ppxlib_jane.Ast_builder.Default.value_binding
147147+ ~loc
148148+ ~pat
149149+ ~expr:body
150150+ ~modes:(if portable then [ { txt = Mode "portable"; loc } ] else [])
151151+;;
152152+153153+let with_let ~loc ~binds body =
154154+ List.fold_right binds ~init:body ~f:(fun bind body ->
155155+ if List.is_empty bind then body else pexp_let ~loc Nonrecursive bind body)
156156+;;
157157+158158+let with_types ~loc ~types body =
159159+ if List.is_empty types
160160+ then body
161161+ else
162162+ pexp_open
163163+ ~loc
164164+ (open_infos
165165+ ~loc
166166+ ~override:Fresh
167167+ ~expr:
168168+ (pmod_structure
169169+ ~loc
170170+ (List.map types ~f:(fun type_decl -> pstr_type ~loc Recursive [ type_decl ]))))
171171+ body
172172+;;
173173+174174+let fresh_lambda ~loc apply =
175175+ let var = gen_symbol ~prefix:"x" () in
176176+ let pat = pvar ~loc var in
177177+ let arg = evar ~loc var in
178178+ let body = apply ~arg in
179179+ pexp_fun ~loc Nolabel None pat body
180180+;;
181181+182182+let rec is_value_expression expr =
183183+ match
184184+ Ppxlib_jane.Shim.Expression_desc.of_parsetree expr.pexp_desc ~loc:expr.pexp_loc
185185+ with
186186+ (* Syntactic values. *)
187187+ | Pexp_ident _ | Pexp_constant _ | Pexp_function _ | Pexp_lazy _ -> true
188188+ (* Type-only wrappers; we check their contents. *)
189189+ | Pexp_constraint (expr, (_ : core_type option), _)
190190+ | Pexp_coerce (expr, (_ : core_type option), (_ : core_type))
191191+ | Pexp_newtype ((_ : string loc), (_ : Ppxlib_jane.jkind_annotation option), expr)
192192+ | Pexp_stack expr -> is_value_expression expr
193193+ (* Allocating constructors; they are only values if all of their contents are. *)
194194+ | Pexp_tuple lexprs -> List.for_all lexprs ~f:(fun (_, e) -> is_value_expression e)
195195+ | Pexp_unboxed_tuple lexprs ->
196196+ List.for_all lexprs ~f:(fun (_, e) -> is_value_expression e)
197197+ | Pexp_construct (_, None) -> true
198198+ | Pexp_construct (_, Some expr) -> is_value_expression expr
199199+ | Pexp_variant (_, None) -> true
200200+ | Pexp_variant (_, Some expr) -> is_value_expression expr
201201+ | Pexp_record (fields, maybe_expr) | Pexp_record_unboxed_product (fields, maybe_expr) ->
202202+ List.for_all fields ~f:(fun (_, expr) -> is_value_expression expr)
203203+ &&
204204+ (match maybe_expr with
205205+ | None -> true
206206+ | Some expr -> is_value_expression expr)
207207+ (* Not values, or not always values. We make a conservative approximation. *)
208208+ | Pexp_unreachable
209209+ | Pexp_let _
210210+ | Pexp_apply _
211211+ | Pexp_match _
212212+ | Pexp_try _
213213+ | Pexp_field _
214214+ | Pexp_unboxed_field _
215215+ | Pexp_setfield _
216216+ | Pexp_array _
217217+ | Pexp_idx _
218218+ | Pexp_ifthenelse _
219219+ | Pexp_sequence _
220220+ | Pexp_while _
221221+ | Pexp_for _
222222+ | Pexp_send _
223223+ | Pexp_new _
224224+ | Pexp_setvar _
225225+ | Pexp_override _
226226+ | Pexp_letmodule _
227227+ | Pexp_letexception _
228228+ | Pexp_assert _
229229+ | Pexp_poly _
230230+ | Pexp_object _
231231+ | Pexp_pack _
232232+ | Pexp_open _
233233+ | Pexp_letop _
234234+ | Pexp_extension _
235235+ | Pexp_comprehension _
236236+ | Pexp_overwrite _
237237+ | Pexp_quote _
238238+ | Pexp_splice _
239239+ | Pexp_hole -> false
240240+;;
241241+242242+let really_recursive_respecting_opaque rec_flag tds =
243243+ (object
244244+ inherit type_is_recursive rec_flag tds as super
245245+246246+ method! core_type ctype =
247247+ match ctype with
248248+ | _ when Option.is_some (Attribute.get ~mark_as_seen:false Attrs.opaque ctype) ->
249249+ ()
250250+ | [%type: [%t? _] sexp_opaque] -> ()
251251+ | _ -> super#core_type ctype
252252+ end)
253253+ #go
254254+ ()
255255+;;
256256+257257+let strip_attributes =
258258+ object
259259+ inherit Ppxlib_jane.Ast_traverse.map
260260+261261+ method! attribute attr =
262262+ Location.raise_errorf ~loc:attr.attr_loc "failed to strip attribute from syntax"
263263+264264+ method! attributes _ = []
265265+266266+ method! signature_items items =
267267+ List.filter items ~f:(fun item ->
268268+ match item.psig_desc with
269269+ | Psig_attribute _ -> false
270270+ | _ -> true)
271271+272272+ method! structure items =
273273+ List.filter items ~f:(fun item ->
274274+ match item.pstr_desc with
275275+ | Pstr_attribute _ -> false
276276+ | _ -> true)
277277+278278+ method! class_signature csig =
279279+ { csig with
280280+ pcsig_fields =
281281+ List.filter csig.pcsig_fields ~f:(fun field ->
282282+ match field.pctf_desc with
283283+ | Pctf_attribute _ -> false
284284+ | _ -> true)
285285+ }
286286+287287+ method! class_structure cstr =
288288+ { cstr with
289289+ pcstr_fields =
290290+ List.filter cstr.pcstr_fields ~f:(fun field ->
291291+ match field.pcf_desc with
292292+ | Pcf_attribute _ -> false
293293+ | _ -> true)
294294+ }
295295+ end
296296+;;
297297+298298+let include_param_in_combinator param =
299299+ not (Option.is_some (Attribute.get Attrs.phantom param))
300300+;;
+44
vendor/opam/ppx_sexp_conv/expander/helpers.mli
···11+open! Stdppx
22+open! Ppxlib
33+44+(** Constructs a branch of a [match] or [function] expression with no guard. *)
55+val ( --> ) : pattern -> expression -> case
66+77+(** Replace all type variables like ['a] with wildcard ([_]) types. *)
88+val replace_variables_by_underscores : core_type -> core_type
99+1010+(** Create a binding for a derived function, adding a type annotation if required. *)
1111+val constrained_function_binding
1212+ : location (** location to use for the binding *)
1313+ -> type_declaration (** type declaration used to derive the function *)
1414+ -> core_type (** type of the function *)
1515+ -> tps:(string loc * Ppxlib_jane.Shim.jkind_annotation option) list
1616+ (** names and jkinds of type parameters in the declaration *)
1717+ -> func_name:string (** name to bind the function to *)
1818+ -> portable:bool (** Whether the function should be marked as portable. *)
1919+ -> expression (** expression representing the function *)
2020+ -> value_binding
2121+2222+(** Wraps an expression in layers of non-recursive [let] bindings, with the bindings
2323+ sorted from outermost to innermost. *)
2424+val with_let : loc:location -> binds:value_binding list list -> expression -> expression
2525+2626+(** Wraps an expression in [let open] containing type declarations, if non-empty. *)
2727+val with_types : loc:location -> types:type_declaration list -> expression -> expression
2828+2929+(** Constructs a lambda of a fresh variable. Passes a reference to that variable as [arg]
3030+ to construct the lambda's body. *)
3131+val fresh_lambda : loc:location -> (arg:expression -> expression) -> expression
3232+3333+(** Conservative approximation of which expressions are syntactically values, i.e.
3434+ constants, variables, or lambdas. When [true], these expressions have no effects
3535+ (other than possibly closure allocation) and can be used in [let rec] definitions.
3636+ When [false], they may need to be eta-expanded or wrapped in [lazy]. *)
3737+val is_value_expression : expression -> bool
3838+3939+(** Shadows [Ppxlib.really_recursive] with a version that respects the [[@opaque]]
4040+ attribute. *)
4141+val really_recursive_respecting_opaque : rec_flag -> type_declaration list -> rec_flag
4242+4343+val strip_attributes : Ppxlib_jane.Ast_traverse.map
4444+val include_param_in_combinator : core_type -> bool
···11+(* Support for labeled tuples, a language feature currently only implemented in Jane
22+ Street's experimental branch of the compiler
33+ (https://github.com/ocaml-flambda/flambda-backend/). *)
44+55+open! Stdppx
66+77+val has_any_label : (string option * _) list -> bool
88+val atom_of_label : string option -> string
+54
vendor/opam/ppx_sexp_conv/expander/lifted.ml
···11+open! Stdppx
22+open Ppxlib
33+open Ast_builder.Default
44+55+type 'a t =
66+ { value_bindings : value_binding list
77+ ; body : 'a
88+ }
99+1010+let return body = { value_bindings = []; body }
1111+1212+let bind a ~f =
1313+ let b = f a.body in
1414+ { value_bindings = a.value_bindings @ b.value_bindings; body = b.body }
1515+;;
1616+1717+let map a ~f = { a with body = f a.body }
1818+1919+module Monad_infix = struct
2020+ let ( >>| ) a f = map a ~f
2121+ let ( >>= ) a f = bind a ~f
2222+end
2323+2424+open Monad_infix
2525+2626+let all list =
2727+ List.fold_right list ~init:(return []) ~f:(fun head tail ->
2828+ head >>= fun head -> tail >>| fun tail -> head :: tail)
2929+;;
3030+3131+let create ~loc ~prefix ~ty rhs =
3232+ let name = gen_symbol ~prefix () in
3333+ let lhs = pvar ~loc name in
3434+ let body = evar ~loc name in
3535+ let ty, rhs, body =
3636+ if Helpers.is_value_expression rhs
3737+ then ty, rhs, body
3838+ else (
3939+ (* Thunkify the value to evaluate when referred to. *)
4040+ let ty = [%type: Stdlib.Unit.t -> [%t ty]] in
4141+ let rhs = [%expr fun () -> [%e rhs]] in
4242+ let body = [%expr [%e body] ()] in
4343+ ty, rhs, body)
4444+ in
4545+ { value_bindings = [ value_binding ~loc ~pat:(ppat_constraint ~loc lhs ty) ~expr:rhs ]
4646+ ; body
4747+ }
4848+;;
4949+5050+let let_bind_user_expressions { value_bindings; body } ~loc =
5151+ if List.is_empty value_bindings
5252+ then body
5353+ else pexp_let ~loc Nonrecursive value_bindings body
5454+;;
+29
vendor/opam/ppx_sexp_conv/expander/lifted.mli
···11+open! Stdppx
22+open Ppxlib
33+44+(** Represents an ['a], along with some user expressions that should lifted out of the
55+ scope of internal bindings. For example, if a user writes [[@@default x]], they mean
66+ [x] in the surface code, not some temporary variable [x] added by ppx machinery. *)
77+type 'a t
88+99+(** As a monad, combines all client expressions so they can be lifted to the outermost
1010+ level of generated code. *)
1111+1212+val return : 'a -> 'a t
1313+val map : 'a t -> f:('a -> 'b) -> 'b t
1414+val bind : 'a t -> f:('a -> 'b t) -> 'b t
1515+val all : 'a t list -> 'a list t
1616+1717+module Monad_infix : sig
1818+ val ( >>| ) : 'a t -> ('a -> 'b) -> 'b t
1919+ val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t
2020+end
2121+2222+(** Lifts the given expression and binds it to a fresh variable starting with [prefix].
2323+ The expression is evaluated each time it is referred to. The binding is annotated with
2424+ [ty]. Uses [loc] for generated code. *)
2525+val create : loc:location -> prefix:string -> ty:core_type -> expression -> expression t
2626+2727+(** Uses [let] to bind all lifted user expressions, with the contained expression as the
2828+ body. Should be called in whatever scope the user should be able to refer to. *)
2929+val let_bind_user_expressions : expression t -> loc:location -> expression
···11+open! Stdppx
22+open! Ppxlib
33+44+module Generic : sig
55+ type 'specific t =
66+ | Omit_nil
77+ | Sexp_array of core_type
88+ | Sexp_bool
99+ | Sexp_list of core_type
1010+ | Sexp_option of core_type
1111+ | Sexp_or_null of core_type
1212+ | Specific of 'specific
1313+end
1414+1515+module Of_sexp : sig
1616+ type t =
1717+ | Default of expression Lifted.t
1818+ | Required
1919+2020+ val create : loc:Location.t -> label_declaration -> t Generic.t
2121+end
2222+2323+module Sexp_of : sig
2424+ module Drop : sig
2525+ type t =
2626+ | Compare
2727+ | Equal
2828+ | Sexp
2929+ | Func of expression Lifted.t
3030+ end
3131+3232+ type t =
3333+ | Drop_default of Drop.t
3434+ | Drop_if of expression Lifted.t
3535+ | Keep
3636+3737+ val create : loc:Location.t -> label_declaration -> t Generic.t
3838+end
3939+4040+(** Lift the contents of [Attrs.default]. *)
4141+val lift_default : loc:location -> label_declaration -> expression -> expression Lifted.t
+125
vendor/opam/ppx_sexp_conv/expander/renaming.ml
···11+open! Stdppx
22+open! Ppxlib
33+44+type t =
55+ { universal : (Fresh_name.t, string loc) result String.Map.t
66+ ; existential : bool
77+ }
88+99+module Binding_kind = struct
1010+ type t =
1111+ | Universally_bound of Fresh_name.t
1212+ | Existentially_bound
1313+end
1414+1515+let add_universally_bound t name ~prefix =
1616+ { t with
1717+ universal =
1818+ String.Map.add
1919+ name.txt
2020+ (Ok (Fresh_name.create (prefix ^ name.txt) ~loc:name.loc))
2121+ t.universal
2222+ }
2323+;;
2424+2525+let binding_kind t var ~loc =
2626+ match String.Map.find_opt var t.universal with
2727+ | None ->
2828+ if t.existential
2929+ then Binding_kind.Existentially_bound
3030+ else Location.raise_errorf ~loc "ppx_sexp_conv: unbound type variable '%s" var
3131+ | Some (Ok fresh) -> Binding_kind.Universally_bound fresh
3232+ | Some (Error { loc; txt }) -> Location.raise_errorf ~loc "%s" txt
3333+;;
3434+3535+(* Return a map translating type variables appearing in the return type of a GADT
3636+ constructor to their name in the type parameter list.
3737+3838+ For instance:
3939+4040+ {[
4141+ type ('a, 'b) t = X : 'x * 'y -> ('x, 'y) t
4242+ ]}
4343+4444+ will produce:
4545+4646+ {v
4747+ "x" -> Ok "a"
4848+ "y" -> Ok "b"
4949+ v}
5050+5151+ If a variable appears twice in the return type it will map to [Error _]. If a
5252+ variable cannot be mapped to a parameter of the type declaration, it will map to
5353+ [Error] (for instance [A : 'a -> 'a list t]).
5454+5555+ It returns [original] on user error, to let the typer give the error message *)
5656+let with_constructor_declaration original cd ~type_parameters:tps =
5757+ (* Add all type variables of a type to a map. *)
5858+ let add_typevars =
5959+ object
6060+ inherit [t] Ast_traverse.fold as super
6161+6262+ method! core_type ty t =
6363+ match Ppxlib_jane.Shim.Core_type_desc.of_parsetree ty.ptyp_desc with
6464+ | Ptyp_var (var, _) ->
6565+ let error =
6666+ { loc = ty.ptyp_loc
6767+ ; txt =
6868+ Printf.sprintf
6969+ "ppx_sexp_conv: variable is not a parameter of the type constructor. \
7070+ Hint: mark all appearances of '%s in the constructor's arguments as \
7171+ [@sexp.opaque]."
7272+ var
7373+ }
7474+ in
7575+ { t with universal = String.Map.add var (Error error) t.universal }
7676+ | _ -> super#core_type ty t
7777+ end
7878+ in
7979+ let aux t tp_name tp_in_return_type =
8080+ match Ppxlib_jane.Shim.Core_type_desc.of_parsetree tp_in_return_type.ptyp_desc with
8181+ | Ptyp_var (var, _) ->
8282+ let data =
8383+ let loc = tp_in_return_type.ptyp_loc in
8484+ if String.Map.mem var t.universal
8585+ then Error { loc; txt = "ppx_sexp_conv: duplicate variable" }
8686+ else (
8787+ match String.Map.find_opt tp_name original.universal with
8888+ | Some result -> result
8989+ | None -> Error { loc; txt = "ppx_sexp_conv: unbound type parameter" })
9090+ in
9191+ { t with universal = String.Map.add var data t.universal }
9292+ | _ -> add_typevars#core_type tp_in_return_type t
9393+ in
9494+ match cd.pcd_res with
9595+ | None -> original
9696+ | Some ty ->
9797+ (match ty.ptyp_desc with
9898+ | Ptyp_constr (_, params) ->
9999+ if List.length params <> List.length tps
100100+ then original
101101+ else
102102+ Stdlib.ListLabels.fold_left2
103103+ tps
104104+ params
105105+ ~init:{ existential = true; universal = String.Map.empty }
106106+ ~f:aux
107107+ | _ -> original)
108108+;;
109109+110110+let of_type_declaration decl ~prefix =
111111+ { existential = false
112112+ ; universal =
113113+ List.fold_left decl.ptype_params ~init:String.Map.empty ~f:(fun map param ->
114114+ let name = get_type_param_name param in
115115+ String.Map.update
116116+ name.txt
117117+ (function
118118+ | None -> Some (Ok (Fresh_name.create (prefix ^ name.txt) ~loc:name.loc))
119119+ | Some _ ->
120120+ Some (Error { loc = name.loc; txt = "ppx_sexp_conv: duplicate variable" }))
121121+ map)
122122+ }
123123+;;
124124+125125+let without_type () = { existential = false; universal = String.Map.empty }
+52
vendor/opam/ppx_sexp_conv/expander/renaming.mli
···11+(* A renaming is a mapping from type variable name to type variable name.
22+ In definitions such as:
33+44+ type 'a t =
55+ | A : <type> -> 'b t
66+ | B of 'a
77+88+ we generate a function that takes an sexp_of parameter named after 'a, but 'a is not in
99+ scope in <type> when handling the constructor A (because A is a gadt constructor).
1010+ Instead the type variables in scope are the ones defined in the return type of A,
1111+ namely 'b. There could be less or more type variable in cases such as:
1212+1313+ type _ less = Less : int less
1414+ type _ more = More : ('a * 'a) more
1515+1616+ If for instance, <type> is ['b * 'c], when we find 'b, we will look for ['b] in the
1717+ renaming and find ['a] (only in that gadt branch, it could be something else in other
1818+ branches), at which point we can call the previously bound sexp_of parameter named
1919+ after 'a.
2020+ If we can't find a resulting name, like when looking up ['c] in the renaming, then we
2121+ assume the variable is existentially quantified and treat it as [_] (which is ok,
2222+ assuming there are no constraints). *)
2323+open! Stdppx
2424+open! Ppxlib
2525+2626+type t
2727+2828+(** Renaming for contexts outside a type declaration, such as expression extensions. *)
2929+val without_type : unit -> t
3030+3131+(** Renaming for a type declaration. Adds [prefix] to bindings for type parameters. *)
3232+val of_type_declaration : type_declaration -> prefix:string -> t
3333+3434+(** Adds a new name with the given [prefix] for a universally bound type variable. *)
3535+val add_universally_bound : t -> string loc -> prefix:string -> t
3636+3737+module Binding_kind : sig
3838+ type t =
3939+ | Universally_bound of Fresh_name.t
4040+ | Existentially_bound
4141+end
4242+4343+(** Looks up the binding for a type variable. *)
4444+val binding_kind : t -> string -> loc:location -> Binding_kind.t
4545+4646+(** Extends the renaming of a type declaration with GADT context for a constructor
4747+ declaration, if any. *)
4848+val with_constructor_declaration
4949+ : t
5050+ -> constructor_declaration
5151+ -> type_parameters:string list
5252+ -> t
···11+type t = { a : int [@sexp_drop_default ( = )] [@sexp.omit_nil] }
22+[@@deriving sexp_of ~stackify]
33+44+[%%expect
55+ {|
66+Line _, characters _-_:
77+Error: The following elements are mutually exclusive: sexp.sexp_drop_default sexp.omit_nil
88+|}]
99+1010+type t = { a : int list [@sexp.list] [@sexp.omit_nil] } [@@deriving sexp_of ~stackify]
1111+1212+[%%expect
1313+ {|
1414+Line _, characters _-_:
1515+Error: The following elements are mutually exclusive: sexp.omit_nil [@sexp.list]
1616+|}]
1717+1818+type t = { a : int [@default 0] [@sexp.omit_nil] } [@@deriving of_sexp]
1919+2020+[%%expect
2121+ {|
2222+Line _, characters _-_:
2323+Error: The following elements are mutually exclusive: sexp.default sexp.omit_nil
2424+|}]
2525+2626+type t = int [@@deriving sexp ~stackify] [@@sexp.allow_extra_fields]
2727+2828+[%%expect
2929+ {|
3030+Line _, characters _-_:
3131+Error: ppx_sexp_conv: [@@allow_extra_fields] is only allowed on records.
3232+|}]
3333+3434+type 'a t = 'a option =
3535+ | None
3636+ | Some of 'a
3737+[@@deriving sexp ~stackify] [@@sexp.allow_extra_fields]
3838+3939+[%%expect
4040+ {|
4141+Line _, characters _-_:
4242+Error: ppx_sexp_conv: [@@allow_extra_fields] is only allowed on records.
4343+|}]
4444+4545+type 'a t = Some of { a : int } [@@deriving sexp ~stackify] [@@sexp.allow_extra_fields]
4646+4747+[%%expect
4848+ {|
4949+Line _, characters _-_:
5050+Error: ppx_sexp_conv: [@@allow_extra_fields] only works on records. For inline records, do: type t = A of { a : int } [@allow_extra_fields] | B [@@deriving sexp]
5151+|}]
5252+5353+type 'a t =
5454+ | Some of { a : int }
5555+ | None [@sexp.allow_extra_fields]
5656+[@@deriving sexp ~stackify]
5757+5858+[%%expect
5959+ {|
6060+Line _, characters _-_:
6161+Error: ppx_sexp_conv: [@allow_extra_fields] is only allowed on inline records.
6262+|}]
6363+6464+type t =
6565+ | Non
6666+ | Som of { next : t [@default Non] [@sexp_drop_default.equal] }
6767+[@@deriving sexp ~stackify]
6868+6969+[%%expect
7070+ {|
7171+Line _, characters _-_:
7272+Error: [@sexp_drop_default.equal] was used, but the type of the field contains a type defined in the current recursive block: t.
7373+This is not supported.
7474+Consider using [@sexp_drop_if _] or [@sexp_drop_default.sexp] instead.
7575+|}]
7676+7777+type nonrec 'a t = { foo : 'a option [@default None] [@sexp_drop_default.equal] }
7878+[@@deriving sexp ~stackify]
7979+8080+[%%expect
8181+ {|
8282+Line _, characters _-_:
8383+Error: [@sexp_drop_default.equal] was used, but the type of the field contains a type variable: 'a.
8484+Comparison is not avaiable for type variables.
8585+Consider using [@sexp_drop_if _] or [@sexp_drop_default.sexp] instead.
8686+|}]
8787+8888+open Base
8989+9090+type t = { a : int [@default 8] [@sexp_drop_default] } [@@deriving sexp_of ~stackify]
9191+9292+[%%expect
9393+ {|
9494+Line _, characters _-_:
9595+Error: Unsupported [@sexp_drop_default] payload; please use one of:
9696+- [@sexp_drop_default f] and give an explicit equality function [f]
9797+- [@sexp_drop_default.compare] if the type supports [%compare]
9898+- [@sexp_drop_default.equal] if the type supports [%equal]
9999+- [@sexp_drop_default.sexp] if you want to compare the sexp representations
100100+|}]
101101+102102+type t = { x : unit [@sexp.opaque] } [@@deriving sexp_of ~stackify]
103103+type t = { x : unit [@sexp.opaque] } [@@deriving of_sexp]
104104+type t = { x : unit [@sexp.opaque] } [@@deriving sexp_grammar]
105105+106106+[%%expect
107107+ {|
108108+Line _, characters _-_:
109109+Error: Attribute `sexp.opaque' was not used.
110110+ Hint: `sexp.opaque' is available for core types but is used here in
111111+ the
112112+ context of a label declaration.
113113+ Did you put it at the wrong level?
114114+115115+Line _, characters _-_:
116116+Error: Attribute `sexp.opaque' was not used.
117117+ Hint: `sexp.opaque' is available for core types but is used here in
118118+ the
119119+ context of a label declaration.
120120+ Did you put it at the wrong level?
121121+122122+Line _, characters _-_:
123123+Error: Attribute `sexp.opaque' was not used.
124124+ Hint: `sexp.opaque' is available for core types but is used here in
125125+ the
126126+ context of a label declaration.
127127+ Did you put it at the wrong level?
128128+|}]
129129+130130+type t = { x : unit [@sexp.option] } [@@deriving sexp_of ~stackify]
131131+type t = { x : unit [@sexp.option] } [@@deriving of_sexp]
132132+type t = { x : unit [@sexp.option] } [@@deriving sexp_grammar]
133133+134134+[%%expect
135135+ {|
136136+Line _, characters _-_:
137137+Error: ppx_sexp_conv: [@sexp.option] is only allowed on type [_ option].
138138+139139+Line _, characters _-_:
140140+Error: ppx_sexp_conv: [@sexp.option] is only allowed on type [_ option].
141141+142142+Line _, characters _-_:
143143+Error: ppx_sexp_conv: [@sexp.option] is only allowed on type [_ option].
144144+|}]
145145+146146+type t = { x : unit [@sexp.or_null] } [@@deriving sexp_of ~stackify]
147147+type t = { x : unit [@sexp.or_null] } [@@deriving of_sexp]
148148+type t = { x : unit [@sexp.or_null] } [@@deriving sexp_grammar]
149149+150150+[%%expect
151151+ {|
152152+Line _, characters _-_:
153153+Error: ppx_sexp_conv: [@sexp.or_null] is only allowed on type [_ or_null].
154154+155155+Line _, characters _-_:
156156+Error: ppx_sexp_conv: [@sexp.or_null] is only allowed on type [_ or_null].
157157+158158+Line _, characters _-_:
159159+Error: ppx_sexp_conv: [@sexp.or_null] is only allowed on type [_ or_null].
160160+|}]
161161+162162+type t = { x : unit [@sexp.list] } [@@deriving sexp_of ~stackify]
163163+type t = { x : unit [@sexp.list] } [@@deriving of_sexp]
164164+type t = { x : unit [@sexp.list] } [@@deriving sexp_grammar]
165165+166166+[%%expect
167167+ {|
168168+Line _, characters _-_:
169169+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
170170+171171+Line _, characters _-_:
172172+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
173173+174174+Line _, characters _-_:
175175+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
176176+|}]
177177+178178+type t = { x : unit [@sexp.array] } [@@deriving sexp_of ~stackify]
179179+type t = { x : unit [@sexp.array] } [@@deriving of_sexp]
180180+type t = { x : unit [@sexp.array] } [@@deriving sexp_grammar]
181181+182182+[%%expect
183183+ {|
184184+Line _, characters _-_:
185185+Error: ppx_sexp_conv: [@sexp.array] is only allowed on type [_ array].
186186+187187+Line _, characters _-_:
188188+Error: ppx_sexp_conv: [@sexp.array] is only allowed on type [_ array].
189189+190190+Line _, characters _-_:
191191+Error: ppx_sexp_conv: [@sexp.array] is only allowed on type [_ array].
192192+|}]
193193+194194+type t = { x : unit [@sexp.bool] } [@@deriving sexp_of ~stackify]
195195+type t = { x : unit [@sexp.bool] } [@@deriving of_sexp]
196196+type t = { x : unit [@sexp.bool] } [@@deriving sexp_grammar]
197197+198198+[%%expect
199199+ {|
200200+Line _, characters _-_:
201201+Error: ppx_sexp_conv: [@sexp.bool] is only allowed on type [bool].
202202+203203+Line _, characters _-_:
204204+Error: ppx_sexp_conv: [@sexp.bool] is only allowed on type [bool].
205205+206206+Line _, characters _-_:
207207+Error: ppx_sexp_conv: [@sexp.bool] is only allowed on type [bool].
208208+|}]
209209+210210+type t = A of unit [@sexp.list] [@@deriving sexp_of ~stackify]
211211+type t = A of unit [@sexp.list] [@@deriving of_sexp]
212212+type t = A of unit [@sexp.list] [@@deriving sexp_grammar]
213213+214214+[%%expect
215215+ {|
216216+Line _, characters _-_:
217217+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
218218+219219+Line _, characters _-_:
220220+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
221221+222222+Line _, characters _-_:
223223+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
224224+|}]
225225+226226+type t = [ `A of unit [@sexp.list] ] [@@deriving sexp_of ~stackify]
227227+type t = [ `A of unit [@sexp.list] ] [@@deriving of_sexp]
228228+type t = [ `A of unit [@sexp.list] ] [@@deriving sexp_grammar]
229229+230230+[%%expect
231231+ {|
232232+Line _, characters _-_:
233233+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
234234+235235+Line _, characters _-_:
236236+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
237237+238238+Line _, characters _-_:
239239+Error: ppx_sexp_conv: [@sexp.list] is only allowed on type [_ list].
240240+|}]
241241+242242+let (_ : _) = [%sexp_grammar: 'k -> 'v -> ('k * 'v) list]
243243+244244+[%%expect {| |}]
245245+246246+let (_ : _) = [%sexp_grammar: < for_all : 'k 'v. ('k * 'v) list > ]
247247+248248+[%%expect
249249+ {|
250250+Line _, characters _-_:
251251+Error: sexp_grammar: object types are unsupported
252252+|}]
253253+254254+let (_ : _) = [%sexp_grammar: < other : 'k 'v. ('k * 'v) list > ]
255255+256256+[%%expect
257257+ {|
258258+Line _, characters _-_:
259259+Error: sexp_grammar: object types are unsupported
260260+|}]
261261+262262+type t = < for_all : 'k 'v. ('k * 'v) list > [@@deriving sexp_grammar]
263263+264264+[%%expect
265265+ {|
266266+Line _, characters _-_:
267267+Error: sexp_grammar: object types are unsupported
268268+|}]
269269+270270+type t = < other : 'k 'v. ('k * 'v) list > [@@deriving sexp_grammar]
271271+272272+[%%expect
273273+ {|
274274+Line _, characters _-_:
275275+Error: sexp_grammar: object types are unsupported
276276+|}]
277277+278278+type t = T : 'a -> t [@@deriving sexp_grammar]
279279+280280+[%%expect
281281+ {|
282282+Line _, characters _-_:
283283+Error: Unbound value _'a_sexp_grammar
284284+Hint: Did you mean char_sexp_grammar, int_sexp_grammar or ref_sexp_grammar?
285285+|}]
286286+287287+(* If we can sensibly derive [sexp_grammar], we might as well, because the user might
288288+ still be able to pair it with a consistent hand-written [t_of_sexp]. *)
289289+type _ t = T : int -> string t [@@deriving sexp_grammar]
290290+291291+[%%expect {| |}]
292292+293293+type _ t = T : int -> string t [@@deriving of_sexp]
294294+295295+[%%expect
296296+ {|
297297+Line _, characters _-_:
298298+Error: This expression has type string t
299299+ but an expression was expected of type a__110_ t
300300+ Type string is not compatible with type a__110_
301301+|}]
302302+303303+type t = exn [@@deriving sexp_of ~stackify]
304304+305305+[%%expect
306306+ {|
307307+Line _, characters _-_:
308308+Error: Unbound value sexp_of_exn__stack
309309+Hint: Did you mean sexp_of_int__stack or sexp_of_ref__stack?
310310+|}]
311311+312312+let [%sexp_of: M.t] = ()
313313+314314+[%%expect
315315+ {|
316316+Line _, characters _-_:
317317+Error: Invalid identifier M.t for converter in pattern position. Only simple
318318+ identifiers (like t or string) or applications of functors with simple
319319+ identifiers (like M(K).t) are supported.
320320+|}]
321321+322322+let [%sexp_of: 'a M.t] = ()
323323+324324+[%%expect
325325+ {|
326326+Line _, characters _-_:
327327+Error: Invalid identifier M.t for converter in pattern position. Only simple
328328+ identifiers (like t or string) or applications of functors with simple
329329+ identifiers (like M(K).t) are supported.
330330+|}]
331331+332332+let [%sexp_of: M.F(N).t] = ()
333333+334334+[%%expect
335335+ {|
336336+Line _, characters _-_:
337337+Error: Invalid identifier M.F(N).t for converter in pattern position. Only
338338+ simple identifiers (like t or string) or applications of functors with
339339+ simple identifiers (like M(K).t) are supported.
340340+|}]
341341+342342+let [%sexp_grammar: M.F(N).t] = ()
343343+344344+[%%expect
345345+ {|
346346+Line _, characters _-_:
347347+Error: Invalid identifier M.F(N).t for converter in pattern position. Only
348348+ simple identifiers (like t or string) or applications of functors with
349349+ simple identifiers (like M(K).t) are supported.
350350+|}]
351351+352352+let [%sexp_grammar: _] = ()
353353+354354+[%%expect
355355+ {|
356356+Line _, characters _-_:
357357+Error: Only type variables and constructors are allowed here (e.g. ['a], [t],
358358+ ['a t], or [M(X).t]).
359359+|}]
360360+361361+(* Passing ~portable to sexp can give you better error messages in
362362+ structure context.
363363+*)
364364+365365+module Non_portable : sig
366366+ type t [@@deriving sexp]
367367+end @ nonportable =
368368+ Int
369369+370370+type t =
371371+ { non_portable : Non_portable.t
372372+ ; other : int
373373+ }
374374+[@@deriving sexp ~portable]
375375+376376+[%%expect
377377+ {|
378378+Line _, characters _-_:
379379+Error: The value Non_portable.t_of_sexp is nonportable
380380+ but is expected to be portable because it is used inside a function
381381+ which is expected to be portable.
382382+|}]
+201
vendor/opam/ppx_sexp_conv/test/examples.mlt
···11+module Position_for_polymorphic_variant_errors = struct
22+ type t1 = [ `A ] [@@deriving of_sexp]
33+ type t2 = [ `B ] [@@deriving of_sexp]
44+ type t3 = A of [ t1 | t2 ] [@@deriving of_sexp]
55+66+ let (_ : t3) = t3_of_sexp (List [ Atom "A"; Atom "C" ])
77+end
88+99+[%%expect
1010+ {|
1111+Exception:
1212+(Of_sexp_error
1313+ "examples.mlt.Position_for_polymorphic_variant_errors.t3_of_sexp: no matching variant found"
1414+ (invalid_sexp C))
1515+|}]
1616+1717+let _ = [%sexp_of: 'a]
1818+1919+[%%expect
2020+ {|
2121+Line _, characters _-_:
2222+Error: ppx_sexp_conv: unbound type variable 'a
2323+|}]
2424+2525+let _ = [%sexp_of_stack: 'a]
2626+2727+[%%expect
2828+ {|
2929+Line _, characters _-_:
3030+Error: ppx_sexp_conv: unbound type variable 'a
3131+|}]
3232+3333+let _ = [%of_sexp: 'a]
3434+3535+[%%expect
3636+ {|
3737+Line _, characters _-_:
3838+Error: ppx_sexp_conv: unbound type variable 'a
3939+|}]
4040+4141+module type S = sig
4242+ val x : [%sexp_of: 'a]
4343+end
4444+4545+[%%expect {| |}]
4646+4747+module type S = sig
4848+ val x : [%sexp_of_stack: 'a]
4949+end
5050+5151+[%%expect {| |}]
5252+5353+let _ = [%sexp (() : 'a)]
5454+5555+[%%expect
5656+ {|
5757+Line _, characters _-_:
5858+Error: ppx_sexp_conv: unbound type variable 'a
5959+|}]
6060+6161+type 'a t =
6262+ | None
6363+ | Something_else of { value : 'a }
6464+[@@deriving sexp ~stackify]
6565+6666+[%%expect {| |}]
6767+6868+module Record_with_defaults = struct
6969+ open Sexplib0.Sexp_conv
7070+7171+ let a_field = "a_field"
7272+ let b_field = "b_field"
7373+7474+ type record_with_defaults =
7575+ { a : string [@default a_field]
7676+ ; b : string [@default b_field]
7777+ }
7878+ [@@deriving of_sexp]
7979+end
8080+8181+[%%expect {| |}]
8282+8383+module Polymorphic_recursion = struct
8484+ type 'a t = T of 'a t t [@@deriving sexp_grammar]
8585+end
8686+8787+[%%expect {| |}]
8888+8989+module type Sexpable = sig
9090+ type t [@@deriving sexp, sexp_grammar]
9191+end
9292+9393+module Define_sexp_converters_manually : sig
9494+ type t [@@deriving sexp, sexp_grammar]
9595+9696+ module Functor (M : Sexpable) : Sexpable with type t = t
9797+ module T : Sexpable with type t = t
9898+9999+ type with_functor = { x : Functor(T).t } [@@deriving sexp, sexp_grammar]
100100+101101+ module Parameterized : sig
102102+ type 'a t [@@deriving sexp, sexp_grammar]
103103+ end
104104+end = struct
105105+ open Base
106106+107107+ type t = unit
108108+109109+ let [%sexp_of: t] = [%sexp_of: unit]
110110+ let [%of_sexp: t] = [%of_sexp: unit]
111111+ let [%sexp_grammar: t] = [%sexp_grammar: unit]
112112+113113+ module T = struct
114114+ type nonrec t = t
115115+116116+ let [%sexp_of: t] = [%sexp_of: t]
117117+ let [%of_sexp: t] = [%of_sexp: t]
118118+ let [%sexp_grammar: t] = [%sexp_grammar: t]
119119+ end
120120+121121+ module Functor (M : Sexpable) = struct
122122+ module _ = M
123123+124124+ type nonrec t = t [@@deriving sexp, sexp_grammar]
125125+ end
126126+127127+ (* the raison d'etre *)
128128+ let [%sexp_of: Functor(T).t] = fun (module M : Sexpable) -> [%sexp_of: t]
129129+ let [%of_sexp: Functor(T).t] = fun (module M : Sexpable) -> [%of_sexp: t]
130130+ let [%sexp_grammar: Functor(T).t] = fun (module M : Sexpable) -> [%sexp_grammar: t]
131131+132132+ type with_functor = { x : Functor(T).t } [@@deriving sexp, sexp_grammar]
133133+134134+ module Parameterized = struct
135135+ type 'a t = 'a * 'a
136136+137137+ let [%sexp_of: a t] = fun [%sexp_of: a] -> [%sexp_of: a * a]
138138+ let [%of_sexp: a t] = fun [%of_sexp: a] -> [%of_sexp: a * a]
139139+ let [%sexp_grammar: 'a t] = fun [%sexp_grammar: 'a] -> [%sexp_grammar: 'a * 'a]
140140+ end
141141+end
142142+143143+[%%expect {| |}]
144144+145145+(* Banning this is fine because it's also banned in expression position. *)
146146+let [%sexp_of: 'a] = ()
147147+148148+[%%expect
149149+ {|
150150+Line _, characters _-_:
151151+Error: Type variables are disallowed here. Instead, consider using a locally
152152+ abstract type.
153153+|}]
154154+155155+(* Banning this is fine because it's also banned in expression position. *)
156156+let [%of_sexp: 'a] = ()
157157+158158+[%%expect
159159+ {|
160160+Line _, characters _-_:
161161+Error: Type variables are disallowed here. Instead, consider using a locally
162162+ abstract type.
163163+|}]
164164+165165+let [%sexp_of: _] = ()
166166+167167+[%%expect
168168+ {|
169169+Line _, characters _-_:
170170+Error: Only type constructors are allowed here (e.g. [t], ['a t], or
171171+ [M(X).t]).
172172+|}]
173173+174174+let [%of_sexp: _] = ()
175175+176176+[%%expect
177177+ {|
178178+Line _, characters _-_:
179179+Error: Only type constructors are allowed here (e.g. [t], ['a t], or
180180+ [M(X).t]).
181181+|}]
182182+183183+let [%sexp_of: M.N(X).t] = ()
184184+185185+[%%expect
186186+ {|
187187+Line _, characters _-_:
188188+Error: Invalid identifier M.N(X).t for converter in pattern position. Only
189189+ simple identifiers (like t or string) or applications of functors with
190190+ simple identifiers (like M(K).t) are supported.
191191+|}]
192192+193193+let [%of_sexp: M.N(X).t] = ()
194194+195195+[%%expect
196196+ {|
197197+Line _, characters _-_:
198198+Error: Invalid identifier M.N(X).t for converter in pattern position. Only
199199+ simple identifiers (like t or string) or applications of functors with
200200+ simple identifiers (like M(K).t) are supported.
201201+|}]
···11+open Base
22+33+(* This test documents the behavior of [@@deriving sexp_of] on GADTs with type indexes. *)
44+55+(* These GADTs are handled by ppx_sexp_conv, where the ['a] is implicitly opaqueified: *)
66+77+module Silently_opaqueified = struct
88+ type t1 = X1 : 'a -> t1 [@@deriving sexp_of]
99+ type _ t2 = X2 : 'a -> 'b t2 [@@deriving sexp_of]
1010+1111+ let t1 = sexp_of_t1 (X1 1)
1212+ let t2 = sexp_of_t2 [%sexp_of: int] (X2 2)
1313+ let () = Stdio.print_s t1
1414+ let () = Stdio.print_s t2
1515+end
1616+1717+[%%expect
1818+ {|
1919+(X1 _)
2020+(X2 _)
2121+|}]
2222+2323+(* This GADT is handled by ppx_sexp_conv, where [sexp_of_a] is passed in by the caller:
2424+*)
2525+2626+module Not_opaque = struct
2727+ type _ t3 = X3 : 'a -> 'a t3 [@@deriving sexp_of]
2828+2929+ let t3 = sexp_of_t3 [%sexp_of: int] (X3 3)
3030+ let () = Stdio.print_s t3
3131+end
3232+3333+[%%expect
3434+ {|
3535+(X3 3)
3636+|}]
3737+3838+(* This GADT is **NOT** handleable by ppx_sexp_conv without opaqueifying the constructor:
3939+ the type variable ['a] that appears in the constructor argument ['a] is not a simple
4040+ index of the "return type" ['a list t4] (instead, ['a list] is the index): *)
4141+4242+module Error_if_not_opaqueified = struct
4343+ type _ t4 = X4 : 'a -> 'a list t4 [@@deriving sexp_of]
4444+end
4545+4646+[%%expect
4747+ {|
4848+Line _, characters _-_:
4949+Error: ppx_sexp_conv: variable is not a parameter of the type constructor. Hint: mark all appearances of 'a in the constructor's arguments as [@sexp.opaque].
5050+|}]
5151+5252+(* The error message encourages users to opt in to the explicitly-opaqueified version: *)
5353+5454+module Explicitly_opaqueified = struct
5555+ type _ t5 = X5 : ('a[@sexp.opaque]) -> 'a list t5 [@@deriving sexp_of]
5656+5757+ let t5 = sexp_of_t5 [%sexp_of: int list] (X5 5)
5858+ let () = Stdio.print_s t5
5959+end
6060+6161+[%%expect
6262+ {|
6363+(X5 <opaque>)
6464+|}]
+2140
vendor/opam/ppx_sexp_conv/test/expansion.ml
···11+open! Base
22+33+[@@@disable_unused_warnings]
44+55+open struct
66+ type _shadow_constructors =
77+ | []
88+ | ( :: )
99+ | None
1010+ | Some
1111+end
1212+1313+module%template Abstract = struct
1414+ type t [@@deriving_inline sexp [@alloc stack]]
1515+1616+ let _ = fun (_ : t) -> ()
1717+1818+ let t_of_sexp =
1919+ (let error_source__002_ = "expansion.ml.Abstract.t" in
2020+ fun x__003_ -> Sexplib0.Sexp_conv_error.empty_type error_source__002_ x__003_
2121+ : Sexplib0.Sexp.t -> t)
2222+ ;;
2323+2424+ let _ = t_of_sexp
2525+ let sexp_of_t = (fun _ -> assert false : t -> Sexplib0.Sexp.t)
2626+ let _ = sexp_of_t
2727+ let sexp_of_t__stack = (fun _ -> assert false : t -> Sexplib0.Sexp.t)
2828+ let _ = sexp_of_t__stack
2929+3030+ [@@@end]
3131+end
3232+3333+module Tuple = struct
3434+ type t = int * int * int [@@deriving_inline sexp ~stackify]
3535+3636+ let _ = fun (_ : t) -> ()
3737+3838+ let t_of_sexp =
3939+ (let error_source__012_ = "expansion.ml.Tuple.t" in
4040+ function
4141+ | Sexplib0.Sexp.List [ arg0__005_; arg1__006_; arg2__007_ ] ->
4242+ let res0__008_ = int_of_sexp arg0__005_
4343+ and res1__009_ = int_of_sexp arg1__006_
4444+ and res2__010_ = int_of_sexp arg2__007_ in
4545+ res0__008_, res1__009_, res2__010_
4646+ | sexp__011_ ->
4747+ Sexplib0.Sexp_conv_error.tuple_of_size_n_expected error_source__012_ 3 sexp__011_
4848+ : Sexplib0.Sexp.t -> t)
4949+ ;;
5050+5151+ let _ = t_of_sexp
5252+5353+ let sexp_of_t =
5454+ (fun (arg0__013_, arg1__014_, arg2__015_) ->
5555+ let res0__016_ = sexp_of_int arg0__013_
5656+ and res1__017_ = sexp_of_int arg1__014_
5757+ and res2__018_ = sexp_of_int arg2__015_ in
5858+ Sexplib0.Sexp.List [ res0__016_; res1__017_; res2__018_ ]
5959+ : t -> Sexplib0.Sexp.t)
6060+ ;;
6161+6262+ let _ = sexp_of_t
6363+6464+ let sexp_of_t__stack =
6565+ (fun (arg0__019_, arg1__020_, arg2__021_) ->
6666+ let res0__022_ = sexp_of_int__stack arg0__019_
6767+ and res1__023_ = sexp_of_int__stack arg1__020_
6868+ and res2__024_ = sexp_of_int__stack arg2__021_ in
6969+ Sexplib0.Sexp.List [ res0__022_; res1__023_; res2__024_ ]
7070+ : t -> Sexplib0.Sexp.t)
7171+ ;;
7272+7373+ let _ = sexp_of_t__stack
7474+7575+ [@@@end]
7676+end
7777+7878+module Record = struct
7979+ type t =
8080+ { a : int
8181+ ; b : int
8282+ ; c : int
8383+ }
8484+ [@@deriving_inline sexp ~stackify]
8585+8686+ let _ = fun (_ : t) -> ()
8787+8888+ let t_of_sexp =
8989+ (let error_source__026_ = "expansion.ml.Record.t" in
9090+ fun x__033_ ->
9191+ Sexplib0.Sexp_conv_record.record_of_sexp
9292+ ~caller:error_source__026_
9393+ ~fields:
9494+ (Field
9595+ { name = "a"
9696+ ; kind = Required
9797+ ; conv =
9898+ (fun x__031_ ->
9999+ let _x__032_ = int_of_sexp x__031_ in
100100+ fun () -> _x__032_)
101101+ ; rest =
102102+ Field
103103+ { name = "b"
104104+ ; kind = Required
105105+ ; conv =
106106+ (fun x__029_ ->
107107+ let _x__030_ = int_of_sexp x__029_ in
108108+ fun () -> _x__030_)
109109+ ; rest =
110110+ Field
111111+ { name = "c"
112112+ ; kind = Required
113113+ ; conv =
114114+ (fun x__027_ ->
115115+ let _x__028_ = int_of_sexp x__027_ in
116116+ fun () -> _x__028_)
117117+ ; rest = Empty
118118+ }
119119+ }
120120+ })
121121+ ~index_of_field:(function
122122+ | "a" -> 0
123123+ | "b" -> 1
124124+ | "c" -> 2
125125+ | _ -> -1)
126126+ ~allow_extra_fields:false
127127+ ~create:(fun (a, (b, (c, ()))) : t ->
128128+ let a = a () in
129129+ let b = b () in
130130+ let c = c () in
131131+ { a; b; c })
132132+ x__033_
133133+ : Sexplib0.Sexp.t -> t)
134134+ ;;
135135+136136+ let _ = t_of_sexp
137137+138138+ let sexp_of_t =
139139+ (fun { a = a__035_; b = b__037_; c = c__039_ } ->
140140+ let bnds__034_ = ([] : _ Stdlib.List.t) in
141141+ let bnds__034_ =
142142+ let arg__040_ = sexp_of_int c__039_ in
143143+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__040_ ] :: bnds__034_
144144+ : _ Stdlib.List.t)
145145+ in
146146+ let bnds__034_ =
147147+ let arg__038_ = sexp_of_int b__037_ in
148148+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__038_ ] :: bnds__034_
149149+ : _ Stdlib.List.t)
150150+ in
151151+ let bnds__034_ =
152152+ let arg__036_ = sexp_of_int a__035_ in
153153+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__036_ ] :: bnds__034_
154154+ : _ Stdlib.List.t)
155155+ in
156156+ Sexplib0.Sexp.List bnds__034_
157157+ : t -> Sexplib0.Sexp.t)
158158+ ;;
159159+160160+ let _ = sexp_of_t
161161+162162+ let sexp_of_t__stack =
163163+ (fun { a = a__042_; b = b__044_; c = c__046_ } ->
164164+ let bnds__041_ = ([] : _ Stdlib.List.t) in
165165+ let bnds__041_ =
166166+ let arg__047_ = sexp_of_int__stack c__046_ in
167167+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__047_ ] :: bnds__041_
168168+ : _ Stdlib.List.t)
169169+ in
170170+ let bnds__041_ =
171171+ let arg__045_ = sexp_of_int__stack b__044_ in
172172+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__045_ ] :: bnds__041_
173173+ : _ Stdlib.List.t)
174174+ in
175175+ let bnds__041_ =
176176+ let arg__043_ = sexp_of_int__stack a__042_ in
177177+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__043_ ] :: bnds__041_
178178+ : _ Stdlib.List.t)
179179+ in
180180+ Sexplib0.Sexp.List bnds__041_
181181+ : t -> Sexplib0.Sexp.t)
182182+ ;;
183183+184184+ let _ = sexp_of_t__stack
185185+186186+ [@@@end]
187187+end
188188+189189+module Mutable_record = struct
190190+ type t =
191191+ { mutable a : int
192192+ ; mutable b : int
193193+ ; mutable c : int
194194+ }
195195+ [@@deriving_inline sexp ~stackify]
196196+197197+ let _ = fun (_ : t) -> ()
198198+199199+ let t_of_sexp =
200200+ (let error_source__049_ = "expansion.ml.Mutable_record.t" in
201201+ fun x__056_ ->
202202+ Sexplib0.Sexp_conv_record.record_of_sexp
203203+ ~caller:error_source__049_
204204+ ~fields:
205205+ (Field
206206+ { name = "a"
207207+ ; kind = Required
208208+ ; conv =
209209+ (fun x__054_ ->
210210+ let _x__055_ = int_of_sexp x__054_ in
211211+ fun () -> _x__055_)
212212+ ; rest =
213213+ Field
214214+ { name = "b"
215215+ ; kind = Required
216216+ ; conv =
217217+ (fun x__052_ ->
218218+ let _x__053_ = int_of_sexp x__052_ in
219219+ fun () -> _x__053_)
220220+ ; rest =
221221+ Field
222222+ { name = "c"
223223+ ; kind = Required
224224+ ; conv =
225225+ (fun x__050_ ->
226226+ let _x__051_ = int_of_sexp x__050_ in
227227+ fun () -> _x__051_)
228228+ ; rest = Empty
229229+ }
230230+ }
231231+ })
232232+ ~index_of_field:(function
233233+ | "a" -> 0
234234+ | "b" -> 1
235235+ | "c" -> 2
236236+ | _ -> -1)
237237+ ~allow_extra_fields:false
238238+ ~create:(fun (a, (b, (c, ()))) : t ->
239239+ let a = a () in
240240+ let b = b () in
241241+ let c = c () in
242242+ { a; b; c })
243243+ x__056_
244244+ : Sexplib0.Sexp.t -> t)
245245+ ;;
246246+247247+ let _ = t_of_sexp
248248+249249+ let sexp_of_t =
250250+ (fun { a = a__058_; b = b__060_; c = c__062_ } ->
251251+ let bnds__057_ = ([] : _ Stdlib.List.t) in
252252+ let bnds__057_ =
253253+ let arg__063_ = sexp_of_int c__062_ in
254254+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__063_ ] :: bnds__057_
255255+ : _ Stdlib.List.t)
256256+ in
257257+ let bnds__057_ =
258258+ let arg__061_ = sexp_of_int b__060_ in
259259+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__061_ ] :: bnds__057_
260260+ : _ Stdlib.List.t)
261261+ in
262262+ let bnds__057_ =
263263+ let arg__059_ = sexp_of_int a__058_ in
264264+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__059_ ] :: bnds__057_
265265+ : _ Stdlib.List.t)
266266+ in
267267+ Sexplib0.Sexp.List bnds__057_
268268+ : t -> Sexplib0.Sexp.t)
269269+ ;;
270270+271271+ let _ = sexp_of_t
272272+273273+ let sexp_of_t__stack =
274274+ (fun { a = a__065_; b = b__067_; c = c__069_ } ->
275275+ let bnds__064_ = ([] : _ Stdlib.List.t) in
276276+ let bnds__064_ =
277277+ let arg__070_ = sexp_of_int__stack c__069_ in
278278+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__070_ ] :: bnds__064_
279279+ : _ Stdlib.List.t)
280280+ in
281281+ let bnds__064_ =
282282+ let arg__068_ = sexp_of_int__stack b__067_ in
283283+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__068_ ] :: bnds__064_
284284+ : _ Stdlib.List.t)
285285+ in
286286+ let bnds__064_ =
287287+ let arg__066_ = sexp_of_int__stack a__065_ in
288288+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__066_ ] :: bnds__064_
289289+ : _ Stdlib.List.t)
290290+ in
291291+ Sexplib0.Sexp.List bnds__064_
292292+ : t -> Sexplib0.Sexp.t)
293293+ ;;
294294+295295+ let _ = sexp_of_t__stack
296296+297297+ [@@@end]
298298+end
299299+300300+module Variant = struct
301301+ type t =
302302+ | A
303303+ | B of int * int
304304+ | C of
305305+ { a : int
306306+ ; b : int
307307+ ; d : int
308308+ }
309309+ | D of
310310+ { mutable a : int
311311+ ; mutable b : int
312312+ ; mutable t : int
313313+ }
314314+ [@@deriving_inline sexp ~stackify]
315315+316316+ let _ = fun (_ : t) -> ()
317317+318318+ let t_of_sexp =
319319+ (let error_source__073_ = "expansion.ml.Variant.t" in
320320+ function
321321+ | Sexplib0.Sexp.Atom ("a" | "A") -> A
322322+ | Sexplib0.Sexp.List
323323+ (Sexplib0.Sexp.Atom (("b" | "B") as _tag__076_) :: sexp_args__077_) as
324324+ _sexp__075_ ->
325325+ (match sexp_args__077_ with
326326+ | [ arg0__078_; arg1__079_ ] ->
327327+ let res0__080_ = int_of_sexp arg0__078_
328328+ and res1__081_ = int_of_sexp arg1__079_ in
329329+ B (res0__080_, res1__081_)
330330+ | _ ->
331331+ Sexplib0.Sexp_conv_error.stag_incorrect_n_args
332332+ error_source__073_
333333+ _tag__076_
334334+ _sexp__075_)
335335+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("c" | "C") :: sexps__089_) as sexp__088_ ->
336336+ Sexplib0.Sexp_conv_record.record_of_sexps
337337+ ~context:sexp__088_
338338+ ~caller:error_source__073_
339339+ ~fields:
340340+ (Field
341341+ { name = "a"
342342+ ; kind = Required
343343+ ; conv =
344344+ (fun x__086_ ->
345345+ let _x__087_ = int_of_sexp x__086_ in
346346+ fun () -> _x__087_)
347347+ ; rest =
348348+ Field
349349+ { name = "b"
350350+ ; kind = Required
351351+ ; conv =
352352+ (fun x__084_ ->
353353+ let _x__085_ = int_of_sexp x__084_ in
354354+ fun () -> _x__085_)
355355+ ; rest =
356356+ Field
357357+ { name = "d"
358358+ ; kind = Required
359359+ ; conv =
360360+ (fun x__082_ ->
361361+ let _x__083_ = int_of_sexp x__082_ in
362362+ fun () -> _x__083_)
363363+ ; rest = Empty
364364+ }
365365+ }
366366+ })
367367+ ~index_of_field:(function
368368+ | "a" -> 0
369369+ | "b" -> 1
370370+ | "d" -> 2
371371+ | _ -> -1)
372372+ ~allow_extra_fields:false
373373+ ~create:(fun (a, (b, (d, ()))) : t ->
374374+ let a = a () in
375375+ let b = b () in
376376+ let d = d () in
377377+ C { a; b; d })
378378+ sexps__089_
379379+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("d" | "D") :: sexps__097_) as sexp__096_ ->
380380+ Sexplib0.Sexp_conv_record.record_of_sexps
381381+ ~context:sexp__096_
382382+ ~caller:error_source__073_
383383+ ~fields:
384384+ (Field
385385+ { name = "a"
386386+ ; kind = Required
387387+ ; conv =
388388+ (fun x__094_ ->
389389+ let _x__095_ = int_of_sexp x__094_ in
390390+ fun () -> _x__095_)
391391+ ; rest =
392392+ Field
393393+ { name = "b"
394394+ ; kind = Required
395395+ ; conv =
396396+ (fun x__092_ ->
397397+ let _x__093_ = int_of_sexp x__092_ in
398398+ fun () -> _x__093_)
399399+ ; rest =
400400+ Field
401401+ { name = "t"
402402+ ; kind = Required
403403+ ; conv =
404404+ (fun x__090_ ->
405405+ let _x__091_ = int_of_sexp x__090_ in
406406+ fun () -> _x__091_)
407407+ ; rest = Empty
408408+ }
409409+ }
410410+ })
411411+ ~index_of_field:(function
412412+ | "a" -> 0
413413+ | "b" -> 1
414414+ | "t" -> 2
415415+ | _ -> -1)
416416+ ~allow_extra_fields:false
417417+ ~create:(fun (a, (b, (t, ()))) : t ->
418418+ let a = a () in
419419+ let b = b () in
420420+ let t = t () in
421421+ D { a; b; t })
422422+ sexps__097_
423423+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("a" | "A") :: _) as sexp__074_ ->
424424+ Sexplib0.Sexp_conv_error.stag_no_args error_source__073_ sexp__074_
425425+ | Sexplib0.Sexp.Atom ("b" | "B" | "c" | "C" | "d" | "D") as sexp__074_ ->
426426+ Sexplib0.Sexp_conv_error.stag_takes_args error_source__073_ sexp__074_
427427+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__072_ ->
428428+ Sexplib0.Sexp_conv_error.nested_list_invalid_sum error_source__073_ sexp__072_
429429+ | Sexplib0.Sexp.List [] as sexp__072_ ->
430430+ Sexplib0.Sexp_conv_error.empty_list_invalid_sum error_source__073_ sexp__072_
431431+ | sexp__072_ ->
432432+ Sexplib0.Sexp_conv_error.unexpected_stag
433433+ error_source__073_
434434+ [ "A"; "B"; "C"; "D" ]
435435+ sexp__072_
436436+ : Sexplib0.Sexp.t -> t)
437437+ ;;
438438+439439+ let _ = t_of_sexp
440440+441441+ let sexp_of_t =
442442+ (function
443443+ | A -> Sexplib0.Sexp.Atom "A"
444444+ | B (arg0__098_, arg1__099_) ->
445445+ let res0__100_ = sexp_of_int arg0__098_
446446+ and res1__101_ = sexp_of_int arg1__099_ in
447447+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "B"; res0__100_; res1__101_ ]
448448+ | C { a = a__103_; b = b__105_; d = d__107_ } ->
449449+ let bnds__102_ = ([] : _ Stdlib.List.t) in
450450+ let bnds__102_ =
451451+ let arg__108_ = sexp_of_int d__107_ in
452452+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "d"; arg__108_ ] :: bnds__102_
453453+ : _ Stdlib.List.t)
454454+ in
455455+ let bnds__102_ =
456456+ let arg__106_ = sexp_of_int b__105_ in
457457+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__106_ ] :: bnds__102_
458458+ : _ Stdlib.List.t)
459459+ in
460460+ let bnds__102_ =
461461+ let arg__104_ = sexp_of_int a__103_ in
462462+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__104_ ] :: bnds__102_
463463+ : _ Stdlib.List.t)
464464+ in
465465+ Sexplib0.Sexp.List (Sexplib0.Sexp.Atom "C" :: bnds__102_)
466466+ | D { a = a__110_; b = b__112_; t = t__114_ } ->
467467+ let bnds__109_ = ([] : _ Stdlib.List.t) in
468468+ let bnds__109_ =
469469+ let arg__115_ = sexp_of_int t__114_ in
470470+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "t"; arg__115_ ] :: bnds__109_
471471+ : _ Stdlib.List.t)
472472+ in
473473+ let bnds__109_ =
474474+ let arg__113_ = sexp_of_int b__112_ in
475475+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__113_ ] :: bnds__109_
476476+ : _ Stdlib.List.t)
477477+ in
478478+ let bnds__109_ =
479479+ let arg__111_ = sexp_of_int a__110_ in
480480+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__111_ ] :: bnds__109_
481481+ : _ Stdlib.List.t)
482482+ in
483483+ Sexplib0.Sexp.List (Sexplib0.Sexp.Atom "D" :: bnds__109_)
484484+ : t -> Sexplib0.Sexp.t)
485485+ ;;
486486+487487+ let _ = sexp_of_t
488488+489489+ let sexp_of_t__stack =
490490+ (function
491491+ | A -> Sexplib0.Sexp.Atom "A"
492492+ | B (arg0__116_, arg1__117_) ->
493493+ let res0__118_ = sexp_of_int__stack arg0__116_
494494+ and res1__119_ = sexp_of_int__stack arg1__117_ in
495495+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "B"; res0__118_; res1__119_ ]
496496+ | C { a = a__121_; b = b__123_; d = d__125_ } ->
497497+ let bnds__120_ = ([] : _ Stdlib.List.t) in
498498+ let bnds__120_ =
499499+ let arg__126_ = sexp_of_int__stack d__125_ in
500500+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "d"; arg__126_ ] :: bnds__120_
501501+ : _ Stdlib.List.t)
502502+ in
503503+ let bnds__120_ =
504504+ let arg__124_ = sexp_of_int__stack b__123_ in
505505+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__124_ ] :: bnds__120_
506506+ : _ Stdlib.List.t)
507507+ in
508508+ let bnds__120_ =
509509+ let arg__122_ = sexp_of_int__stack a__121_ in
510510+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__122_ ] :: bnds__120_
511511+ : _ Stdlib.List.t)
512512+ in
513513+ Sexplib0.Sexp.List (Sexplib0.Sexp.Atom "C" :: bnds__120_)
514514+ | D { a = a__128_; b = b__130_; t = t__132_ } ->
515515+ let bnds__127_ = ([] : _ Stdlib.List.t) in
516516+ let bnds__127_ =
517517+ let arg__133_ = sexp_of_int__stack t__132_ in
518518+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "t"; arg__133_ ] :: bnds__127_
519519+ : _ Stdlib.List.t)
520520+ in
521521+ let bnds__127_ =
522522+ let arg__131_ = sexp_of_int__stack b__130_ in
523523+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__131_ ] :: bnds__127_
524524+ : _ Stdlib.List.t)
525525+ in
526526+ let bnds__127_ =
527527+ let arg__129_ = sexp_of_int__stack a__128_ in
528528+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__129_ ] :: bnds__127_
529529+ : _ Stdlib.List.t)
530530+ in
531531+ Sexplib0.Sexp.List (Sexplib0.Sexp.Atom "D" :: bnds__127_)
532532+ : t -> Sexplib0.Sexp.t)
533533+ ;;
534534+535535+ let _ = sexp_of_t__stack
536536+537537+ [@@@end]
538538+end
539539+540540+module Poly_variant = struct
541541+ type t =
542542+ [ `A
543543+ | `B of int
544544+ ]
545545+ [@@deriving_inline sexp ~stackify]
546546+547547+ let _ = fun (_ : t) -> ()
548548+549549+ let __t_of_sexp__ =
550550+ (let error_source__139_ = "expansion.ml.Poly_variant.t" in
551551+ function
552552+ | Sexplib0.Sexp.Atom atom__135_ as _sexp__137_ ->
553553+ (match atom__135_ with
554554+ | "A" -> `A
555555+ | "B" -> Sexplib0.Sexp_conv_error.ptag_takes_args error_source__139_ _sexp__137_
556556+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
557557+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom atom__135_ :: sexp_args__138_) as
558558+ _sexp__137_ ->
559559+ (match atom__135_ with
560560+ | "B" as _tag__140_ ->
561561+ (match sexp_args__138_ with
562562+ | arg0__141_ :: [] ->
563563+ let res0__142_ = int_of_sexp arg0__141_ in
564564+ `B res0__142_
565565+ | _ ->
566566+ Sexplib0.Sexp_conv_error.ptag_incorrect_n_args
567567+ error_source__139_
568568+ _tag__140_
569569+ _sexp__137_)
570570+ | "A" -> Sexplib0.Sexp_conv_error.ptag_no_args error_source__139_ _sexp__137_
571571+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
572572+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__136_ ->
573573+ Sexplib0.Sexp_conv_error.nested_list_invalid_poly_var error_source__139_ sexp__136_
574574+ | Sexplib0.Sexp.List [] as sexp__136_ ->
575575+ Sexplib0.Sexp_conv_error.empty_list_invalid_poly_var error_source__139_ sexp__136_
576576+ : Sexplib0.Sexp.t -> t)
577577+ ;;
578578+579579+ let _ = __t_of_sexp__
580580+581581+ let t_of_sexp =
582582+ (let error_source__144_ = "expansion.ml.Poly_variant.t" in
583583+ fun sexp__143_ ->
584584+ try __t_of_sexp__ sexp__143_ with
585585+ | Sexplib0.Sexp_conv_error.No_variant_match ->
586586+ Sexplib0.Sexp_conv_error.no_matching_variant_found error_source__144_ sexp__143_
587587+ : Sexplib0.Sexp.t -> t)
588588+ ;;
589589+590590+ let _ = t_of_sexp
591591+592592+ let sexp_of_t =
593593+ (function
594594+ | `A -> Sexplib0.Sexp.Atom "A"
595595+ | `B v__145_ -> Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "B"; sexp_of_int v__145_ ]
596596+ : t -> Sexplib0.Sexp.t)
597597+ ;;
598598+599599+ let _ = sexp_of_t
600600+601601+ let sexp_of_t__stack =
602602+ (function
603603+ | `A -> Sexplib0.Sexp.Atom "A"
604604+ | `B v__146_ ->
605605+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "B"; sexp_of_int__stack v__146_ ]
606606+ : t -> Sexplib0.Sexp.t)
607607+ ;;
608608+609609+ let _ = sexp_of_t__stack
610610+611611+ [@@@end]
612612+end
613613+614614+module Inline_poly_variant = struct
615615+ type t =
616616+ [ Poly_variant.t
617617+ | `C of int * int
618618+ ]
619619+ [@@deriving_inline sexp]
620620+621621+ let _ = fun (_ : t) -> ()
622622+623623+ let __t_of_sexp__ =
624624+ (let error_source__158_ = "expansion.ml.Inline_poly_variant.t" in
625625+ fun sexp__147_ ->
626626+ try (Poly_variant.__t_of_sexp__ sexp__147_ :> t) with
627627+ | Sexplib0.Sexp_conv_error.No_variant_match ->
628628+ (match sexp__147_ with
629629+ | Sexplib0.Sexp.Atom atom__148_ as _sexp__150_ ->
630630+ (match atom__148_ with
631631+ | "C" ->
632632+ Sexplib0.Sexp_conv_error.ptag_takes_args error_source__158_ _sexp__150_
633633+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
634634+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom atom__148_ :: sexp_args__151_) as
635635+ _sexp__150_ ->
636636+ (match atom__148_ with
637637+ | "C" as _tag__152_ ->
638638+ (match sexp_args__151_ with
639639+ | arg0__159_ :: [] ->
640640+ let res0__160_ =
641641+ match arg0__159_ with
642642+ | Sexplib0.Sexp.List [ arg0__153_; arg1__154_ ] ->
643643+ let res0__155_ = int_of_sexp arg0__153_
644644+ and res1__156_ = int_of_sexp arg1__154_ in
645645+ res0__155_, res1__156_
646646+ | sexp__157_ ->
647647+ Sexplib0.Sexp_conv_error.tuple_of_size_n_expected
648648+ error_source__158_
649649+ 2
650650+ sexp__157_
651651+ in
652652+ `C res0__160_
653653+ | _ ->
654654+ Sexplib0.Sexp_conv_error.ptag_incorrect_n_args
655655+ error_source__158_
656656+ _tag__152_
657657+ _sexp__150_)
658658+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
659659+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__149_ ->
660660+ Sexplib0.Sexp_conv_error.nested_list_invalid_poly_var
661661+ error_source__158_
662662+ sexp__149_
663663+ | Sexplib0.Sexp.List [] as sexp__149_ ->
664664+ Sexplib0.Sexp_conv_error.empty_list_invalid_poly_var
665665+ error_source__158_
666666+ sexp__149_)
667667+ : Sexplib0.Sexp.t -> t)
668668+ ;;
669669+670670+ let _ = __t_of_sexp__
671671+672672+ let t_of_sexp =
673673+ (let error_source__162_ = "expansion.ml.Inline_poly_variant.t" in
674674+ fun sexp__161_ ->
675675+ try __t_of_sexp__ sexp__161_ with
676676+ | Sexplib0.Sexp_conv_error.No_variant_match ->
677677+ Sexplib0.Sexp_conv_error.no_matching_variant_found error_source__162_ sexp__161_
678678+ : Sexplib0.Sexp.t -> t)
679679+ ;;
680680+681681+ let _ = t_of_sexp
682682+683683+ let sexp_of_t =
684684+ (function
685685+ | #Poly_variant.t as v__163_ -> Poly_variant.sexp_of_t v__163_
686686+ | `C v__164_ ->
687687+ Sexplib0.Sexp.List
688688+ [ Sexplib0.Sexp.Atom "C"
689689+ ; (let arg0__165_, arg1__166_ = v__164_ in
690690+ let res0__167_ = sexp_of_int arg0__165_
691691+ and res1__168_ = sexp_of_int arg1__166_ in
692692+ Sexplib0.Sexp.List [ res0__167_; res1__168_ ])
693693+ ]
694694+ : t -> Sexplib0.Sexp.t)
695695+ ;;
696696+697697+ let _ = sexp_of_t
698698+699699+ [@@@end]
700700+end
701701+702702+module Recursive = struct
703703+ type t =
704704+ | Banana of t
705705+ | Orange
706706+ [@@deriving_inline sexp]
707707+708708+ let _ = fun (_ : t) -> ()
709709+710710+ let rec t_of_sexp =
711711+ (let error_source__171_ = "expansion.ml.Recursive.t" in
712712+ function
713713+ | Sexplib0.Sexp.List
714714+ (Sexplib0.Sexp.Atom (("banana" | "Banana") as _tag__174_) :: sexp_args__175_) as
715715+ _sexp__173_ ->
716716+ (match sexp_args__175_ with
717717+ | arg0__176_ :: [] ->
718718+ let res0__177_ = t_of_sexp arg0__176_ in
719719+ Banana res0__177_
720720+ | _ ->
721721+ Sexplib0.Sexp_conv_error.stag_incorrect_n_args
722722+ error_source__171_
723723+ _tag__174_
724724+ _sexp__173_)
725725+ | Sexplib0.Sexp.Atom ("orange" | "Orange") -> Orange
726726+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("orange" | "Orange") :: _) as sexp__172_ ->
727727+ Sexplib0.Sexp_conv_error.stag_no_args error_source__171_ sexp__172_
728728+ | Sexplib0.Sexp.Atom ("banana" | "Banana") as sexp__172_ ->
729729+ Sexplib0.Sexp_conv_error.stag_takes_args error_source__171_ sexp__172_
730730+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__170_ ->
731731+ Sexplib0.Sexp_conv_error.nested_list_invalid_sum error_source__171_ sexp__170_
732732+ | Sexplib0.Sexp.List [] as sexp__170_ ->
733733+ Sexplib0.Sexp_conv_error.empty_list_invalid_sum error_source__171_ sexp__170_
734734+ | sexp__170_ ->
735735+ Sexplib0.Sexp_conv_error.unexpected_stag
736736+ error_source__171_
737737+ [ "Banana"; "Orange" ]
738738+ sexp__170_
739739+ : Sexplib0.Sexp.t -> t)
740740+ ;;
741741+742742+ let _ = t_of_sexp
743743+744744+ let rec sexp_of_t =
745745+ (function
746746+ | Banana arg0__178_ ->
747747+ let res0__179_ = sexp_of_t arg0__178_ in
748748+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "Banana"; res0__179_ ]
749749+ | Orange -> Sexplib0.Sexp.Atom "Orange"
750750+ : t -> Sexplib0.Sexp.t)
751751+ ;;
752752+753753+ let _ = sexp_of_t
754754+755755+ [@@@end]
756756+end
757757+758758+module Nonrecursive = struct
759759+ open Recursive
760760+761761+ type nonrec t = t [@@deriving_inline sexp]
762762+763763+ let _ = fun (_ : t) -> ()
764764+ let t_of_sexp = (t_of_sexp : Sexplib0.Sexp.t -> t)
765765+ let _ = t_of_sexp
766766+ let sexp_of_t = (sexp_of_t : t -> Sexplib0.Sexp.t)
767767+ let _ = sexp_of_t
768768+769769+ [@@@end]
770770+end
771771+772772+module Mutually_recursive = struct
773773+ type a =
774774+ | A
775775+ | B of b
776776+ | C of
777777+ { a : a
778778+ ; b : b
779779+ ; c : c
780780+ }
781781+782782+ and b =
783783+ { a : a
784784+ ; b : b
785785+ }
786786+787787+ and c = a [@@deriving_inline sexp]
788788+789789+ let _ = fun (_ : a) -> ()
790790+ let _ = fun (_ : b) -> ()
791791+ let _ = fun (_ : c) -> ()
792792+793793+ let rec a_of_sexp =
794794+ (let error_source__183_ = "expansion.ml.Mutually_recursive.a" in
795795+ function
796796+ | Sexplib0.Sexp.Atom ("a" | "A") -> A
797797+ | Sexplib0.Sexp.List
798798+ (Sexplib0.Sexp.Atom (("b" | "B") as _tag__186_) :: sexp_args__187_) as
799799+ _sexp__185_ ->
800800+ (match sexp_args__187_ with
801801+ | arg0__188_ :: [] ->
802802+ let res0__189_ = b_of_sexp arg0__188_ in
803803+ B res0__189_
804804+ | _ ->
805805+ Sexplib0.Sexp_conv_error.stag_incorrect_n_args
806806+ error_source__183_
807807+ _tag__186_
808808+ _sexp__185_)
809809+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("c" | "C") :: sexps__197_) as sexp__196_ ->
810810+ Sexplib0.Sexp_conv_record.record_of_sexps
811811+ ~context:sexp__196_
812812+ ~caller:error_source__183_
813813+ ~fields:
814814+ (Field
815815+ { name = "a"
816816+ ; kind = Required
817817+ ; conv =
818818+ (fun x__194_ ->
819819+ let _x__195_ = a_of_sexp x__194_ in
820820+ fun () -> _x__195_)
821821+ ; rest =
822822+ Field
823823+ { name = "b"
824824+ ; kind = Required
825825+ ; conv =
826826+ (fun x__192_ ->
827827+ let _x__193_ = b_of_sexp x__192_ in
828828+ fun () -> _x__193_)
829829+ ; rest =
830830+ Field
831831+ { name = "c"
832832+ ; kind = Required
833833+ ; conv =
834834+ (fun x__190_ ->
835835+ let _x__191_ = c_of_sexp x__190_ in
836836+ fun () -> _x__191_)
837837+ ; rest = Empty
838838+ }
839839+ }
840840+ })
841841+ ~index_of_field:(function
842842+ | "a" -> 0
843843+ | "b" -> 1
844844+ | "c" -> 2
845845+ | _ -> -1)
846846+ ~allow_extra_fields:false
847847+ ~create:(fun (a, (b, (c, ()))) : a ->
848848+ let a = a () in
849849+ let b = b () in
850850+ let c = c () in
851851+ C { a; b; c })
852852+ sexps__197_
853853+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("a" | "A") :: _) as sexp__184_ ->
854854+ Sexplib0.Sexp_conv_error.stag_no_args error_source__183_ sexp__184_
855855+ | Sexplib0.Sexp.Atom ("b" | "B" | "c" | "C") as sexp__184_ ->
856856+ Sexplib0.Sexp_conv_error.stag_takes_args error_source__183_ sexp__184_
857857+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__182_ ->
858858+ Sexplib0.Sexp_conv_error.nested_list_invalid_sum error_source__183_ sexp__182_
859859+ | Sexplib0.Sexp.List [] as sexp__182_ ->
860860+ Sexplib0.Sexp_conv_error.empty_list_invalid_sum error_source__183_ sexp__182_
861861+ | sexp__182_ ->
862862+ Sexplib0.Sexp_conv_error.unexpected_stag
863863+ error_source__183_
864864+ [ "A"; "B"; "C" ]
865865+ sexp__182_
866866+ : Sexplib0.Sexp.t -> a)
867867+868868+ and b_of_sexp =
869869+ (let error_source__199_ = "expansion.ml.Mutually_recursive.b" in
870870+ fun x__204_ ->
871871+ Sexplib0.Sexp_conv_record.record_of_sexp
872872+ ~caller:error_source__199_
873873+ ~fields:
874874+ (Field
875875+ { name = "a"
876876+ ; kind = Required
877877+ ; conv =
878878+ (fun x__202_ ->
879879+ let _x__203_ = a_of_sexp x__202_ in
880880+ fun () -> _x__203_)
881881+ ; rest =
882882+ Field
883883+ { name = "b"
884884+ ; kind = Required
885885+ ; conv =
886886+ (fun x__200_ ->
887887+ let _x__201_ = b_of_sexp x__200_ in
888888+ fun () -> _x__201_)
889889+ ; rest = Empty
890890+ }
891891+ })
892892+ ~index_of_field:(function
893893+ | "a" -> 0
894894+ | "b" -> 1
895895+ | _ -> -1)
896896+ ~allow_extra_fields:false
897897+ ~create:(fun (a, (b, ())) : b ->
898898+ let a = a () in
899899+ let b = b () in
900900+ { a; b })
901901+ x__204_
902902+ : Sexplib0.Sexp.t -> b)
903903+904904+ and c_of_sexp = (fun x__206_ -> a_of_sexp x__206_ : Sexplib0.Sexp.t -> c)
905905+906906+ let _ = a_of_sexp
907907+ and _ = b_of_sexp
908908+ and _ = c_of_sexp
909909+910910+ let rec sexp_of_a =
911911+ (function
912912+ | A -> Sexplib0.Sexp.Atom "A"
913913+ | B arg0__207_ ->
914914+ let res0__208_ = sexp_of_b arg0__207_ in
915915+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "B"; res0__208_ ]
916916+ | C { a = a__210_; b = b__212_; c = c__214_ } ->
917917+ let bnds__209_ = ([] : _ Stdlib.List.t) in
918918+ let bnds__209_ =
919919+ let arg__215_ = sexp_of_c c__214_ in
920920+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__215_ ] :: bnds__209_
921921+ : _ Stdlib.List.t)
922922+ in
923923+ let bnds__209_ =
924924+ let arg__213_ = sexp_of_b b__212_ in
925925+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__213_ ] :: bnds__209_
926926+ : _ Stdlib.List.t)
927927+ in
928928+ let bnds__209_ =
929929+ let arg__211_ = sexp_of_a a__210_ in
930930+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__211_ ] :: bnds__209_
931931+ : _ Stdlib.List.t)
932932+ in
933933+ Sexplib0.Sexp.List (Sexplib0.Sexp.Atom "C" :: bnds__209_)
934934+ : a -> Sexplib0.Sexp.t)
935935+936936+ and sexp_of_b =
937937+ (fun { a = a__217_; b = b__219_ } ->
938938+ let bnds__216_ = ([] : _ Stdlib.List.t) in
939939+ let bnds__216_ =
940940+ let arg__220_ = sexp_of_b b__219_ in
941941+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__220_ ] :: bnds__216_
942942+ : _ Stdlib.List.t)
943943+ in
944944+ let bnds__216_ =
945945+ let arg__218_ = sexp_of_a a__217_ in
946946+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__218_ ] :: bnds__216_
947947+ : _ Stdlib.List.t)
948948+ in
949949+ Sexplib0.Sexp.List bnds__216_
950950+ : b -> Sexplib0.Sexp.t)
951951+952952+ and sexp_of_c = (fun x__221_ -> sexp_of_a x__221_ : c -> Sexplib0.Sexp.t)
953953+954954+ let _ = sexp_of_a
955955+ and _ = sexp_of_b
956956+ and _ = sexp_of_c
957957+958958+ [@@@end]
959959+end
960960+961961+module Alias = struct
962962+ type t = Recursive.t [@@deriving_inline sexp]
963963+964964+ let _ = fun (_ : t) -> ()
965965+ let t_of_sexp = (Recursive.t_of_sexp : Sexplib0.Sexp.t -> t)
966966+ let _ = t_of_sexp
967967+ let sexp_of_t = (Recursive.sexp_of_t : t -> Sexplib0.Sexp.t)
968968+ let _ = sexp_of_t
969969+970970+ [@@@end]
971971+end
972972+973973+module Re_export = struct
974974+ type t = Recursive.t =
975975+ | Banana of t
976976+ | Orange
977977+ [@@deriving_inline sexp]
978978+979979+ let _ = fun (_ : t) -> ()
980980+981981+ let rec t_of_sexp =
982982+ (let error_source__225_ = "expansion.ml.Re_export.t" in
983983+ function
984984+ | Sexplib0.Sexp.List
985985+ (Sexplib0.Sexp.Atom (("banana" | "Banana") as _tag__228_) :: sexp_args__229_) as
986986+ _sexp__227_ ->
987987+ (match sexp_args__229_ with
988988+ | arg0__230_ :: [] ->
989989+ let res0__231_ = t_of_sexp arg0__230_ in
990990+ Banana res0__231_
991991+ | _ ->
992992+ Sexplib0.Sexp_conv_error.stag_incorrect_n_args
993993+ error_source__225_
994994+ _tag__228_
995995+ _sexp__227_)
996996+ | Sexplib0.Sexp.Atom ("orange" | "Orange") -> Orange
997997+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom ("orange" | "Orange") :: _) as sexp__226_ ->
998998+ Sexplib0.Sexp_conv_error.stag_no_args error_source__225_ sexp__226_
999999+ | Sexplib0.Sexp.Atom ("banana" | "Banana") as sexp__226_ ->
10001000+ Sexplib0.Sexp_conv_error.stag_takes_args error_source__225_ sexp__226_
10011001+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__224_ ->
10021002+ Sexplib0.Sexp_conv_error.nested_list_invalid_sum error_source__225_ sexp__224_
10031003+ | Sexplib0.Sexp.List [] as sexp__224_ ->
10041004+ Sexplib0.Sexp_conv_error.empty_list_invalid_sum error_source__225_ sexp__224_
10051005+ | sexp__224_ ->
10061006+ Sexplib0.Sexp_conv_error.unexpected_stag
10071007+ error_source__225_
10081008+ [ "Banana"; "Orange" ]
10091009+ sexp__224_
10101010+ : Sexplib0.Sexp.t -> t)
10111011+ ;;
10121012+10131013+ let _ = t_of_sexp
10141014+10151015+ let rec sexp_of_t =
10161016+ (function
10171017+ | Banana arg0__232_ ->
10181018+ let res0__233_ = sexp_of_t arg0__232_ in
10191019+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "Banana"; res0__233_ ]
10201020+ | Orange -> Sexplib0.Sexp.Atom "Orange"
10211021+ : t -> Sexplib0.Sexp.t)
10221022+ ;;
10231023+10241024+ let _ = sexp_of_t
10251025+10261026+ [@@@end]
10271027+end
10281028+10291029+module Unary = struct
10301030+ type 'a t = 'a list option [@@deriving_inline sexp]
10311031+10321032+ let _ = fun (_ : 'a t) -> ()
10331033+10341034+ let t_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t =
10351035+ fun _of_a__234_ x__236_ -> option_of_sexp (list_of_sexp _of_a__234_) x__236_
10361036+ ;;
10371037+10381038+ let _ = t_of_sexp
10391039+10401040+ let sexp_of_t : 'a. ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t =
10411041+ fun _of_a__237_ x__238_ -> sexp_of_option (sexp_of_list _of_a__237_) x__238_
10421042+ ;;
10431043+10441044+ let _ = sexp_of_t
10451045+10461046+ [@@@end]
10471047+end
10481048+10491049+module Binary = struct
10501050+ type ('a, 'b) t = ('a, 'b) Either.t [@@deriving_inline sexp]
10511051+10521052+ let _ = fun (_ : ('a, 'b) t) -> ()
10531053+10541054+ let t_of_sexp
10551055+ : 'a 'b.
10561056+ (Sexplib0.Sexp.t -> 'a) -> (Sexplib0.Sexp.t -> 'b) -> Sexplib0.Sexp.t -> ('a, 'b) t
10571057+ =
10581058+ Either.t_of_sexp
10591059+ ;;
10601060+10611061+ let _ = t_of_sexp
10621062+10631063+ let sexp_of_t
10641064+ : 'a 'b.
10651065+ ('a -> Sexplib0.Sexp.t) -> ('b -> Sexplib0.Sexp.t) -> ('a, 'b) t -> Sexplib0.Sexp.t
10661066+ =
10671067+ Either.sexp_of_t
10681068+ ;;
10691069+10701070+ let _ = sexp_of_t
10711071+10721072+ [@@@end]
10731073+end
10741074+10751075+module First_order = struct
10761076+ type 'a t = 'a -> 'a [@@deriving_inline sexp]
10771077+10781078+ let _ = fun (_ : 'a t) -> ()
10791079+10801080+ let t_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a t =
10811081+ fun _of_a__246_ -> Sexplib0.Sexp_conv.fun_of_sexp
10821082+ ;;
10831083+10841084+ let _ = t_of_sexp
10851085+10861086+ let sexp_of_t : 'a. ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t =
10871087+ fun _of_a__248_ _ -> Sexplib0.Sexp_conv.sexp_of_fun Sexplib0.Sexp_conv.ignore
10881088+ ;;
10891089+10901090+ let _ = sexp_of_t
10911091+10921092+ [@@@end]
10931093+end
10941094+10951095+module Second_order = struct
10961096+ type ('a, 'b) t = ('a -> 'a) -> ('a -> 'b) -> ('b -> 'b) -> 'a -> 'b
10971097+ [@@deriving_inline sexp]
10981098+10991099+ let _ = fun (_ : ('a, 'b) t) -> ()
11001100+11011101+ let t_of_sexp
11021102+ : 'a 'b.
11031103+ (Sexplib0.Sexp.t -> 'a) -> (Sexplib0.Sexp.t -> 'b) -> Sexplib0.Sexp.t -> ('a, 'b) t
11041104+ =
11051105+ fun _of_a__249_ _of_b__250_ -> Sexplib0.Sexp_conv.fun_of_sexp
11061106+ ;;
11071107+11081108+ let _ = t_of_sexp
11091109+11101110+ let sexp_of_t
11111111+ : 'a 'b.
11121112+ ('a -> Sexplib0.Sexp.t) -> ('b -> Sexplib0.Sexp.t) -> ('a, 'b) t -> Sexplib0.Sexp.t
11131113+ =
11141114+ fun _of_a__252_ _of_b__253_ _ ->
11151115+ Sexplib0.Sexp_conv.sexp_of_fun Sexplib0.Sexp_conv.ignore
11161116+ ;;
11171117+11181118+ let _ = sexp_of_t
11191119+11201120+ [@@@end]
11211121+end
11221122+11231123+module Named_arguments = struct
11241124+ type t = ?a:int -> b:int -> int -> int [@@deriving_inline sexp]
11251125+11261126+ let _ = fun (_ : t) -> ()
11271127+ let t_of_sexp = (Sexplib0.Sexp_conv.fun_of_sexp : Sexplib0.Sexp.t -> t)
11281128+ let _ = t_of_sexp
11291129+11301130+ let sexp_of_t =
11311131+ (fun _ -> Sexplib0.Sexp_conv.sexp_of_fun Sexplib0.Sexp_conv.ignore
11321132+ : t -> Sexplib0.Sexp.t)
11331133+ ;;
11341134+11351135+ let _ = sexp_of_t
11361136+11371137+ [@@@end]
11381138+end
11391139+11401140+module Gadt = struct
11411141+ type _ t =
11421142+ | A : _ option t
11431143+ | B : int -> int t
11441144+ | C : 'a list -> unit t
11451145+ [@@deriving_inline sexp_of]
11461146+11471147+ let _ = fun (_ : _ t) -> ()
11481148+11491149+ let sexp_of_t : 'a__255_. ('a__255_ -> Sexplib0.Sexp.t) -> 'a__255_ t -> Sexplib0.Sexp.t
11501150+ =
11511151+ fun (type a__261_) : ((a__261_ -> Sexplib0.Sexp.t) -> a__261_ t -> Sexplib0.Sexp.t) ->
11521152+ fun _of_a__256_ -> function
11531153+ | A -> Sexplib0.Sexp.Atom "A"
11541154+ | B arg0__257_ ->
11551155+ let res0__258_ = sexp_of_int arg0__257_ in
11561156+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "B"; res0__258_ ]
11571157+ | C arg0__259_ ->
11581158+ let res0__260_ = sexp_of_list (fun _ -> Sexplib0.Sexp.Atom "_") arg0__259_ in
11591159+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "C"; res0__260_ ]
11601160+ ;;
11611161+11621162+ let _ = sexp_of_t
11631163+11641164+ [@@@end]
11651165+end
11661166+11671167+module Recursive_record_containing_variant = struct
11681168+ type t =
11691169+ { a : [ `A of t ]
11701170+ ; b : [ `B ] [@sexp_drop_default Poly.equal] [@default `B]
11711171+ }
11721172+ [@@deriving_inline sexp]
11731173+11741174+ let _ = fun (_ : t) -> ()
11751175+11761176+ let rec t_of_sexp =
11771177+ (let default__264_ : [ `B ] = `B in
11781178+ let error_source__263_ = "expansion.ml.Recursive_record_containing_variant.t" in
11791179+ fun x__284_ ->
11801180+ Sexplib0.Sexp_conv_record.record_of_sexp
11811181+ ~caller:error_source__263_
11821182+ ~fields:
11831183+ (Field
11841184+ { name = "a"
11851185+ ; kind = Required
11861186+ ; conv =
11871187+ (fun x__282_ ->
11881188+ let _x__283_ =
11891189+ (fun sexp__281_ ->
11901190+ try
11911191+ match sexp__281_ with
11921192+ | Sexplib0.Sexp.Atom atom__274_ as _sexp__276_ ->
11931193+ (match atom__274_ with
11941194+ | "A" ->
11951195+ Sexplib0.Sexp_conv_error.ptag_takes_args
11961196+ error_source__263_
11971197+ _sexp__276_
11981198+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
11991199+ | Sexplib0.Sexp.List
12001200+ (Sexplib0.Sexp.Atom atom__274_ :: sexp_args__277_) as
12011201+ _sexp__276_ ->
12021202+ (match atom__274_ with
12031203+ | "A" as _tag__278_ ->
12041204+ (match sexp_args__277_ with
12051205+ | arg0__279_ :: [] ->
12061206+ let res0__280_ = t_of_sexp arg0__279_ in
12071207+ `A res0__280_
12081208+ | _ ->
12091209+ Sexplib0.Sexp_conv_error.ptag_incorrect_n_args
12101210+ error_source__263_
12111211+ _tag__278_
12121212+ _sexp__276_)
12131213+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
12141214+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__275_
12151215+ ->
12161216+ Sexplib0.Sexp_conv_error.nested_list_invalid_poly_var
12171217+ error_source__263_
12181218+ sexp__275_
12191219+ | Sexplib0.Sexp.List [] as sexp__275_ ->
12201220+ Sexplib0.Sexp_conv_error.empty_list_invalid_poly_var
12211221+ error_source__263_
12221222+ sexp__275_
12231223+ with
12241224+ | Sexplib0.Sexp_conv_error.No_variant_match ->
12251225+ Sexplib0.Sexp_conv_error.no_matching_variant_found
12261226+ error_source__263_
12271227+ sexp__281_)
12281228+ x__282_
12291229+ in
12301230+ fun () -> _x__283_)
12311231+ ; rest =
12321232+ Field
12331233+ { name = "b"
12341234+ ; kind = Default (fun () -> default__264_)
12351235+ ; conv =
12361236+ (fun x__271_ ->
12371237+ let _x__272_ =
12381238+ (fun sexp__270_ ->
12391239+ try
12401240+ match sexp__270_ with
12411241+ | Sexplib0.Sexp.Atom atom__266_ as _sexp__268_ ->
12421242+ (match atom__266_ with
12431243+ | "B" -> `B
12441244+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
12451245+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom atom__266_ :: _)
12461246+ as _sexp__268_ ->
12471247+ (match atom__266_ with
12481248+ | "B" ->
12491249+ Sexplib0.Sexp_conv_error.ptag_no_args
12501250+ error_source__263_
12511251+ _sexp__268_
12521252+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
12531253+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as
12541254+ sexp__267_ ->
12551255+ Sexplib0.Sexp_conv_error.nested_list_invalid_poly_var
12561256+ error_source__263_
12571257+ sexp__267_
12581258+ | Sexplib0.Sexp.List [] as sexp__267_ ->
12591259+ Sexplib0.Sexp_conv_error.empty_list_invalid_poly_var
12601260+ error_source__263_
12611261+ sexp__267_
12621262+ with
12631263+ | Sexplib0.Sexp_conv_error.No_variant_match ->
12641264+ Sexplib0.Sexp_conv_error.no_matching_variant_found
12651265+ error_source__263_
12661266+ sexp__270_)
12671267+ x__271_
12681268+ in
12691269+ fun () -> _x__272_)
12701270+ ; rest = Empty
12711271+ }
12721272+ })
12731273+ ~index_of_field:(function
12741274+ | "a" -> 0
12751275+ | "b" -> 1
12761276+ | _ -> -1)
12771277+ ~allow_extra_fields:false
12781278+ ~create:(fun (a, (b, ())) : t ->
12791279+ let a = a () in
12801280+ let b = b () in
12811281+ { a; b })
12821282+ x__284_
12831283+ : Sexplib0.Sexp.t -> t)
12841284+ ;;
12851285+12861286+ let _ = t_of_sexp
12871287+12881288+ let rec sexp_of_t =
12891289+ (let default__291_ : [ `B ] = `B
12901290+ and drop_default__290_ : [ `B ] -> [ `B ] -> Stdlib.Bool.t = Poly.equal in
12911291+ fun { a = a__286_; b = b__292_ } ->
12921292+ let bnds__285_ = ([] : _ Stdlib.List.t) in
12931293+ let bnds__285_ =
12941294+ if drop_default__290_ default__291_ b__292_
12951295+ then bnds__285_
12961296+ else (
12971297+ let arg__294_ = (fun `B -> Sexplib0.Sexp.Atom "B") b__292_ in
12981298+ let bnd__293_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__294_ ] in
12991299+ (bnd__293_ :: bnds__285_ : _ Stdlib.List.t))
13001300+ in
13011301+ let bnds__285_ =
13021302+ let arg__287_ =
13031303+ let (`A v__288_) = a__286_ in
13041304+ Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "A"; sexp_of_t v__288_ ]
13051305+ in
13061306+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__287_ ] :: bnds__285_
13071307+ : _ Stdlib.List.t)
13081308+ in
13091309+ Sexplib0.Sexp.List bnds__285_
13101310+ : t -> Sexplib0.Sexp.t)
13111311+ ;;
13121312+13131313+ let _ = sexp_of_t
13141314+13151315+ [@@@end]
13161316+end
13171317+13181318+module Poly_record = struct
13191319+ type t =
13201320+ { a : 'a. 'a list
13211321+ ; b : 'b. 'b option
13221322+ ; c : 'c. 'c
13231323+ }
13241324+ [@@deriving_inline sexp]
13251325+13261326+ let _ = fun (_ : t) -> ()
13271327+13281328+ let t_of_sexp =
13291329+ (let error_source__296_ = "expansion.ml.Poly_record.t" in
13301330+ fun x__309_ ->
13311331+ let open struct
13321332+ type a__297_ = { a__297_ : 'a. 'a list } [@@unboxed]
13331333+ type b__298_ = { b__298_ : 'b. 'b option } [@@unboxed]
13341334+ type c__299_ = { c__299_ : 'c. 'c } [@@unboxed]
13351335+ end in
13361336+ Sexplib0.Sexp_conv_record.record_of_sexp
13371337+ ~caller:error_source__296_
13381338+ ~fields:
13391339+ (Field
13401340+ { name = "a"
13411341+ ; kind = Required
13421342+ ; conv =
13431343+ (fun sexp__306_ ->
13441344+ let _x__308_ =
13451345+ { a__297_ =
13461346+ (let _a__307_ =
13471347+ Sexplib0.Sexp_conv_error.record_poly_field_value
13481348+ error_source__296_
13491349+ in
13501350+ list_of_sexp _a__307_ sexp__306_)
13511351+ }
13521352+ in
13531353+ fun () -> _x__308_)
13541354+ ; rest =
13551355+ Field
13561356+ { name = "b"
13571357+ ; kind = Required
13581358+ ; conv =
13591359+ (fun sexp__303_ ->
13601360+ let _x__305_ =
13611361+ { b__298_ =
13621362+ (let _b__304_ =
13631363+ Sexplib0.Sexp_conv_error.record_poly_field_value
13641364+ error_source__296_
13651365+ in
13661366+ option_of_sexp _b__304_ sexp__303_)
13671367+ }
13681368+ in
13691369+ fun () -> _x__305_)
13701370+ ; rest =
13711371+ Field
13721372+ { name = "c"
13731373+ ; kind = Required
13741374+ ; conv =
13751375+ (fun sexp__300_ ->
13761376+ let _x__302_ =
13771377+ { c__299_ =
13781378+ (let _c__301_ =
13791379+ Sexplib0.Sexp_conv_error.record_poly_field_value
13801380+ error_source__296_
13811381+ in
13821382+ _c__301_ sexp__300_)
13831383+ }
13841384+ in
13851385+ fun () -> _x__302_)
13861386+ ; rest = Empty
13871387+ }
13881388+ }
13891389+ })
13901390+ ~index_of_field:(function
13911391+ | "a" -> 0
13921392+ | "b" -> 1
13931393+ | "c" -> 2
13941394+ | _ -> -1)
13951395+ ~allow_extra_fields:false
13961396+ ~create:(fun (a, (b, (c, ()))) : t ->
13971397+ let { a__297_ = a } = a () in
13981398+ let { b__298_ = b } = b () in
13991399+ let { c__299_ = c } = c () in
14001400+ { a; b; c })
14011401+ x__309_
14021402+ : Sexplib0.Sexp.t -> t)
14031403+ ;;
14041404+14051405+ let _ = t_of_sexp
14061406+14071407+ let sexp_of_t =
14081408+ (fun { a = a__311_; b = b__314_; c = c__317_ } ->
14091409+ let bnds__310_ = ([] : _ Stdlib.List.t) in
14101410+ let bnds__310_ =
14111411+ let arg__318_ =
14121412+ let _of_c__319_ = (Sexplib0.Sexp_conv.sexp_of_opaque : _ -> _) in
14131413+ _of_c__319_ c__317_
14141414+ in
14151415+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__318_ ] :: bnds__310_
14161416+ : _ Stdlib.List.t)
14171417+ in
14181418+ let bnds__310_ =
14191419+ let arg__315_ =
14201420+ let _of_b__316_ = (Sexplib0.Sexp_conv.sexp_of_opaque : _ -> _) in
14211421+ sexp_of_option _of_b__316_ b__314_
14221422+ in
14231423+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__315_ ] :: bnds__310_
14241424+ : _ Stdlib.List.t)
14251425+ in
14261426+ let bnds__310_ =
14271427+ let arg__312_ =
14281428+ let _of_a__313_ = (Sexplib0.Sexp_conv.sexp_of_opaque : _ -> _) in
14291429+ sexp_of_list _of_a__313_ a__311_
14301430+ in
14311431+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__312_ ] :: bnds__310_
14321432+ : _ Stdlib.List.t)
14331433+ in
14341434+ Sexplib0.Sexp.List bnds__310_
14351435+ : t -> Sexplib0.Sexp.t)
14361436+ ;;
14371437+14381438+ let _ = sexp_of_t
14391439+14401440+ [@@@end]
14411441+end
14421442+14431443+module Record_with_defaults = struct
14441444+ type t =
14451445+ { a : int [@default 0]
14461446+ ; b : int [@default 0] [@sexp_drop_default.compare]
14471447+ ; c : int [@default 0] [@sexp_drop_default.equal]
14481448+ ; d : int [@default 0] [@sexp_drop_default.sexp]
14491449+ ; e : int [@default 0] [@sexp_drop_default ( = )]
14501450+ ; f : int [@sexp_drop_if ( = ) 0]
14511451+ }
14521452+ [@@deriving_inline sexp]
14531453+14541454+ let _ = fun (_ : t) -> ()
14551455+14561456+ let t_of_sexp =
14571457+ (let default__326_ : int = 0
14581458+ and default__325_ : int = 0
14591459+ and default__324_ : int = 0
14601460+ and default__323_ : int = 0
14611461+ and default__322_ : int = 0 in
14621462+ let error_source__321_ = "expansion.ml.Record_with_defaults.t" in
14631463+ fun x__339_ ->
14641464+ Sexplib0.Sexp_conv_record.record_of_sexp
14651465+ ~caller:error_source__321_
14661466+ ~fields:
14671467+ (Field
14681468+ { name = "a"
14691469+ ; kind = Default (fun () -> default__322_)
14701470+ ; conv =
14711471+ (fun x__337_ ->
14721472+ let _x__338_ = int_of_sexp x__337_ in
14731473+ fun () -> _x__338_)
14741474+ ; rest =
14751475+ Field
14761476+ { name = "b"
14771477+ ; kind = Default (fun () -> default__323_)
14781478+ ; conv =
14791479+ (fun x__335_ ->
14801480+ let _x__336_ = int_of_sexp x__335_ in
14811481+ fun () -> _x__336_)
14821482+ ; rest =
14831483+ Field
14841484+ { name = "c"
14851485+ ; kind = Default (fun () -> default__324_)
14861486+ ; conv =
14871487+ (fun x__333_ ->
14881488+ let _x__334_ = int_of_sexp x__333_ in
14891489+ fun () -> _x__334_)
14901490+ ; rest =
14911491+ Field
14921492+ { name = "d"
14931493+ ; kind = Default (fun () -> default__325_)
14941494+ ; conv =
14951495+ (fun x__331_ ->
14961496+ let _x__332_ = int_of_sexp x__331_ in
14971497+ fun () -> _x__332_)
14981498+ ; rest =
14991499+ Field
15001500+ { name = "e"
15011501+ ; kind = Default (fun () -> default__326_)
15021502+ ; conv =
15031503+ (fun x__329_ ->
15041504+ let _x__330_ = int_of_sexp x__329_ in
15051505+ fun () -> _x__330_)
15061506+ ; rest =
15071507+ Field
15081508+ { name = "f"
15091509+ ; kind = Required
15101510+ ; conv =
15111511+ (fun x__327_ ->
15121512+ let _x__328_ = int_of_sexp x__327_ in
15131513+ fun () -> _x__328_)
15141514+ ; rest = Empty
15151515+ }
15161516+ }
15171517+ }
15181518+ }
15191519+ }
15201520+ })
15211521+ ~index_of_field:(function
15221522+ | "a" -> 0
15231523+ | "b" -> 1
15241524+ | "c" -> 2
15251525+ | "d" -> 3
15261526+ | "e" -> 4
15271527+ | "f" -> 5
15281528+ | _ -> -1)
15291529+ ~allow_extra_fields:false
15301530+ ~create:(fun (a, (b, (c, (d, (e, (f, ())))))) : t ->
15311531+ let a = a () in
15321532+ let b = b () in
15331533+ let c = c () in
15341534+ let d = d () in
15351535+ let e = e () in
15361536+ let f = f () in
15371537+ { a; b; c; d; e; f })
15381538+ x__339_
15391539+ : Sexplib0.Sexp.t -> t)
15401540+ ;;
15411541+15421542+ let _ = t_of_sexp
15431543+15441544+ let sexp_of_t =
15451545+ (let default__344_ : int = 0
15461546+ and default__349_ : int = 0
15471547+ and default__354_ : int = 0
15481548+ and default__360_ : int = 0
15491549+ and drop_default__359_ : int -> int -> Stdlib.Bool.t = ( = )
15501550+ and drop_if__365_ : Stdlib.Unit.t -> int -> Stdlib.Bool.t = fun () -> ( = ) 0 in
15511551+ fun { a = a__341_; b = b__345_; c = c__350_; d = d__355_; e = e__361_; f = f__366_ } ->
15521552+ let bnds__340_ = ([] : _ Stdlib.List.t) in
15531553+ let bnds__340_ =
15541554+ if (drop_if__365_ ()) f__366_
15551555+ then bnds__340_
15561556+ else (
15571557+ let arg__368_ = sexp_of_int f__366_ in
15581558+ let bnd__367_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "f"; arg__368_ ] in
15591559+ (bnd__367_ :: bnds__340_ : _ Stdlib.List.t))
15601560+ in
15611561+ let bnds__340_ =
15621562+ if drop_default__359_ default__360_ e__361_
15631563+ then bnds__340_
15641564+ else (
15651565+ let arg__363_ = sexp_of_int e__361_ in
15661566+ let bnd__362_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "e"; arg__363_ ] in
15671567+ (bnd__362_ :: bnds__340_ : _ Stdlib.List.t))
15681568+ in
15691569+ let bnds__340_ =
15701570+ let arg__357_ = sexp_of_int d__355_ in
15711571+ if Sexplib0.Sexp_conv.( = ) (sexp_of_int default__354_) arg__357_
15721572+ then bnds__340_
15731573+ else (
15741574+ let bnd__356_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "d"; arg__357_ ] in
15751575+ (bnd__356_ :: bnds__340_ : _ Stdlib.List.t))
15761576+ in
15771577+ let bnds__340_ =
15781578+ if [%equal: int] default__349_ c__350_
15791579+ then bnds__340_
15801580+ else (
15811581+ let arg__352_ = sexp_of_int c__350_ in
15821582+ let bnd__351_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__352_ ] in
15831583+ (bnd__351_ :: bnds__340_ : _ Stdlib.List.t))
15841584+ in
15851585+ let bnds__340_ =
15861586+ if [%compare.equal: int] default__344_ b__345_
15871587+ then bnds__340_
15881588+ else (
15891589+ let arg__347_ = sexp_of_int b__345_ in
15901590+ let bnd__346_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__347_ ] in
15911591+ (bnd__346_ :: bnds__340_ : _ Stdlib.List.t))
15921592+ in
15931593+ let bnds__340_ =
15941594+ let arg__342_ = sexp_of_int a__341_ in
15951595+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__342_ ] :: bnds__340_
15961596+ : _ Stdlib.List.t)
15971597+ in
15981598+ Sexplib0.Sexp.List bnds__340_
15991599+ : t -> Sexplib0.Sexp.t)
16001600+ ;;
16011601+16021602+ let _ = sexp_of_t
16031603+16041604+ [@@@end]
16051605+end
16061606+16071607+module Record_with_special_types = struct
16081608+ type t =
16091609+ { a : int option [@sexp.option]
16101610+ ; b : int list [@sexp.list]
16111611+ ; c : int array [@sexp.array]
16121612+ ; d : bool [@sexp.bool]
16131613+ ; e : int or_null [@sexp.or_null]
16141614+ }
16151615+ [@@deriving_inline sexp]
16161616+16171617+ let _ = fun (_ : t) -> ()
16181618+16191619+ let t_of_sexp =
16201620+ (let error_source__376_ = "expansion.ml.Record_with_special_types.t" in
16211621+ fun x__377_ ->
16221622+ Sexplib0.Sexp_conv_record.record_of_sexp
16231623+ ~caller:error_source__376_
16241624+ ~fields:
16251625+ (Field
16261626+ { name = "a"
16271627+ ; kind = Sexp_option
16281628+ ; conv = int_of_sexp
16291629+ ; rest =
16301630+ Field
16311631+ { name = "b"
16321632+ ; kind = Sexp_list
16331633+ ; conv = int_of_sexp
16341634+ ; rest =
16351635+ Field
16361636+ { name = "c"
16371637+ ; kind = Sexp_array
16381638+ ; conv = int_of_sexp
16391639+ ; rest =
16401640+ Field
16411641+ { name = "d"
16421642+ ; kind = Sexp_bool
16431643+ ; conv = ()
16441644+ ; rest =
16451645+ Field
16461646+ { name = "e"
16471647+ ; kind = Sexp_or_null
16481648+ ; conv = int_of_sexp
16491649+ ; rest = Empty
16501650+ }
16511651+ }
16521652+ }
16531653+ }
16541654+ })
16551655+ ~index_of_field:(function
16561656+ | "a" -> 0
16571657+ | "b" -> 1
16581658+ | "c" -> 2
16591659+ | "d" -> 3
16601660+ | "e" -> 4
16611661+ | _ -> -1)
16621662+ ~allow_extra_fields:false
16631663+ ~create:(fun (a, (b, (c, (d, (e, ()))))) : t -> { a; b; c; d; e })
16641664+ x__377_
16651665+ : Sexplib0.Sexp.t -> t)
16661666+ ;;
16671667+16681668+ let _ = t_of_sexp
16691669+16701670+ let sexp_of_t =
16711671+ (fun { a = a__379_; b = b__384_; c = c__388_; d = d__391_; e = e__393_ } ->
16721672+ let bnds__378_ = ([] : _ Stdlib.List.t) in
16731673+ let bnds__378_ =
16741674+ match e__393_ with
16751675+ | Ppx_sexp_conv_lib.Or_null.Null -> bnds__378_
16761676+ | Ppx_sexp_conv_lib.Or_null.This v__394_ ->
16771677+ let arg__396_ = sexp_of_int v__394_ in
16781678+ let bnd__395_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "e"; arg__396_ ] in
16791679+ (bnd__395_ :: bnds__378_ : _ Stdlib.List.t)
16801680+ in
16811681+ let bnds__378_ =
16821682+ if d__391_
16831683+ then (
16841684+ let bnd__392_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "d" ] in
16851685+ (bnd__392_ :: bnds__378_ : _ Stdlib.List.t))
16861686+ else bnds__378_
16871687+ in
16881688+ let bnds__378_ =
16891689+ if match c__388_ with
16901690+ | [||] -> true
16911691+ | _ -> false
16921692+ then bnds__378_
16931693+ else (
16941694+ let arg__390_ = (sexp_of_array sexp_of_int) c__388_ in
16951695+ let bnd__389_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__390_ ] in
16961696+ (bnd__389_ :: bnds__378_ : _ Stdlib.List.t))
16971697+ in
16981698+ let bnds__378_ =
16991699+ if match b__384_ with
17001700+ | [] -> true
17011701+ | _ -> false
17021702+ then bnds__378_
17031703+ else (
17041704+ let arg__386_ = (sexp_of_list sexp_of_int) b__384_ in
17051705+ let bnd__385_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__386_ ] in
17061706+ (bnd__385_ :: bnds__378_ : _ Stdlib.List.t))
17071707+ in
17081708+ let bnds__378_ =
17091709+ match a__379_ with
17101710+ | Stdlib.Option.None -> bnds__378_
17111711+ | Stdlib.Option.Some v__380_ ->
17121712+ let arg__382_ = sexp_of_int v__380_ in
17131713+ let bnd__381_ = Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__382_ ] in
17141714+ (bnd__381_ :: bnds__378_ : _ Stdlib.List.t)
17151715+ in
17161716+ Sexplib0.Sexp.List bnds__378_
17171717+ : t -> Sexplib0.Sexp.t)
17181718+ ;;
17191719+17201720+ let _ = sexp_of_t
17211721+17221722+ [@@@end]
17231723+end
17241724+17251725+module Record_with_omit_nil = struct
17261726+ type t =
17271727+ { a : int option [@sexp.omit_nil]
17281728+ ; b : int list [@sexp.omit_nil]
17291729+ ; c : unit [@sexp.omit_nil]
17301730+ ; d : int [@sexp.omit_nil]
17311731+ }
17321732+ [@@deriving_inline sexp]
17331733+17341734+ let _ = fun (_ : t) -> ()
17351735+17361736+ let t_of_sexp =
17371737+ (let error_source__398_ = "expansion.ml.Record_with_omit_nil.t" in
17381738+ fun x__407_ ->
17391739+ Sexplib0.Sexp_conv_record.record_of_sexp
17401740+ ~caller:error_source__398_
17411741+ ~fields:
17421742+ (Field
17431743+ { name = "a"
17441744+ ; kind = Omit_nil
17451745+ ; conv =
17461746+ (fun x__405_ ->
17471747+ let _x__406_ = (option_of_sexp int_of_sexp) x__405_ in
17481748+ fun () -> _x__406_)
17491749+ ; rest =
17501750+ Field
17511751+ { name = "b"
17521752+ ; kind = Omit_nil
17531753+ ; conv =
17541754+ (fun x__403_ ->
17551755+ let _x__404_ = (list_of_sexp int_of_sexp) x__403_ in
17561756+ fun () -> _x__404_)
17571757+ ; rest =
17581758+ Field
17591759+ { name = "c"
17601760+ ; kind = Omit_nil
17611761+ ; conv =
17621762+ (fun x__401_ ->
17631763+ let _x__402_ = unit_of_sexp x__401_ in
17641764+ fun () -> _x__402_)
17651765+ ; rest =
17661766+ Field
17671767+ { name = "d"
17681768+ ; kind = Omit_nil
17691769+ ; conv =
17701770+ (fun x__399_ ->
17711771+ let _x__400_ = int_of_sexp x__399_ in
17721772+ fun () -> _x__400_)
17731773+ ; rest = Empty
17741774+ }
17751775+ }
17761776+ }
17771777+ })
17781778+ ~index_of_field:(function
17791779+ | "a" -> 0
17801780+ | "b" -> 1
17811781+ | "c" -> 2
17821782+ | "d" -> 3
17831783+ | _ -> -1)
17841784+ ~allow_extra_fields:false
17851785+ ~create:(fun (a, (b, (c, (d, ())))) : t ->
17861786+ let a = a () in
17871787+ let b = b () in
17881788+ let c = c () in
17891789+ let d = d () in
17901790+ { a; b; c; d })
17911791+ x__407_
17921792+ : Sexplib0.Sexp.t -> t)
17931793+ ;;
17941794+17951795+ let _ = t_of_sexp
17961796+17971797+ let sexp_of_t =
17981798+ (fun { a = a__409_; b = b__411_; c = c__413_; d = d__415_ } ->
17991799+ let bnds__408_ = ([] : _ Stdlib.List.t) in
18001800+ let bnds__408_ =
18011801+ match sexp_of_int d__415_ with
18021802+ | Sexplib0.Sexp.List [] -> bnds__408_
18031803+ | arg__416_ ->
18041804+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "d"; arg__416_ ] :: bnds__408_
18051805+ : _ Stdlib.List.t)
18061806+ in
18071807+ let bnds__408_ =
18081808+ match sexp_of_unit c__413_ with
18091809+ | Sexplib0.Sexp.List [] -> bnds__408_
18101810+ | arg__414_ ->
18111811+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "c"; arg__414_ ] :: bnds__408_
18121812+ : _ Stdlib.List.t)
18131813+ in
18141814+ let bnds__408_ =
18151815+ match sexp_of_list sexp_of_int b__411_ with
18161816+ | Sexplib0.Sexp.List [] -> bnds__408_
18171817+ | arg__412_ ->
18181818+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__412_ ] :: bnds__408_
18191819+ : _ Stdlib.List.t)
18201820+ in
18211821+ let bnds__408_ =
18221822+ match sexp_of_option sexp_of_int a__409_ with
18231823+ | Sexplib0.Sexp.List [] -> bnds__408_
18241824+ | arg__410_ ->
18251825+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__410_ ] :: bnds__408_
18261826+ : _ Stdlib.List.t)
18271827+ in
18281828+ Sexplib0.Sexp.List bnds__408_
18291829+ : t -> Sexplib0.Sexp.t)
18301830+ ;;
18311831+18321832+ let _ = sexp_of_t
18331833+18341834+ [@@@end]
18351835+end
18361836+18371837+module Variant_with_sexp_list = struct
18381838+ type t = A of int list [@sexp.list] [@@deriving_inline sexp]
18391839+18401840+ let _ = fun (_ : t) -> ()
18411841+18421842+ let t_of_sexp =
18431843+ (let error_source__419_ = "expansion.ml.Variant_with_sexp_list.t" in
18441844+ function
18451845+ | Sexplib0.Sexp.List
18461846+ (Sexplib0.Sexp.Atom (("a" | "A") as _tag__422_) :: sexp_args__423_) as
18471847+ _sexp__421_ -> A (Sexplib0.Sexp_conv.list_map int_of_sexp sexp_args__423_)
18481848+ | Sexplib0.Sexp.Atom ("a" | "A") as sexp__420_ ->
18491849+ Sexplib0.Sexp_conv_error.stag_takes_args error_source__419_ sexp__420_
18501850+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__418_ ->
18511851+ Sexplib0.Sexp_conv_error.nested_list_invalid_sum error_source__419_ sexp__418_
18521852+ | Sexplib0.Sexp.List [] as sexp__418_ ->
18531853+ Sexplib0.Sexp_conv_error.empty_list_invalid_sum error_source__419_ sexp__418_
18541854+ | sexp__418_ ->
18551855+ Sexplib0.Sexp_conv_error.unexpected_stag error_source__419_ [ "A" ] sexp__418_
18561856+ : Sexplib0.Sexp.t -> t)
18571857+ ;;
18581858+18591859+ let _ = t_of_sexp
18601860+18611861+ let sexp_of_t =
18621862+ (fun (A l__424_) ->
18631863+ Sexplib0.Sexp.List
18641864+ (Sexplib0.Sexp.Atom "A" :: Sexplib0.Sexp_conv.list_map sexp_of_int l__424_)
18651865+ : t -> Sexplib0.Sexp.t)
18661866+ ;;
18671867+18681868+ let _ = sexp_of_t
18691869+18701870+ [@@@end]
18711871+end
18721872+18731873+module Poly_variant_with_sexp_list = struct
18741874+ type t = [ `A of int list [@sexp.list] ] [@@deriving_inline sexp]
18751875+18761876+ let _ = fun (_ : t) -> ()
18771877+18781878+ let __t_of_sexp__ =
18791879+ (let error_source__431_ = "expansion.ml.Poly_variant_with_sexp_list.t" in
18801880+ function
18811881+ | Sexplib0.Sexp.Atom atom__426_ as _sexp__428_ ->
18821882+ (match atom__426_ with
18831883+ | "A" -> Sexplib0.Sexp_conv_error.ptag_takes_args error_source__431_ _sexp__428_
18841884+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
18851885+ | Sexplib0.Sexp.List (Sexplib0.Sexp.Atom atom__426_ :: sexp_args__429_) as
18861886+ _sexp__428_ ->
18871887+ (match atom__426_ with
18881888+ | "A" as _tag__430_ ->
18891889+ `A (Sexplib0.Sexp_conv.list_map int_of_sexp sexp_args__429_)
18901890+ | _ -> Sexplib0.Sexp_conv_error.no_variant_match ())
18911891+ | Sexplib0.Sexp.List (Sexplib0.Sexp.List _ :: _) as sexp__427_ ->
18921892+ Sexplib0.Sexp_conv_error.nested_list_invalid_poly_var error_source__431_ sexp__427_
18931893+ | Sexplib0.Sexp.List [] as sexp__427_ ->
18941894+ Sexplib0.Sexp_conv_error.empty_list_invalid_poly_var error_source__431_ sexp__427_
18951895+ : Sexplib0.Sexp.t -> t)
18961896+ ;;
18971897+18981898+ let _ = __t_of_sexp__
18991899+19001900+ let t_of_sexp =
19011901+ (let error_source__433_ = "expansion.ml.Poly_variant_with_sexp_list.t" in
19021902+ fun sexp__432_ ->
19031903+ try __t_of_sexp__ sexp__432_ with
19041904+ | Sexplib0.Sexp_conv_error.No_variant_match ->
19051905+ Sexplib0.Sexp_conv_error.no_matching_variant_found error_source__433_ sexp__432_
19061906+ : Sexplib0.Sexp.t -> t)
19071907+ ;;
19081908+19091909+ let _ = t_of_sexp
19101910+19111911+ let sexp_of_t =
19121912+ (fun (`A l__434_) ->
19131913+ Sexplib0.Sexp.List
19141914+ (Sexplib0.Sexp.Atom "A" :: Sexplib0.Sexp_conv.list_map sexp_of_int l__434_)
19151915+ : t -> Sexplib0.Sexp.t)
19161916+ ;;
19171917+19181918+ let _ = sexp_of_t
19191919+19201920+ [@@@end]
19211921+end
19221922+19231923+module Record_allowing_extra_fields = struct
19241924+ type t = { a : int } [@@allow_extra_fields] [@@deriving_inline sexp]
19251925+19261926+ let _ = fun (_ : t) -> ()
19271927+19281928+ let t_of_sexp =
19291929+ (let error_source__436_ = "expansion.ml.Record_allowing_extra_fields.t" in
19301930+ fun x__439_ ->
19311931+ Sexplib0.Sexp_conv_record.record_of_sexp
19321932+ ~caller:error_source__436_
19331933+ ~fields:
19341934+ (Field
19351935+ { name = "a"
19361936+ ; kind = Required
19371937+ ; conv =
19381938+ (fun x__437_ ->
19391939+ let _x__438_ = int_of_sexp x__437_ in
19401940+ fun () -> _x__438_)
19411941+ ; rest = Empty
19421942+ })
19431943+ ~index_of_field:(function
19441944+ | "a" -> 0
19451945+ | _ -> -1)
19461946+ ~allow_extra_fields:true
19471947+ ~create:(fun (a, ()) : t ->
19481948+ let a = a () in
19491949+ { a })
19501950+ x__439_
19511951+ : Sexplib0.Sexp.t -> t)
19521952+ ;;
19531953+19541954+ let _ = t_of_sexp
19551955+19561956+ let sexp_of_t =
19571957+ (fun { a = a__441_ } ->
19581958+ let bnds__440_ = ([] : _ Stdlib.List.t) in
19591959+ let bnds__440_ =
19601960+ let arg__442_ = sexp_of_int a__441_ in
19611961+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__442_ ] :: bnds__440_
19621962+ : _ Stdlib.List.t)
19631963+ in
19641964+ Sexplib0.Sexp.List bnds__440_
19651965+ : t -> Sexplib0.Sexp.t)
19661966+ ;;
19671967+19681968+ let _ = sexp_of_t
19691969+19701970+ [@@@end]
19711971+end
19721972+19731973+module Opaque = struct
19741974+ type t = (int[@sexp.opaque]) list [@@deriving_inline sexp]
19751975+19761976+ let _ = fun (_ : t) -> ()
19771977+19781978+ let t_of_sexp =
19791979+ (fun x__444_ -> list_of_sexp Sexplib0.Sexp_conv.opaque_of_sexp x__444_
19801980+ : Sexplib0.Sexp.t -> t)
19811981+ ;;
19821982+19831983+ let _ = t_of_sexp
19841984+19851985+ let sexp_of_t =
19861986+ (fun x__445_ -> sexp_of_list (Sexplib0.Sexp_conv.sexp_of_opaque : _ -> _) x__445_
19871987+ : t -> Sexplib0.Sexp.t)
19881988+ ;;
19891989+19901990+ let _ = sexp_of_t
19911991+19921992+ [@@@end]
19931993+end
19941994+19951995+[@@@expand_inline
19961996+ let [%sexp_of: Functor(T).t] = ()
19971997+ let [%of_sexp: Functor(T).t] = ()]
19981998+19991999+let sexp_of_functor__t = ()
20002000+let functor__t_of_sexp = ()
20012001+20022002+[@@@end]
20032003+20042004+module Portable = struct
20052005+ type t =
20062006+ { u : int u
20072007+ ; b : int
20082008+ }
20092009+20102010+ and 'a u =
20112011+ { t : t
20122012+ ; a : 'a
20132013+ }
20142014+ [@@deriving_inline sexp ~portable]
20152015+20162016+ let _ = fun (_ : t) -> ()
20172017+ let _ = fun (_ : 'a u) -> ()
20182018+20192019+ include struct
20202020+ let rec t_of_sexp =
20212021+ (let error_source__447_ = "expansion.ml.Portable.t" in
20222022+ fun x__452_ ->
20232023+ Sexplib0.Sexp_conv_record.record_of_sexp
20242024+ ~caller:error_source__447_
20252025+ ~fields:
20262026+ (Field
20272027+ { name = "u"
20282028+ ; kind = Required
20292029+ ; conv =
20302030+ (fun x__450_ ->
20312031+ let _x__451_ = (u_of_sexp int_of_sexp) x__450_ in
20322032+ fun () -> _x__451_)
20332033+ ; rest =
20342034+ Field
20352035+ { name = "b"
20362036+ ; kind = Required
20372037+ ; conv =
20382038+ (fun x__448_ ->
20392039+ let _x__449_ = int_of_sexp x__448_ in
20402040+ fun () -> _x__449_)
20412041+ ; rest = Empty
20422042+ }
20432043+ })
20442044+ ~index_of_field:(function
20452045+ | "u" -> 0
20462046+ | "b" -> 1
20472047+ | _ -> -1)
20482048+ ~allow_extra_fields:false
20492049+ ~create:(fun (u, (b, ())) : t ->
20502050+ let u = u () in
20512051+ let b = b () in
20522052+ { u; b })
20532053+ x__452_
20542054+ : Sexplib0.Sexp.t -> t)
20552055+20562056+ and u_of_sexp : 'a. (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a u =
20572057+ let error_source__455_ = "expansion.ml.Portable.u" in
20582058+ fun _of_a__453_ x__460_ ->
20592059+ Sexplib0.Sexp_conv_record.record_of_sexp
20602060+ ~caller:error_source__455_
20612061+ ~fields:
20622062+ (Field
20632063+ { name = "t"
20642064+ ; kind = Required
20652065+ ; conv =
20662066+ (fun x__458_ ->
20672067+ let _x__459_ = t_of_sexp x__458_ in
20682068+ fun () -> _x__459_)
20692069+ ; rest =
20702070+ Field
20712071+ { name = "a"
20722072+ ; kind = Required
20732073+ ; conv =
20742074+ (fun x__456_ ->
20752075+ let _x__457_ = _of_a__453_ x__456_ in
20762076+ fun () -> _x__457_)
20772077+ ; rest = Empty
20782078+ }
20792079+ })
20802080+ ~index_of_field:(function
20812081+ | "t" -> 0
20822082+ | "a" -> 1
20832083+ | _ -> -1)
20842084+ ~allow_extra_fields:false
20852085+ ~create:(fun (t, (a, ())) : _ u ->
20862086+ let t = t () in
20872087+ let a = a () in
20882088+ { t; a })
20892089+ x__460_
20902090+ ;;
20912091+20922092+ let _ = t_of_sexp
20932093+ and _ = u_of_sexp
20942094+ end
20952095+20962096+ let _ = t_of_sexp
20972097+ and _ = u_of_sexp
20982098+20992099+ include struct
21002100+ let rec sexp_of_t =
21012101+ (fun { u = u__462_; b = b__464_ } ->
21022102+ let bnds__461_ = ([] : _ Stdlib.List.t) in
21032103+ let bnds__461_ =
21042104+ let arg__465_ = sexp_of_int b__464_ in
21052105+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "b"; arg__465_ ] :: bnds__461_
21062106+ : _ Stdlib.List.t)
21072107+ in
21082108+ let bnds__461_ =
21092109+ let arg__463_ = sexp_of_u sexp_of_int u__462_ in
21102110+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "u"; arg__463_ ] :: bnds__461_
21112111+ : _ Stdlib.List.t)
21122112+ in
21132113+ Sexplib0.Sexp.List bnds__461_
21142114+ : t -> Sexplib0.Sexp.t)
21152115+21162116+ and sexp_of_u : 'a. ('a -> Sexplib0.Sexp.t) -> 'a u -> Sexplib0.Sexp.t =
21172117+ fun _of_a__466_ { t = t__468_; a = a__470_ } ->
21182118+ let bnds__467_ = ([] : _ Stdlib.List.t) in
21192119+ let bnds__467_ =
21202120+ let arg__471_ = _of_a__466_ a__470_ in
21212121+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "a"; arg__471_ ] :: bnds__467_
21222122+ : _ Stdlib.List.t)
21232123+ in
21242124+ let bnds__467_ =
21252125+ let arg__469_ = sexp_of_t t__468_ in
21262126+ (Sexplib0.Sexp.List [ Sexplib0.Sexp.Atom "t"; arg__469_ ] :: bnds__467_
21272127+ : _ Stdlib.List.t)
21282128+ in
21292129+ Sexplib0.Sexp.List bnds__467_
21302130+ ;;
21312131+21322132+ let _ = sexp_of_t
21332133+ and _ = sexp_of_u
21342134+ end
21352135+21362136+ let _ = sexp_of_t
21372137+ and _ = sexp_of_u
21382138+21392139+ [@@@end]
21402140+end
+476
vendor/opam/ppx_sexp_conv/test/expansion.mli
···11+open! Base
22+33+module%template Abstract : sig
44+ type t [@@deriving_inline sexp [@alloc stack]]
55+66+ include sig
77+ [@@@ocaml.warning "-32"]
88+99+ include Sexplib0.Sexpable.S__stack with type t := t
1010+ end
1111+ [@@ocaml.doc "@inline"]
1212+1313+ [@@@end]
1414+end
1515+1616+module Tuple : sig
1717+ type t = int * int * int [@@deriving_inline sexp]
1818+1919+ include sig
2020+ [@@@ocaml.warning "-32"]
2121+2222+ include Sexplib0.Sexpable.S_any with type t := t
2323+ end
2424+ [@@ocaml.doc "@inline"]
2525+2626+ [@@@end]
2727+end
2828+2929+module Record : sig
3030+ type t =
3131+ { a : int
3232+ ; b : int
3333+ ; c : int
3434+ }
3535+ [@@deriving_inline sexp]
3636+3737+ include sig
3838+ [@@@ocaml.warning "-32"]
3939+4040+ include Sexplib0.Sexpable.S with type t := t
4141+ end
4242+ [@@ocaml.doc "@inline"]
4343+4444+ [@@@end]
4545+end
4646+4747+module Mutable_record : sig
4848+ type t =
4949+ { mutable a : int
5050+ ; mutable b : int
5151+ ; mutable c : int
5252+ }
5353+ [@@deriving_inline sexp]
5454+5555+ include sig
5656+ [@@@ocaml.warning "-32"]
5757+5858+ include Sexplib0.Sexpable.S with type t := t
5959+ end
6060+ [@@ocaml.doc "@inline"]
6161+6262+ [@@@end]
6363+end
6464+6565+module Variant : sig
6666+ type t =
6767+ | A
6868+ | B of int * int
6969+ | C of
7070+ { a : int
7171+ ; b : int
7272+ ; d : int
7373+ }
7474+ | D of
7575+ { mutable a : int
7676+ ; mutable b : int
7777+ ; mutable t : int
7878+ }
7979+ [@@deriving_inline sexp]
8080+8181+ include sig
8282+ [@@@ocaml.warning "-32"]
8383+8484+ include Sexplib0.Sexpable.S with type t := t
8585+ end
8686+ [@@ocaml.doc "@inline"]
8787+8888+ [@@@end]
8989+end
9090+9191+module Poly_variant : sig
9292+ type t =
9393+ [ `A
9494+ | `B of int
9595+ ]
9696+ [@@deriving_inline sexp]
9797+9898+ include sig
9999+ [@@@ocaml.warning "-32"]
100100+101101+ val sexp_of_t : t -> Sexplib0.Sexp.t
102102+ val t_of_sexp : Sexplib0.Sexp.t -> t
103103+ val __t_of_sexp__ : Sexplib0.Sexp.t -> t
104104+ end
105105+ [@@ocaml.doc "@inline"]
106106+107107+ [@@@end]
108108+end
109109+110110+module Inline_poly_variant : sig
111111+ type t =
112112+ [ Poly_variant.t
113113+ | `C of int * int
114114+ ]
115115+ [@@deriving_inline sexp]
116116+117117+ include sig
118118+ [@@@ocaml.warning "-32"]
119119+120120+ val sexp_of_t : t -> Sexplib0.Sexp.t
121121+ val t_of_sexp : Sexplib0.Sexp.t -> t
122122+ val __t_of_sexp__ : Sexplib0.Sexp.t -> t
123123+ end
124124+ [@@ocaml.doc "@inline"]
125125+126126+ [@@@end]
127127+end
128128+129129+module Recursive : sig
130130+ type t =
131131+ | Banana of t
132132+ | Orange
133133+ [@@deriving_inline sexp]
134134+135135+ include sig
136136+ [@@@ocaml.warning "-32"]
137137+138138+ include Sexplib0.Sexpable.S with type t := t
139139+ end
140140+ [@@ocaml.doc "@inline"]
141141+142142+ [@@@end]
143143+end
144144+145145+module Nonrecursive : sig
146146+ open Recursive
147147+148148+ type nonrec t = t [@@deriving_inline sexp]
149149+150150+ include sig
151151+ [@@@ocaml.warning "-32"]
152152+153153+ include Sexplib0.Sexpable.S_any with type t := t
154154+ end
155155+ [@@ocaml.doc "@inline"]
156156+157157+ [@@@end]
158158+end
159159+160160+module Mutually_recursive : sig
161161+ type a =
162162+ | A
163163+ | B of b
164164+ | C of
165165+ { a : a
166166+ ; b : b
167167+ ; c : c
168168+ }
169169+170170+ and b =
171171+ { a : a
172172+ ; b : b
173173+ }
174174+175175+ and c = a [@@deriving_inline sexp]
176176+177177+ include sig
178178+ [@@@ocaml.warning "-32"]
179179+180180+ val sexp_of_a : a -> Sexplib0.Sexp.t
181181+ val sexp_of_b : b -> Sexplib0.Sexp.t
182182+ val sexp_of_c : c -> Sexplib0.Sexp.t
183183+ val a_of_sexp : Sexplib0.Sexp.t -> a
184184+ val b_of_sexp : Sexplib0.Sexp.t -> b
185185+ val c_of_sexp : Sexplib0.Sexp.t -> c
186186+ end
187187+ [@@ocaml.doc "@inline"]
188188+189189+ [@@@end]
190190+end
191191+192192+module Alias : sig
193193+ type t = Recursive.t [@@deriving_inline sexp]
194194+195195+ include sig
196196+ [@@@ocaml.warning "-32"]
197197+198198+ include Sexplib0.Sexpable.S_any with type t := t
199199+ end
200200+ [@@ocaml.doc "@inline"]
201201+202202+ [@@@end]
203203+end
204204+205205+module Re_export : sig
206206+ type t = Recursive.t =
207207+ | Banana of t
208208+ | Orange
209209+ [@@deriving_inline sexp]
210210+211211+ include sig
212212+ [@@@ocaml.warning "-32"]
213213+214214+ include Sexplib0.Sexpable.S with type t := t
215215+ end
216216+ [@@ocaml.doc "@inline"]
217217+218218+ [@@@end]
219219+end
220220+221221+module Unary : sig
222222+ type 'a t = 'a list option [@@deriving_inline sexp]
223223+224224+ include sig
225225+ [@@@ocaml.warning "-32"]
226226+227227+ include Sexplib0.Sexpable.S_any1 with type 'a t := 'a t
228228+ end
229229+ [@@ocaml.doc "@inline"]
230230+231231+ [@@@end]
232232+end
233233+234234+module Binary : sig
235235+ type ('a, 'b) t = ('a, 'b) Either.t [@@deriving_inline sexp]
236236+237237+ include sig
238238+ [@@@ocaml.warning "-32"]
239239+240240+ include Sexplib0.Sexpable.S_any2 with type ('a, 'b) t := ('a, 'b) t
241241+ end
242242+ [@@ocaml.doc "@inline"]
243243+244244+ [@@@end]
245245+end
246246+247247+module First_order : sig
248248+ type 'a t = 'a -> 'a [@@deriving_inline sexp]
249249+250250+ include sig
251251+ [@@@ocaml.warning "-32"]
252252+253253+ include Sexplib0.Sexpable.S_any1 with type 'a t := 'a t
254254+ end
255255+ [@@ocaml.doc "@inline"]
256256+257257+ [@@@end]
258258+end
259259+260260+module Second_order : sig
261261+ type ('a, 'b) t = ('a -> 'a) -> ('a -> 'b) -> ('b -> 'b) -> 'a -> 'b
262262+ [@@deriving_inline sexp]
263263+264264+ include sig
265265+ [@@@ocaml.warning "-32"]
266266+267267+ include Sexplib0.Sexpable.S_any2 with type ('a, 'b) t := ('a, 'b) t
268268+ end
269269+ [@@ocaml.doc "@inline"]
270270+271271+ [@@@end]
272272+end
273273+274274+module Named_arguments : sig
275275+ type t = ?a:int -> b:int -> int -> int [@@deriving_inline sexp]
276276+277277+ include sig
278278+ [@@@ocaml.warning "-32"]
279279+280280+ include Sexplib0.Sexpable.S_any with type t := t
281281+ end
282282+ [@@ocaml.doc "@inline"]
283283+284284+ [@@@end]
285285+end
286286+287287+module Gadt : sig
288288+ type _ t =
289289+ | A : _ option t
290290+ | B : int -> int t
291291+ | C : 'a list -> unit t
292292+ [@@deriving_inline sexp_of]
293293+294294+ include sig
295295+ [@@@ocaml.warning "-32"]
296296+297297+ val sexp_of_t : ('a__001_ -> Sexplib0.Sexp.t) -> 'a__001_ t -> Sexplib0.Sexp.t
298298+ end
299299+ [@@ocaml.doc "@inline"]
300300+301301+ [@@@end]
302302+end
303303+304304+module Recursive_record_containing_variant : sig
305305+ type t =
306306+ { a : [ `A of t ]
307307+ ; b : [ `B ]
308308+ }
309309+ [@@deriving_inline sexp]
310310+311311+ include sig
312312+ [@@@ocaml.warning "-32"]
313313+314314+ include Sexplib0.Sexpable.S with type t := t
315315+ end
316316+ [@@ocaml.doc "@inline"]
317317+318318+ [@@@end]
319319+end
320320+321321+module Poly_record : sig
322322+ type t =
323323+ { a : 'a. 'a list
324324+ ; b : 'b. 'b option
325325+ ; c : 'c. 'c
326326+ }
327327+ [@@deriving_inline sexp]
328328+329329+ include sig
330330+ [@@@ocaml.warning "-32"]
331331+332332+ include Sexplib0.Sexpable.S with type t := t
333333+ end
334334+ [@@ocaml.doc "@inline"]
335335+336336+ [@@@end]
337337+end
338338+339339+module Record_with_defaults : sig
340340+ type t =
341341+ { a : int
342342+ ; b : int
343343+ ; c : int
344344+ ; d : int
345345+ ; e : int
346346+ ; f : int
347347+ }
348348+ [@@deriving_inline sexp]
349349+350350+ include sig
351351+ [@@@ocaml.warning "-32"]
352352+353353+ include Sexplib0.Sexpable.S with type t := t
354354+ end
355355+ [@@ocaml.doc "@inline"]
356356+357357+ [@@@end]
358358+end
359359+360360+module Record_with_special_types : sig
361361+ type t =
362362+ { a : int option
363363+ ; b : int list
364364+ ; c : int array
365365+ ; d : bool
366366+ ; e : int or_null
367367+ }
368368+ [@@deriving_inline sexp]
369369+370370+ include sig
371371+ [@@@ocaml.warning "-32"]
372372+373373+ include Sexplib0.Sexpable.S with type t := t
374374+ end
375375+ [@@ocaml.doc "@inline"]
376376+377377+ [@@@end]
378378+end
379379+380380+module Record_with_omit_nil : sig
381381+ type t =
382382+ { a : int option
383383+ ; b : int list
384384+ ; c : unit
385385+ ; d : int
386386+ }
387387+ [@@deriving_inline sexp]
388388+389389+ include sig
390390+ [@@@ocaml.warning "-32"]
391391+392392+ include Sexplib0.Sexpable.S with type t := t
393393+ end
394394+ [@@ocaml.doc "@inline"]
395395+396396+ [@@@end]
397397+end
398398+399399+module Variant_with_sexp_list : sig
400400+ type t = A of int list [@@deriving_inline sexp]
401401+402402+ include sig
403403+ [@@@ocaml.warning "-32"]
404404+405405+ include Sexplib0.Sexpable.S with type t := t
406406+ end
407407+ [@@ocaml.doc "@inline"]
408408+409409+ [@@@end]
410410+end
411411+412412+module Poly_variant_with_sexp_list : sig
413413+ type t = [ `A of int list ] [@@deriving_inline sexp]
414414+415415+ include sig
416416+ [@@@ocaml.warning "-32"]
417417+418418+ val sexp_of_t : t -> Sexplib0.Sexp.t
419419+ val t_of_sexp : Sexplib0.Sexp.t -> t
420420+ val __t_of_sexp__ : Sexplib0.Sexp.t -> t
421421+ end
422422+ [@@ocaml.doc "@inline"]
423423+424424+ [@@@end]
425425+end
426426+427427+module Record_allowing_extra_fields : sig
428428+ type t = { a : int } [@@deriving_inline sexp]
429429+430430+ include sig
431431+ [@@@ocaml.warning "-32"]
432432+433433+ include Sexplib0.Sexpable.S with type t := t
434434+ end
435435+ [@@ocaml.doc "@inline"]
436436+437437+ [@@@end]
438438+end
439439+440440+module Opaque : sig
441441+ type t = int list [@@deriving_inline sexp]
442442+443443+ include sig
444444+ [@@@ocaml.warning "-32"]
445445+446446+ include Sexplib0.Sexpable.S_any with type t := t
447447+ end
448448+ [@@ocaml.doc "@inline"]
449449+450450+ [@@@end]
451451+end
452452+453453+module Portable : sig
454454+ type t =
455455+ { u : int u
456456+ ; b : int
457457+ }
458458+459459+ and 'a u =
460460+ { t : t
461461+ ; a : 'a
462462+ }
463463+ [@@deriving_inline sexp ~portable]
464464+465465+ include sig
466466+ [@@@ocaml.warning "-32"]
467467+468468+ val sexp_of_t : t -> Sexplib0.Sexp.t
469469+ val sexp_of_u : ('a -> Sexplib0.Sexp.t) -> 'a u -> Sexplib0.Sexp.t
470470+ val t_of_sexp : Sexplib0.Sexp.t -> t
471471+ val u_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a u
472472+ end
473473+ [@@ocaml.doc "@inline"]
474474+475475+ [@@@end]
476476+end
+59
vendor/opam/ppx_sexp_conv/test/lib/conv_test.ml
···11+open Ppx_sexp_conv_lib
22+open Conv
33+44+module%test Exceptions = struct
55+ let check_sexp exn string =
66+ match sexp_of_exn_opt exn with
77+ | None -> raise exn
88+ | Some sexp ->
99+ let sexp_as_string = Ppx_sexp_conv_lib.Sexp.to_string sexp in
1010+ if sexp_as_string <> string then failwith sexp_as_string
1111+ ;;
1212+1313+ (* first global exceptions, checking different arities since they
1414+ don't have the same representation *)
1515+ exception Arg0 [@@deriving sexp]
1616+ exception Arg1 of int [@@deriving sexp]
1717+ exception Arg2 of int * int [@@deriving sexp]
1818+1919+ let%test_unit _ = check_sexp Arg0 "conv_test.ml.Arg0"
2020+ let%test_unit _ = check_sexp (Arg1 1) "(conv_test.ml.Arg1 1)"
2121+ let%test_unit _ = check_sexp (Arg2 (2, 3)) "(conv_test.ml.Arg2 2 3)"
2222+2323+ (* now local exceptions *)
2424+ let exn (type a) a sexp_of_a =
2525+ let module M = struct
2626+ exception E of a [@@deriving sexp]
2727+ end
2828+ in
2929+ M.E a
3030+ ;;
3131+3232+ let%test_unit "incompatible exceptions with the same name" =
3333+ let e_int = exn 1 sexp_of_int in
3434+ let e_string = exn "a" sexp_of_string in
3535+ check_sexp e_int "(conv_test.ml.E 1)";
3636+ check_sexp e_string "(conv_test.ml.E a)"
3737+ ;;
3838+3939+ let%test_unit "sexp converters are finalized properly for local exceptions" =
4040+ Gc.compact ();
4141+ Gc.compact ();
4242+ let size_before = Ppx_sexp_conv_lib.Conv.Exn_converter.For_unit_tests_only.size () in
4343+ let e = exn 2.5 sexp_of_float in
4444+ let size_after_local_exn =
4545+ Ppx_sexp_conv_lib.Conv.Exn_converter.For_unit_tests_only.size ()
4646+ in
4747+ let e_finalized = ref false in
4848+ Gc.finalise (fun _ -> e_finalized := true) e;
4949+ check_sexp e "(conv_test.ml.E 2.5)";
5050+ Gc.compact ();
5151+ Gc.compact ();
5252+ assert !e_finalized;
5353+ let size_after_gc =
5454+ Ppx_sexp_conv_lib.Conv.Exn_converter.For_unit_tests_only.size ()
5555+ in
5656+ assert (size_before + 1 = size_after_local_exn);
5757+ assert (size_before = size_after_gc)
5858+ ;;
5959+end
+1
vendor/opam/ppx_sexp_conv/test/lib/conv_test.mli
···11+(*_ This signature is deliberately empty. *)
···11+type unit = U [@@deriving sexp]
22+33+type a = { a : unit }
44+and b = { b : unit } [@@deriving sexp]
55+66+type c = [ `C of unit ]
77+and d = [ `D of unit ] [@@deriving sexp]
88+99+type%template 'a t = { a : 'a } [@@kind k = (value, bits64, float64)] [@@deriving sexp]
···11+type unit = U [@@deriving sexp]
22+33+type a = { a : unit }
44+and b = { b : unit } [@@deriving sexp]
55+66+type c = [ `C of unit ]
77+and d = [ `D of unit ] [@@deriving sexp]
88+99+type%template 'a t = { a : 'a } [@@kind k = (value, bits64, float64)] [@@deriving sexp]
+118
vendor/opam/ppx_sexp_conv/test/nonrec_test.ml
···11+open Ppx_sexp_conv_lib.Conv
22+33+type t = float [@@deriving sexp ~stackify]
44+55+module M : sig
66+ type t = float list [@@deriving sexp ~stackify]
77+end = struct
88+ type nonrec t = t list [@@deriving sexp ~stackify]
99+end
1010+1111+type 'a u = 'a [@@deriving sexp ~stackify]
1212+1313+module M2 : sig
1414+ type 'a u = 'a list [@@deriving sexp ~stackify]
1515+end = struct
1616+ type nonrec 'a u = 'a u list [@@deriving sexp ~stackify]
1717+end
1818+1919+type 'a v = 'a w
2020+and 'a w = A of 'a v [@@deriving sexp ~stackify]
2121+2222+type 'a v_ = 'a v [@@deriving sexp ~stackify]
2323+type 'a w_ = 'a w [@@deriving sexp ~stackify]
2424+2525+module M3 : sig
2626+ type 'a v = 'a w_ [@@deriving sexp ~stackify]
2727+ type 'a w = 'a v_ [@@deriving sexp ~stackify]
2828+end = struct
2929+ type nonrec 'a v = 'a w
3030+ and 'a w = 'a v [@@deriving sexp ~stackify]
3131+end
3232+3333+type t0 = A of t0 [@@deriving sexp ~stackify]
3434+3535+module B : sig
3636+ type nonrec t0 = t0 [@@deriving sexp ~stackify]
3737+end = struct
3838+ type nonrec t0 = t0 = A of t0 [@@deriving sexp ~stackify]
3939+end
4040+4141+type t1 = A of t2
4242+and t2 = B of t1 [@@deriving sexp ~stackify]
4343+4444+module C : sig
4545+ type nonrec t1 = t1 [@@deriving sexp ~stackify]
4646+ type nonrec t2 = t2 [@@deriving sexp ~stackify]
4747+end = struct
4848+ type nonrec t1 = t1 = A of t2
4949+ and t2 = t2 = B of t1 [@@deriving sexp ~stackify]
5050+end
5151+5252+type 'a v1 = A of 'a v2
5353+and 'a v2 = B of 'a v1 [@@deriving sexp ~stackify]
5454+5555+module D : sig
5656+ type nonrec 'a v1 = 'a v1 [@@deriving sexp ~stackify]
5757+ type nonrec 'a v2 = 'a v2 [@@deriving sexp ~stackify]
5858+end = struct
5959+ type nonrec 'a v1 = 'a v1 = A of 'a v2
6060+ and 'a v2 = 'a v2 = B of 'a v1 [@@deriving sexp ~stackify]
6161+end
6262+6363+type +'a w1
6464+6565+module E = struct
6666+ type nonrec +'a w1 = 'a w1
6767+end
6868+6969+type 'a y1 = A of 'a y2
7070+and 'a y2 = B of 'a y1
7171+7272+module F : sig
7373+ type nonrec 'a y2 = B of 'a y1
7474+ type nonrec 'a y1 = 'a y1
7575+end = struct
7676+ type nonrec 'a y1 = 'a y1 = A of 'a y2
7777+ and 'a y2 = B of 'a y1
7878+end
7979+8080+type z1 = A of z1
8181+8282+module G : sig
8383+ module A : sig
8484+ type z2 = A of z2
8585+ end
8686+8787+ module B : sig
8888+ type z2 = A of z2
8989+ end
9090+9191+ module C : sig
9292+ type z2 = A of z2
9393+ end
9494+end = struct
9595+ type z2 = z1 = A of z1
9696+9797+ module A = struct
9898+ type nonrec z2 = z1 = A of z2
9999+ end
100100+101101+ module B = struct
102102+ type nonrec z2 = z2 = A of z2
103103+ end
104104+105105+ module C = struct
106106+ type nonrec z2 = z2 = A of z1
107107+ end
108108+end
109109+110110+type ('a, 'b) zz = A of 'a * 'b
111111+112112+module H = struct
113113+ type nonrec ('a, 'b) zz = ('a, 'b) zz = A of 'a * 'b
114114+end
115115+116116+module I = struct
117117+ type nonrec 'a zz = ('a, 'a) zz
118118+end
+100
vendor/opam/ppx_sexp_conv/test/phantom.ml
···11+open Base
22+open Ppx_sexp_conv_lib.Conv
33+44+type 'a[@phantom] t = int [@@deriving sexp]
55+type ('a[@phantom], 'b) u = 'b list [@@deriving sexp]
66+type ('a[@phantom], 'b[@phantom]) v = string [@@deriving sexp]
77+type ('a, 'b[@phantom]) w = 'a option [@@deriving sexp]
88+99+let print_s sexp = Stdio.print_endline (Sexp.to_string_hum sexp)
1010+1111+let%expect_test "phantom type parameters work correctly" =
1212+ let x : int t = 42 in
1313+ let sexp = sexp_of_t x in
1414+ print_s sexp;
1515+ [%expect {| 42 |}];
1616+ let y : string t = t_of_sexp sexp in
1717+ Expect_test_helpers_base.require_equal (module Int) x y;
1818+ [%expect {| |}];
1919+ let x : (int, string) u = [ "hello"; "world" ] in
2020+ let sexp = sexp_of_u sexp_of_string x in
2121+ print_s sexp;
2222+ [%expect {| (hello world) |}];
2323+ let y : (bool, string) u = u_of_sexp string_of_sexp sexp in
2424+ Expect_test_helpers_base.require_equal
2525+ (module struct
2626+ type t = string list [@@deriving equal, sexp_of]
2727+ end)
2828+ x
2929+ y;
3030+ [%expect {| |}];
3131+ let x : (int, string) v = "test" in
3232+ let sexp = sexp_of_v x in
3333+ print_s sexp;
3434+ [%expect {| test |}];
3535+ let y : (bool, float) v = v_of_sexp sexp in
3636+ Expect_test_helpers_base.require_equal (module String) x y;
3737+ [%expect {| |}];
3838+ let x : (int, string) w = Some 42 in
3939+ let sexp = sexp_of_w sexp_of_int x in
4040+ print_s sexp;
4141+ [%expect {| (42) |}];
4242+ let y : (int, bool) w = w_of_sexp int_of_sexp sexp in
4343+ Expect_test_helpers_base.require_equal
4444+ (module struct
4545+ type t = int option [@@deriving equal, sexp_of]
4646+ end)
4747+ x
4848+ y;
4949+ [%expect {| |}]
5050+;;
5151+5252+let%expect_test "also in extensions" =
5353+ let open struct
5454+ (* versions of types with no sexps derived *)
5555+ type foo_int = int
5656+ type foo_string = string
5757+ type foo_bool = bool
5858+ type foo_float = float
5959+ end in
6060+ let x : foo_int t = 42 in
6161+ let sexp = [%sexp_of: (foo_int[@phantom]) t] x in
6262+ print_s sexp;
6363+ [%expect {| 42 |}];
6464+ let y : foo_string t = [%of_sexp: (foo_string[@phantom]) t] sexp in
6565+ Expect_test_helpers_base.require_equal (module Int) x y;
6666+ [%expect {| |}];
6767+ let x : (foo_int, string) u = [ "hello"; "world" ] in
6868+ let sexp = [%sexp_of: ((foo_int[@phantom]), string) u] x in
6969+ print_s sexp;
7070+ [%expect {| (hello world) |}];
7171+ let y : (foo_bool, string) u = [%of_sexp: ((foo_bool[@phantom]), string) u] sexp in
7272+ Expect_test_helpers_base.require_equal
7373+ (module struct
7474+ type t = string list [@@deriving equal, sexp_of]
7575+ end)
7676+ x
7777+ y;
7878+ [%expect {| |}];
7979+ let x : (foo_int, foo_string) v = "test" in
8080+ let sexp = [%sexp_of: ((foo_int[@phantom]), (foo_string[@phantom])) v] x in
8181+ print_s sexp;
8282+ [%expect {| test |}];
8383+ let y : (foo_bool, foo_float) v =
8484+ [%of_sexp: ((foo_bool[@phantom]), (foo_float[@phantom])) v] sexp
8585+ in
8686+ Expect_test_helpers_base.require_equal (module String) x y;
8787+ [%expect {| |}];
8888+ let x : (int, foo_string) w = Some 42 in
8989+ let sexp = [%sexp_of: (int, (foo_string[@phantom])) w] x in
9090+ print_s sexp;
9191+ [%expect {| (42) |}];
9292+ let y : (int, foo_bool) w = [%of_sexp: (int, (foo_bool[@phantom])) w] sexp in
9393+ Expect_test_helpers_base.require_equal
9494+ (module struct
9595+ type t = int option [@@deriving equal, sexp_of]
9696+ end)
9797+ x
9898+ y;
9999+ [%expect {| |}]
100100+;;
+1
vendor/opam/ppx_sexp_conv/test/phantom.mli
···11+(*_ This file is intentionally left blank. *)
+71
vendor/opam/ppx_sexp_conv/test/phantom.mlt
···11+open Ppx_sexp_conv_lib.Conv
22+33+type 'a[@phantom] t = int [@@deriving sexp]
44+type ('a[@phantom], 'b) u = 'b list [@@deriving sexp]
55+type ('a[@phantom], 'b[@phantom]) v = string [@@deriving sexp]
66+type ('a, 'b[@phantom]) w = 'a option [@@deriving sexp]
77+88+[%%expect {| |}];;
99+1010+(* missing [[@phantom]]s *)
1111+1212+[%sexp_of: int t] 42
1313+1414+[%%expect
1515+ {|
1616+Line _, characters _-_:
1717+Error: The function sexp_of_t has type int -> Sexplib0.Sexp.t
1818+ It is applied to too many arguments
1919+Line _, characters _-_:
2020+ This extra argument is not expected.
2121+|}]
2222+2323+2424+type my_int1 = int
2525+2626+let sexp_of_my_int1 x =
2727+ assert (Int.equal x 42);
2828+ sexp_of_int x
2929+;;
3030+3131+type my_int2 = int
3232+3333+let sexp_of_my_int2 = sexp_of_int;;
3434+3535+print_endline
3636+ (Base.Sexp.to_string_hum ([%sexp_of: (my_int1, (my_int2[@phantom])) u] [ 42 ]))
3737+3838+[%%expect
3939+ {|
4040+(42)
4141+|}]
4242+;;
4343+4444+[%sexp_of: (my_int1, (my_int2[@phantom])) u] [ 43 ]
4545+4646+[%%expect
4747+ {|
4848+Exception: "Assert_failure phantom.mlt:30:2".
4949+|}]
5050+;;
5151+5252+(* extra [[@phantom]]s *)
5353+5454+[%sexp_of: ((int[@phantom]), (string[@phantom])) u] [ "hello"; "world" ]
5555+5656+[%%expect
5757+ {|
5858+Line _, characters _-_:
5959+Error: This expression should not be a list literal, the expected type is
6060+ 'a -> Sexplib0.Sexp.t
6161+|}]
6262+;;
6363+6464+[%sexp_of: ((int[@phantom]), (string[@phantom])) w] (Some 42)
6565+6666+[%%expect
6767+ {|
6868+Line _, characters _-_:
6969+Error: This expression should not be a constructor, the expected type is
7070+ 'a -> Sexplib0.Sexp.t
7171+|}]
···11+open! Base
22+33+[@@@disable_unused_warnings]
44+55+module Sexp_of_t = struct
66+ type t = A [@@deriving sexp_of ~portable]
77+end
88+99+module Sexp_of_t_portable : sig
1010+ include module type of struct
1111+ include Sexp_of_t
1212+ end
1313+end = struct
1414+ include Sexp_of_t
1515+end
1616+1717+module Sexp_of_not_t = struct
1818+ type not_t = A [@@deriving sexp_of ~portable]
1919+end
2020+2121+module Sexp_of_not_t_portable : sig
2222+ include module type of struct
2323+ include Sexp_of_not_t
2424+ end
2525+end = struct
2626+ include Sexp_of_not_t
2727+end
2828+2929+module Of_sexp_t = struct
3030+ type t = A [@@deriving of_sexp ~portable]
3131+end
3232+3333+module Of_sexp_t_portable : sig
3434+ include module type of struct
3535+ include Of_sexp_t
3636+ end
3737+end = struct
3838+ include Of_sexp_t
3939+end
4040+4141+module Of_sexp_not_t = struct
4242+ type not_t = A [@@deriving of_sexp ~portable]
4343+end
4444+4545+module Of_sexp_not_t_portable : sig
4646+ include module type of struct
4747+ include Of_sexp_not_t
4848+ end
4949+end = struct
5050+ include Of_sexp_not_t
5151+end
5252+5353+module Sexp_t = struct
5454+ type t = A [@@deriving sexp ~portable]
5555+end
5656+5757+module Sexp_t_portable : sig
5858+ include module type of struct
5959+ include Sexp_t
6060+ end
6161+end = struct
6262+ include Sexp_t
6363+end
6464+6565+module Sexp_not_t = struct
6666+ type not_t = A [@@deriving sexp ~portable]
6767+end
6868+6969+module Sexp_not_t_portable : sig
7070+ include module type of struct
7171+ include Sexp_not_t
7272+ end
7373+end = struct
7474+ include Sexp_not_t
7575+end
7676+7777+module Sexp_t1 = struct
7878+ type 'a t = A of 'a [@@deriving sexp ~portable]
7979+end
8080+8181+module Sexp_t1_portable : sig
8282+ include module type of struct
8383+ include Sexp_t1
8484+ end
8585+end = struct
8686+ include Sexp_t1
8787+end
···11+open! Base
22+33+module type S = sig
44+ type t [@@deriving sexp_grammar]
55+end
66+77+module Key = struct
88+ type t = int [@@deriving sexp_grammar]
99+end
1010+1111+module Pair = struct
1212+ type ('a, 'b) t = 'a * 'b [@@deriving sexp_grammar]
1313+1414+ module M (A : T) = struct
1515+ type 'b t = A.t * 'b
1616+ end
1717+1818+ let m__t_sexp_grammar (type a) (module Key : S with type t = a) v_sexp_grammar =
1919+ t_sexp_grammar Key.t_sexp_grammar v_sexp_grammar
2020+ ;;
2121+end
2222+2323+type t = string Pair.M(Key).t [@@deriving_inline sexp_grammar]
2424+2525+let _ = fun (_ : t) -> ()
2626+2727+let t_sexp_grammar : t Sexplib0.Sexp_grammar.t =
2828+ { untyped =
2929+ Lazy
3030+ (Basement.Portable_lazy.from_fun (fun () : Sexplib0.Sexp_grammar.grammar ->
3131+ (Pair.m__t_sexp_grammar (module Key) string_sexp_grammar).untyped))
3232+ }
3333+;;
3434+3535+let _ = t_sexp_grammar
3636+3737+[@@@end]
···11+open! Base
22+33+(* Not sure how much people will want to use this, considering that the input is more
44+ complicated and specific than the output, but they have it. *)
55+module type S = sig
66+ val t_sexp_grammar : [%sexp_grammar: int Map.M(String).t]
77+end
88+99+module _ (M : S) : sig
1010+ val t_sexp_grammar : int Map.M(String).t Sexplib0.Sexp_grammar.t [@@warning "-32"]
1111+end =
1212+ M
1313+1414+(* The grammar is illegible, so just make sure it builds. *)
1515+1616+let (_ : _ Sexplib0.Sexp_grammar.t) = [%sexp_grammar: int Map.M(String).t]
1717+1818+(* This used to give a compilation error. *)
1919+let (_ : _ Sexplib0.Sexp_grammar.t) = [%sexp_grammar: _ list]
···11+module type Sexp_of = sig
22+ type t [@@deriving_inline sexp_of ~portable]
33+44+ include sig
55+ [@@@ocaml.warning "-32"]
66+77+ val sexp_of_t : t -> Sexplib0.Sexp.t
88+ end
99+ [@@ocaml.doc "@inline"]
1010+1111+ [@@@end]
1212+end
1313+1414+module type Sexp_of_local = sig
1515+ type t [@@deriving_inline sexp_of ~stackify ~portable]
1616+1717+ include sig
1818+ [@@@ocaml.warning "-32"]
1919+2020+ val sexp_of_t : t -> Sexplib0.Sexp.t
2121+ val sexp_of_t__stack : t -> Sexplib0.Sexp.t
2222+ end
2323+ [@@ocaml.doc "@inline"]
2424+2525+ [@@@end]
2626+end
2727+2828+module type Of_sexp = sig
2929+ type t [@@deriving_inline of_sexp ~portable]
3030+3131+ include sig
3232+ [@@@ocaml.warning "-32"]
3333+3434+ val t_of_sexp : Sexplib0.Sexp.t -> t
3535+ end
3636+ [@@ocaml.doc "@inline"]
3737+3838+ [@@@end]
3939+end
4040+4141+module type Of_sexp_poly = sig
4242+ type t [@@deriving_inline of_sexp_poly ~portable]
4343+4444+ include sig
4545+ [@@@ocaml.warning "-32"]
4646+4747+ val t_of_sexp : Sexplib0.Sexp.t -> t
4848+ val __t_of_sexp__ : Sexplib0.Sexp.t -> t
4949+ end
5050+ [@@ocaml.doc "@inline"]
5151+5252+ [@@@end]
5353+end
5454+5555+module type Sexp = sig
5656+ type t [@@deriving_inline sexp ~portable]
5757+5858+ include sig
5959+ [@@@ocaml.warning "-32"]
6060+6161+ include Sexplib0.Sexpable.S with type t := t
6262+ end
6363+ [@@ocaml.doc "@inline"]
6464+6565+ [@@@end]
6666+end
6767+6868+module type Sexp_local = sig
6969+ type t [@@deriving_inline sexp ~stackify ~portable]
7070+7171+ include sig
7272+ [@@@ocaml.warning "-32"]
7373+7474+ include Sexplib0.Sexpable.S__stack with type t := t
7575+ end
7676+ [@@ocaml.doc "@inline"]
7777+7878+ [@@@end]
7979+end
8080+8181+module type Sexp_poly = sig
8282+ type t [@@deriving_inline sexp_poly ~portable]
8383+8484+ include sig
8585+ [@@@ocaml.warning "-32"]
8686+8787+ val t_of_sexp : Sexplib0.Sexp.t -> t
8888+ val __t_of_sexp__ : Sexplib0.Sexp.t -> t
8989+ val sexp_of_t : t -> Sexplib0.Sexp.t
9090+ end
9191+ [@@ocaml.doc "@inline"]
9292+9393+ [@@@end]
9494+end
9595+9696+module type Sexp_poly_local = sig
9797+ type t [@@deriving_inline sexp_poly ~stackify ~portable]
9898+9999+ include sig
100100+ [@@@ocaml.warning "-32"]
101101+102102+ val t_of_sexp : Sexplib0.Sexp.t -> t
103103+ val __t_of_sexp__ : Sexplib0.Sexp.t -> t
104104+ val sexp_of_t : t -> Sexplib0.Sexp.t
105105+ val sexp_of_t__stack : t -> Sexplib0.Sexp.t
106106+ end
107107+ [@@ocaml.doc "@inline"]
108108+109109+ [@@@end]
110110+end
···11+open! Base
22+33+open struct
44+ type t = int [@@deriving_inline sexp_grammar]
55+66+ let _ = fun (_ : t) -> ()
77+ let (t_sexp_grammar : t Sexplib0.Sexp_grammar.t) = int_sexp_grammar
88+ let _ = t_sexp_grammar
99+1010+ [@@@end]
1111+end
1212+1313+type nonrec t = t [@@deriving_inline sexp_grammar]
1414+1515+let _ = fun (_ : t) -> ()
1616+let (t_sexp_grammar : t Sexplib0.Sexp_grammar.t) = t_sexp_grammar
1717+let _ = t_sexp_grammar
1818+1919+[@@@end]
···11+(* This toplevel test exercises some polymorphic variants that sexp_grammar rejects. We
22+ show that in each case, the compiler or sexp would have given an error anyway. *)
33+44+open Base
55+66+type t = [ `A of int & string ] [@@deriving sexp]
77+88+[%%expect
99+ {|
1010+Line _, characters _-_:
1111+Error: unsupported: polymorphic variant intersection type
1212+|}]
1313+1414+type t = [ `A of int & string ] [@@deriving sexp_grammar]
1515+1616+[%%expect
1717+ {|
1818+Line _, characters _-_:
1919+Error: sexp_grammar: intersection types are unsupported
2020+|}]
2121+2222+type t = [> `A ] [@@deriving sexp]
2323+2424+[%%expect
2525+ {|
2626+Line _, characters _-_:
2727+Error: Type unsupported for ppx [of_sexp] conversion (open polymorphic variant type)
2828+|}]
2929+3030+type t = [> `A ] [@@deriving sexp_grammar]
3131+3232+[%%expect
3333+ {|
3434+Line _, characters _-_:
3535+Error: sexp_grammar: open polymorphic variant types are unsupported
3636+|}]
3737+3838+type t = [< `A ] [@@deriving sexp]
3939+4040+[%%expect
4141+ {|
4242+Line _, characters _-_:
4343+Error: A type variable is unbound in this type declaration.
4444+ In type [< `A ] as 'a the variable 'a is unbound
4545+|}]
4646+4747+type t = [< `A ] [@@deriving sexp_grammar]
4848+4949+[%%expect
5050+ {|
5151+Line _, characters _-_:
5252+Error: A type variable is unbound in this type declaration.
5353+ In type [< `A ] as 'a the variable 'a is unbound
5454+|}]
5555+5656+type 'a t = [< `A ] as 'a [@@deriving sexp]
5757+5858+[%%expect
5959+ {|
6060+Line _, characters _-_:
6161+Error: Type unsupported for ppx [of_sexp] conversion (type alias)
6262+|}]
6363+6464+type 'a t = [< `A ] as 'a [@@deriving sexp_grammar]
6565+6666+[%%expect
6767+ {|
6868+Line _, characters _-_:
6969+Error: sexp_grammar: type aliases are unsupported
7070+|}]
7171+7272+type a = A : [> ] -> a [@@deriving sexp]
7373+7474+[%%expect
7575+ {|
7676+Line _, characters _-_:
7777+Error: Type unsupported for ppx [of_sexp] conversion (open polymorphic variant type)
7878+|}]
7979+8080+type a = A : [> ] -> a [@@deriving sexp_of]
8181+8282+[%%expect
8383+ {|
8484+Line _, characters _-_:
8585+Error: Type unsupported for ppx [sexp_of] conversion (open polymorphic variant type)
8686+|}]
8787+8888+type a = [ `A ] [@@deriving sexp];;
8989+9090+#verbose true
9191+9292+let f = [%sexp_of: [< a ]]
9393+9494+[%%expect
9595+ {|
9696+val f : [< a ] -> Sexp.t = <fun>
9797+|}]
9898+9999+let f = [%of_sexp: [> a ]]
100100+101101+[%%expect
102102+ {|
103103+Line _, characters _-_:
104104+Error: Type unsupported for ppx [of_sexp] conversion (open polymorphic variant type)
105105+|}]
106106+107107+let f = [%of_sexp: [ | a ]]
108108+109109+[%%expect
110110+ {|
111111+val f : Sexp.t -> a = <fun>
112112+|}]
113113+;;
114114+115115+#verbose false
···11+open Ppx_sexp_conv_lib
22+open Conv;;
33+44+#verbose true
55+66+module No_keys = struct
77+ type t = (unit[@sexp_grammar.tag]) [@@deriving sexp_grammar]
88+end
99+1010+[%%expect
1111+ {|
1212+Line _, characters _-_:
1313+Error: :: expected
1414+|}]
1515+1616+module Key_literal_is_not_string = struct
1717+ type t = (unit[@sexp_grammar.tag 1 = [%sexp ""]]) [@@deriving sexp_grammar]
1818+end
1919+2020+[%%expect
2121+ {|
2222+Line _, characters _-_:
2323+Error: This expression has type int but an expression was expected of type
2424+ string
2525+|}]
2626+2727+module Key_ident_is_not_string = struct
2828+ let k = 1
2929+3030+ type t = (unit[@sexp_grammar.tag k = [%sexp ""]]) [@@deriving sexp_grammar]
3131+end
3232+3333+[%%expect
3434+ {|
3535+Line _, characters _-_:
3636+Error: This expression has type int but an expression was expected of type
3737+ string
3838+|}]
3939+4040+module Value_literal_is_not_sexp = struct
4141+ type t = (unit[@sexp_grammar.tag "key" = 1]) [@@deriving sexp_grammar]
4242+end
4343+4444+[%%expect
4545+ {|
4646+Line _, characters _-_:
4747+Error: This expression has type int but an expression was expected of type
4848+ Sexp.t
4949+|}]
5050+5151+module Value_ident_is_not_sexp = struct
5252+ let v = 1
5353+5454+ type t = (unit[@sexp_grammar.tag "key" = v]) [@@deriving sexp_grammar]
5555+end
5656+5757+[%%expect
5858+ {|
5959+Line _, characters _-_:
6060+Error: This expression has type int but an expression was expected of type
6161+ Sexp.t
6262+|}]