Skip to content

Commit 48d3810

Browse files
committed
Extract Irmin_type and its PPX into their own new repository
1 parent 5029c3e commit 48d3810

File tree

168 files changed

+1388
-1346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+1388
-1346
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/_build
2+
/_opam
3+
*~
4+
*.install
5+
*.merlin
6+
.envrc
7+
\#*
8+
.#*
9+
.*.swp
10+
**/.DS_Store

.ocamlformat

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version = 0.15.0
2+
profile = conventional
3+
parse-docstrings
4+
break-infix = fit-or-vertical
5+
indicate-multiline-delimiters = no

LICENSE.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## ISC License
2+
3+
Copyright (c) 2013-2020 Thomas Gazagnaire <[email protected]>
4+
5+
Permission to use, copy, modify, and distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README_PPX.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
## ppx_irmin
1+
## ppx_repr
22

3-
PPX extension for automatically generating Irmin type representations.
3+
PPX extension for automatically generating type representations.
44

55
### Overview
66

7-
`ppx_irmin` automatically generates Irmin type representations (values of type
8-
`_ Irmin.Type.t`) corresponding to type declarations in your code. For example:
7+
`ppx_repr` automatically generates type representations (values of type
8+
`_ Repr.Type.t`) corresponding to type declarations in your code. For example:
99

1010
```ocaml
1111
type 'a tree =
1212
| Branch of tree * bool option * tree
13-
| Leaf of 'a [@@deriving irmin]
13+
| Leaf of 'a [@@deriving repr]
1414
```
1515

