forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvfile_kind.ml
71 lines (54 loc) · 1.25 KB
/
vfile_kind.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
open! Stdune
open Import
module Id = struct
type 'a tag = ..
module type S = sig
type t
type 'a tag += X : t tag
end
type 'a t = (module S with type t = 'a)
let create (type a) () =
let module M = struct
type t = a
type 'a tag += X : t tag
end in
(module M : S with type t = a)
let eq (type a) (type b)
(module A : S with type t = a)
(module B : S with type t = b)
: (a, b) Type_eq.t option =
match A.X with
| B.X -> Some Type_eq.T
| _ -> None
end
module type S = sig
type t
val id : t Id.t
val load : Path.t -> t
val to_string : t -> string
end
type 'a t = (module S with type t = 'a)
let eq (type a) (type b)
(module A : S with type t = a)
(module B : S with type t = b) =
Id.eq A.id B.id
module Make
(T : sig
type t
val encode : t Dune_lang.Encoder.t
val name : string
end)
: S with type t = T.t =
struct
type t = T.t
(* XXX dune dump should make use of this *)
let _t = T.encode
module P = Utils.Persistent(struct
type nonrec t = t
let name = "VFILE_KIND-" ^ T.name
let version = 1
end)
let id = Id.create ()
let to_string x = P.to_out_string x
let load path = Option.value_exn (P.load path)
end