1616
will be expanded to:
@@ -19,7 +19,7 @@ will be expanded to:
1919
type 'a tree = (* as above *)
2020
2121
let tree_t leaf_t =
22-
let open Irmin.Type in
22+
let open Repr.Type in
2323
mu (fun tree_t ->
2424
variant "tree" (fun branch leaf -> function
2525
| Branch (x1, x2, x3) -> branch (x1, x2, x3)
@@ -34,36 +34,36 @@ extension point.
3434

3535
### Installation and usage
3636

37-
`ppx_irmin` may be installed via [opam](https://opam.ocaml.org/):
37+
`ppx_repr` may be installed via [opam](https://opam.ocaml.org/):
3838

3939
```
40-
opam install ppx_irmin
40+
opam install ppx_repr
4141
```
4242

4343
If you're using the [dune](https://github.com/ocaml/dune) build system, add the
4444
following field to your `library`, `executable` or `test` stanza:
4545

4646
```
47-
(preprocess (pps ppx_irmin))
47+
(preprocess (pps ppx_repr))
4848
```
4949

50-
You can now use `[@@deriving irmin]` after a type declaration in your code to
51-
automatically derive an Irmin type representation with the same name.
50+
You can now use `[@@deriving repr]` after a type declaration in your code to
51+
automatically derive a type representation with the same name.
5252

5353
### Specifics
5454

55-
`ppx_irmin` supports all of the type combinators exposed in the
56-
[Irmin.Type](https://docs.mirage.io/irmin/Irmin/Type/index.html) module (basic
55+
`ppx_repr` supports all of the type combinators exposed in the
56+
[Repr.Type](https://docs.mirage.io/irmin/Irmin.Type/index.html) module (basic
5757
types, records, variants (plain and closed polymorphic), recursive types etc.).
5858
Types with parameters will result in parameterised representations (i.e. type
5959
`'a t` is generated a representation of type `'a Type.t -> 'a t Type.t`).
6060

61-
To supply base representations from a module other than `Irmin.Type` (such as
62-
when `Irmin.Type` is aliased to a different module path), the `lib` argument
63-
can be passed to `@@deriving irmin`:
61+
To supply base representations from a module other than `Repr.Type` (such as
62+
when `Repr.Type` is aliased to a different module path), the `lib` argument
63+
can be passed to `@@deriving repr`:
6464

6565
```ocaml
66-
type foo = unit [@@deriving irmin { lib = Some "Mylib.Types" }]
66+
type foo = unit [@@deriving repr { lib = Some "Mylib.Types" }]
6767
6868
(* generates the value *)
6969
val foo_t = Mylib.Types.unit
@@ -79,50 +79,50 @@ type-name is `t`, in which case the representation is simply `t`. This
7979
behaviour can be overridden using the `name` argument, as in:
8080

8181
```ocaml
82-
type foo = string list * int32 [@@deriving irmin { name = "foo_repr" }]
82+
type foo = string list * int32 [@@deriving repr { name = "foo_repr" }]
8383
8484
(* generates the value *)
85-
val foo_repr = Irmin.Type.(pair (list string) int32)
85+
val foo_repr = Repr.Type.(pair (list string) int32)
8686
```
8787

88-
If the type contains an abstract type, `ppx_irmin` will expect to find a
88+
If the type contains an abstract type, `ppx_repr` will expect to find a
8989
corresponding type representation using its own naming rules. This can be
9090
overridden using the `[@repr ...]` attribute, as in:
9191

9292
```ocaml
93-
type bar = (foo [@repr foo_repr], string) result [@@deriving irmin]
93+
type bar = (foo [@repr foo_repr], string) result [@@deriving repr]
9494
9595
(* generates the value *)
96-
val bar_t = Irmin.Type.(result foo_repr string)
96+
val bar_t = Repr.Type.(result foo_repr string)
9797
```
9898

9999
Built-in abstract types such as `unit` are assumed to be represented in
100-
`Irmin.Type`. This behaviour can be overridden with the `[@nobuiltin]`
100+
`Repr.Type`. This behaviour can be overridden with the `[@nobuiltin]`
101101
attribute:
102102

103103
```ocaml
104-
type t = unit [@nobuiltin] [@@deriving irmin]
104+
type t = unit [@nobuiltin] [@@deriving repr]
105105
106106
(* generates the value *)
107-
let t = unit_t (* not [Irmin.Type.unit] *)
107+
let t = unit_t (* not [Repr.Type.unit] *)
108108
```
109109

110110
#### Signature type definitions
111111

112-
The `ppx_irmin` deriver can also be used in signatures to expose the
112+
The `ppx_repr` deriver can also be used in signatures to expose the
113113
auto-generated value:
114114

115115
```ocaml
116116
module Contents : sig
117-
type t = int32 [@@deriving irmin]
117+
type t = int32 [@@deriving repr]
118118
119119
(* exposes repr in signature *)
120-
val t : t Irmin.Type.t
120+
val t : t Repr.Type.t
121121
122122
end = struct
123-
type t = int32 [@@deriving irmin]
123+
type t = int32 [@@deriving repr]
124124
125125
(* generates repr value *)
126-
val t = Irmin.Type.int32
126+
val t = Repr.Type.int32
127127
end
128128
```
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
(executable
22
(name main)
3-
(libraries irmin bechamel fpath yojson ppx_deriving_yojson.runtime unix)
3+
(libraries repr bechamel fpath yojson ppx_deriving_yojson.runtime unix)
44
(preprocess
5-
(pps ppx_irmin ppx_deriving_yojson)))
5+
(pps ppx_repr ppx_deriving_yojson)))
66

77
(rule
88
(alias bench)
9-
(package irmin-bench)
9+
(package repr-bench)
1010
(deps main.exe)
1111
(action (progn)))
1212

1313
;; Require [main.ml] to compile during tests
1414

1515
(rule
1616
(alias runtest)
17-
(package irmin-bench)
17+
(package repr-bench)
1818
(deps main.exe)
1919
(action progn))

bench/irmin/main.ml renamed to bench/main.ml

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
open Bechamel
22
open Toolkit
3-
module T = Irmin.Type
4-
module Hash = Irmin.Hash.BLAKE2B
3+
module T = Repr.Type
54
open Output
65

76
module Generic_op = struct
@@ -96,10 +95,10 @@ module Faker = struct
9695
let triple a b c () = (a (), b (), c ())
9796

9897
type record = { foo : string; bar : int64; baz : bool * unit }
99-
[@@deriving irmin]
98+
[@@deriving repr]
10099

101100
type variant = Foo of string | Bar of int64 | Baz of bool * unit
102-
[@@deriving irmin]
101+
[@@deriving repr]
103102

104103
let record () =
105104
{ foo = string 10 (); bar = int64 (); baz = (bool (), unit ()) }
@@ -117,9 +116,9 @@ module Faker = struct
117116

118117
let fixed_string () = string 5 ()
119118

120-
type 'a node = { left : 'a; v : fixed_string; right : 'a } [@@deriving irmin]
119+
type 'a node = { left : 'a; v : fixed_string; right : 'a } [@@deriving repr]
121120

122-
type tree = Branch of tree node | Leaf of int [@@deriving irmin]
121+
type tree = Branch of tree node | Leaf of int [@@deriving repr]
123122

124123
let tree () =
125124
let rec inner depth =
@@ -164,9 +163,6 @@ module Data = struct
164163

165164
let bool = mk_data T.bool Faker.bool
166165

167-
let hash =
168-
mk_data Hash.t (fun () -> Hash.hash (fun f -> f (Faker.string 1024 ())))
169-
170166
let string_1024 = mk_data T.string Faker.(string 1024)
171167

172168
let bytes_1024 = mk_data T.bytes Faker.(bytes 1024)
@@ -239,7 +235,6 @@ let test_operation ~name (op : Generic_op.t) =
239235
test ~name:"short (8 <= b <= 15)" Data.short_int;
240236
test ~name:"long (16 <= b <= 32)" Data.long_int;
241237
];
242-
test ~name:"hash" Data.hash;
243238
test ~name:"string<1024>" Data.string_1024;
244239
test ~name:"bytes<1024>" Data.bytes_1024;
245240
test ~name:"int32" Data.int32;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dune-project

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(lang dune 2.7)
2+
(generate_opam_files true)
3+
(allow_approximate_merlin)
4+
5+
(name repr)
6+
(source (github mirage/repr))
7+
(license ISC)
8+
(authors "Thomas Gazagnaire")
9+
(maintainers "[email protected]")
10+
11+
(package
12+
(name repr)
13+
(depends
14+
(ocaml (>= 4.08.0))
15+
(fmt (>= 0.8.0))
16+
uutf
17+
(jsonm (>= 1.0.0))
18+
(base64 (>= 2.0.0))
19+
(alcotest (and (>= 1.1.0) :with-test)))
20+
(synopsis "Dynamic type representaitons. Provides no stability guarantee")
21+
(description "\
22+
!!!!!!!!!!!!!!!!!!!!
23+
!!!!! UNSTABLE !!!!!
24+
!!!!!!!!!!!!!!!!!!!!
25+
26+
This package defines a library of combinators for building dynamic type
27+
representations and a set of generic operations over representable types, used
28+
in the implementation of Irmin and related packages.
29+
30+
It is not intended for public consumption and provides no stability guarantee.
31+
"))
32+
33+
(package
34+
(name ppx_repr)
35+
(depends
36+
(repr (= :version))
37+
(ppxlib (and (>= 0.12.0) (< 0.18.0))))
38+
(synopsis "PPX deriver for type representations")
39+
(description "PPX deriver for type representations"))
40+
41+
(package
42+
(name repr-bench)
43+
(depends
44+
(repr (= :version))
45+
bechamel
46+
yojson
47+
ppx_deriving_yojson)
48+
(synopsis "Benchmarks for the `repr` package")
49+
(description "Benchmarks for the `repr` package"))
50+
51+
(package
52+
(name repr-fuzz)
53+
(depends
54+
(repr (= :version))
55+
(crowbar (= 0.2))
56+
(ppxlib (and (>= 0.12.0) (< 0.18.0))))
57+
(synopsis "Fuzz tests for the `repr` package")
58+
(description "Fuzz tests for the `repr` package"))
59+

fuzz/dune

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
(executable
2-
(name fuzz_types)
3-
(libraries digestif.c crowbar irmin)
2+
(name main)
3+
(libraries digestif.c crowbar repr)
44
(preprocess
5-
(pps irmin-fuzz.rewriter)))
5+
(pps repr-fuzz.rewriter)))
66

77
;; Start fuzzing when calling `dune build @fuzz`.
88

99
(rule
1010
(alias fuzz)
1111
(deps
12-
(source_tree ./input)
13-
fuzz_types.exe)
12+
(source_tree ./input))
1413
(action
15-
(run afl-fuzz -i ./input -o output ./fuzz_types.exe @@)))
14+
(run afl-fuzz -i ./input -o output %{exe:fuzz_types.exe} @@)))
1615

1716
(rule
1817
(alias runtest)
19-
(package irmin-fuzz)
20-
(deps fuzz_types.exe)
18+
(package repr-fuzz)
19+
(deps main.exe)
2120
(action progn))

0 commit comments

Comments
 (0)