| 1 |
open Ppx_hash_lib.Std |
| 2 |
open Hash.Builtin |
| 3 |
|
| 4 |
module Check_struct_items_match_sig_items = struct |
| 5 |
module M : sig |
| 6 |
type t0 [@@deriving hash] |
| 7 |
type _ t1 [@@deriving hash] |
| 8 |
type (_, _) t2 [@@deriving hash] |
| 9 |
end = struct |
| 10 |
type t0 = int [@@deriving hash] |
| 11 |
type 'a t1 = 'a * int [@@deriving hash] |
| 12 |
type ('a, 'b) t2 = 'a * 'b * int [@@deriving hash] |
| 13 |
end |
| 14 |
end |
| 15 |
|
| 16 |
module Examples_from_design_doc = struct |
| 17 |
type a = int [@@deriving hash] |
| 18 |
type b = int [@@deriving hash] |
| 19 |
type c = int [@@deriving hash] |
| 20 |
type t1 = a * b * c [@@deriving hash] |
| 21 |
|
| 22 |
type t2 = |
| 23 |
{ a : a |
| 24 |
; b : b |
| 25 |
; c : c |
| 26 |
} |
| 27 |
[@@deriving hash] |
| 28 |
|
| 29 |
type t3 = |
| 30 |
| Foo |
| 31 |
| Bar of a |
| 32 |
| Qaz of b * c |
| 33 |
[@@deriving hash] |
| 34 |
|
| 35 |
type t4 = |
| 36 |
[ `Foo of a |
| 37 |
| `Bar |
| 38 |
] |
| 39 |
[@@deriving hash] |
| 40 |
|
| 41 |
type 'a t5 = ('a * 'a) list [@@deriving hash] |
| 42 |
type t6 = int * string list [@@deriving hash] |
| 43 |
type t7 = int lazy_t [@@deriving hash] |
| 44 |
end |
| 45 |
|
| 46 |
module Single_constructor_variant = struct |
| 47 |
type t = Foo [@@deriving_inline hash] |
| 48 |
|
| 49 |
let _ = fun (_ : t) -> () |
| 50 |
|
| 51 |
let (hash_fold_t : Ppx_hash_lib.Std.Hash.state -> t -> Ppx_hash_lib.Std.Hash.state) = |
| 52 |
(fun hsv arg -> |
| 53 |
match arg with |
| 54 |
| Foo -> hsv |
| 55 |
: Ppx_hash_lib.Std.Hash.state -> t -> Ppx_hash_lib.Std.Hash.state) |
| 56 |
;; |
| 57 |
|
| 58 |
let _ = hash_fold_t |
| 59 |
|
| 60 |
let (hash : t -> Ppx_hash_lib.Std.Hash.hash_value) = |
| 61 |
let func arg = |
| 62 |
Ppx_hash_lib.Std.Hash.get_hash_value |
| 63 |
(let hsv = Ppx_hash_lib.Std.Hash.create () in |
| 64 |
hash_fold_t hsv arg) |
| 65 |
in |
| 66 |
fun x -> func x |
| 67 |
;; |
| 68 |
|
| 69 |
let _ = hash |
| 70 |
|
| 71 |
[@@@deriving.end] |
| 72 |
end |
| 73 |
|
| 74 |
module Flat_variant = struct |
| 75 |
type t = |
| 76 |
| Foo |
| 77 |
| Bar |
| 78 |
| Baz |
| 79 |
[@@deriving_inline hash] |
| 80 |
|
| 81 |
let _ = fun (_ : t) -> () |
| 82 |
|
| 83 |
let (hash_fold_t : Ppx_hash_lib.Std.Hash.state -> t -> Ppx_hash_lib.Std.Hash.state) = |
| 84 |
(fun hsv arg -> |
| 85 |
Ppx_hash_lib.Std.Hash.fold_int |
| 86 |
hsv |
| 87 |
(match arg with |
| 88 |
| Foo -> 0 |
| 89 |
| Bar -> 1 |
| 90 |
| Baz -> 2) |
| 91 |
: Ppx_hash_lib.Std.Hash.state -> t -> Ppx_hash_lib.Std.Hash.state) |
| 92 |
;; |
| 93 |
|
| 94 |
let _ = hash_fold_t |
| 95 |
|
| 96 |
let (hash : t -> Ppx_hash_lib.Std.Hash.hash_value) = |
| 97 |
let func arg = |
| 98 |
Ppx_hash_lib.Std.Hash.get_hash_value |
| 99 |
(let hsv = Ppx_hash_lib.Std.Hash.create () in |
| 100 |
hash_fold_t hsv arg) |
| 101 |
in |
| 102 |
fun x -> func x |
| 103 |
;; |
| 104 |
|
| 105 |
let _ = hash |
| 106 |
|
| 107 |
[@@@deriving.end] |
| 108 |
end |
| 109 |
|
| 110 |
module String = struct |
| 111 |
include String |
| 112 |
|
| 113 |
let hash_fold_t = hash_fold_string |
| 114 |
let hash = hash_string |
| 115 |
end |
| 116 |
|
| 117 |
let hash = `Should_refer_to_Hashtbl_hash_explicitly |
| 118 |
|
| 119 |
type 'a array_frozen = 'a array |
| 120 |
type 'a ref_frozen = 'a ref |
| 121 |
|
| 122 |
module M1s = struct |
| 123 |
type s = unit [@@deriving hash] |
| 124 |
end |
| 125 |
|
| 126 |
module M2s = struct |
| 127 |
type s = int [@@deriving hash] |
| 128 |
end |
| 129 |
|
| 130 |
module M1 = struct |
| 131 |
type t = unit [@@deriving hash] |
| 132 |
end |
| 133 |
|
| 134 |
module M2 = struct |
| 135 |
type t = int [@@deriving hash] |
| 136 |
end |
| 137 |
|
| 138 |
module M3 = struct |
| 139 |
type t = bool [@@deriving hash] |
| 140 |
end |
| 141 |
|
| 142 |
module M4 = struct |
| 143 |
type t = int32 [@@deriving hash] |
| 144 |
end |
| 145 |
|
| 146 |
module M5 = struct |
| 147 |
type t = nativeint [@@deriving hash] |
| 148 |
end |
| 149 |
|
| 150 |
module M6 = struct |
| 151 |
type t = int64 [@@deriving hash] |
| 152 |
end |
| 153 |
|
| 154 |
module M7 = struct |
| 155 |
type t = float [@@deriving hash] |
| 156 |
end |
| 157 |
|
| 158 |
module M8 = struct |
| 159 |
type t = bool * float [@@deriving hash] |
| 160 |
end |
| 161 |
|
| 162 |
module M9 = struct |
| 163 |
type t = bool * float * int [@@deriving hash] |
| 164 |
end |
| 165 |
|
| 166 |
module M10 = struct |
| 167 |
type t = bool * float * int * string [@@deriving hash] |
| 168 |
end |
| 169 |
|
| 170 |
module M11 = struct |
| 171 |
type t = int ref_frozen [@@deriving hash] |
| 172 |
end |
| 173 |
|
| 174 |
module M12 = struct |
| 175 |
type t = (float * float) option [@@deriving hash] |
| 176 |
end |
| 177 |
|
| 178 |
module M13 = struct |
| 179 |
type t = float array_frozen [@@deriving hash] |
| 180 |
end |
| 181 |
|
| 182 |
module M14 = struct |
| 183 |
type t = (int * int) array_frozen [@@deriving hash] |
| 184 |
end |
| 185 |
|
| 186 |
module M15 = struct |
| 187 |
type t = float array_frozen array_frozen [@@deriving hash] |
| 188 |
end |
| 189 |
|
| 190 |
module M16 = struct |
| 191 |
type t = int list [@@deriving hash] |
| 192 |
end |
| 193 |
|
| 194 |
module M17 = struct |
| 195 |
type t = |
| 196 |
{ s : string |
| 197 |
; b : float array_frozen list |
| 198 |
; mutable c : int * int64 option [@hash.ignore] |
| 199 |
} |
| 200 |
[@@deriving hash] |
| 201 |
end |
| 202 |
|
| 203 |
module M18 = struct |
| 204 |
type t = |
| 205 |
{ a : float |
| 206 |
; b : float |
| 207 |
; c : float |
| 208 |
} |
| 209 |
[@@deriving hash] |
| 210 |
end |
| 211 |
|
| 212 |
module M19 = struct |
| 213 |
type t = Foo [@@deriving hash] |
| 214 |
end |
| 215 |
|
| 216 |
module M20 = struct |
| 217 |
type t = Foo of int [@@deriving hash] |
| 218 |
end |
| 219 |
|
| 220 |
module M21 = struct |
| 221 |
type t = Foo of int * float [@@deriving hash] |
| 222 |
end |
| 223 |
|
| 224 |
module M22 = struct |
| 225 |
type t = |
| 226 |
| Foo |
| 227 |
| Bar of int |
| 228 |
| Baz of string option |
| 229 |
[@@deriving hash] |
| 230 |
end |
| 231 |
|
| 232 |
module M23 = struct |
| 233 |
type t = |
| 234 |
[ `Foo |
| 235 |
| `Bar of string * string |
| 236 |
] |
| 237 |
[@@deriving hash] |
| 238 |
end |
| 239 |
|
| 240 |
module M24 = struct |
| 241 |
type t = int * string * [ `Foo | `Bar ] [@@deriving hash] |
| 242 |
end |
| 243 |
|
| 244 |
module M25 = struct |
| 245 |
type t = String.t [@@deriving hash] |
| 246 |
end |
| 247 |
|
| 248 |
module M26 = struct |
| 249 |
type 'a t = 'a array_frozen [@@deriving hash] |
| 250 |
end |
| 251 |
|
| 252 |
module MyList = struct |
| 253 |
type 'a t = |
| 254 |
| Nil |
| 255 |
| Node of 'a * 'a t |
| 256 |
[@@deriving hash] |
| 257 |
end |
| 258 |
|
| 259 |
module M27 = struct |
| 260 |
type t = int [@@deriving hash] |
| 261 |
|
| 262 |
module Inner = struct |
| 263 |
type nonrec t = t list [@@deriving hash] |
| 264 |
end |
| 265 |
end |
| 266 |
|
| 267 |
module M28 = struct |
| 268 |
|
| 269 |
type ('a, 'b) t = ('a * 'b) list [@@deriving hash] |
| 270 |
|
| 271 |
let _ = [%hash_fold: (int, float) t] (Hash.create ()) [ 1, nan ] |
| 272 |
end |
| 273 |
|
| 274 |
module Polyrec = struct |
| 275 |
type ('a, 'b) t = T of ('a option, 'b) t [@@deriving hash] |
| 276 |
|
| 277 |
type ('a, 'b) t1 = T of ('a option, 'b) t2 |
| 278 |
|
| 279 |
and ('a, 'b) t2 = |
| 280 |
| T1 of ('a list, 'b) t1 |
| 281 |
| T2 of ('a, 'b list) t2 |
| 282 |
[@@deriving hash] |
| 283 |
end |
| 284 |
|
| 285 |
module type Variance_sig = sig |
| 286 |
type +'a t [@@deriving hash] |
| 287 |
end |
| 288 |
|
| 289 |
module Variance = struct |
| 290 |
type -'a t [@@deriving hash] |
| 291 |
type (-'a, +'b) u = 'a t * 'b [@@deriving hash] |
| 292 |
end |
| 293 |
|
| 294 |
module Simple_variant_inclusion = struct |
| 295 |
type poly_t = |
| 296 |
[ `Foo of int |
| 297 |
| `Bar |
| 298 |
] |
| 299 |
[@@deriving hash] |
| 300 |
|
| 301 |
type include_poly_t = |
| 302 |
[ poly_t |
| 303 |
| `Blah |
| 304 |
] |
| 305 |
[@@deriving hash] |
| 306 |
end |
| 307 |
|
| 308 |
module Variant_inclusion = struct |
| 309 |
type 'a type1 = [ `T1 of 'a ] [@@deriving hash] |
| 310 |
|
| 311 |
type 'a type2 = |
| 312 |
[ 'a type1 |
| 313 |
| `T2 |
| 314 |
] |
| 315 |
[@@deriving hash] |
| 316 |
|
| 317 |
type 'a type3 = |
| 318 |
[ `T3 |
| 319 |
| 'a type1 |
| 320 |
] |
| 321 |
[@@deriving hash] |
| 322 |
|
| 323 |
type 'a type4 = |
| 324 |
[ 'a type2 |
| 325 |
| `T4 |
| 326 |
| 'a type3 |
| 327 |
] |
| 328 |
[@@deriving hash] |
| 329 |
end |
| 330 |
|
| 331 |
module SigTU = struct |
| 332 |
module A : sig |
| 333 |
type t [@@deriving hash] |
| 334 |
type u [@@deriving hash] |
| 335 |
end = struct |
| 336 |
type t = int [@@deriving hash] |
| 337 |
type u = float [@@deriving hash] |
| 338 |
end |
| 339 |
|
| 340 |
type p = A.t * A.u [@@deriving hash] |
| 341 |
end |
| 342 |
|
| 343 |
module Gadt = struct |
| 344 |
type 'a t = |
| 345 |
| I : int -> int t |
| 346 |
| F : float -> float t |
| 347 |
| R : int t * string t -> bool t |
| 348 |
[@@deriving hash] |
| 349 |
end |
| 350 |
|
| 351 |
module Up_to_polymorphic_variant = struct |
| 352 |
type 'a t = |
| 353 |
| A : [ `A ] t |
| 354 |
| B : [ `B ] t |
| 355 |
| C : [< `A | `B ] t -> [ `C ] t |
| 356 |
| D : [< `A | `B > `A ] t -> [ `C ] t |
| 357 |
[@@deriving hash] |
| 358 |
end |
| 359 |
|
| 360 |
module Clash = struct |
| 361 |
|
| 362 |
type 'hey hey = Hey of 'hey [@@deriving hash] |
| 363 |
type 'hey rigid_hey = Hey of 'hey [@@deriving hash] |
| 364 |
type ('foo, 'rigid_foo) foo = Foo of 'foo [@@deriving hash] |
| 365 |
type 'rigid_bar rigid_rigid_bar = Bar [@@deriving hash] |
| 366 |
end |
| 367 |
|
| 368 |
module Ignoring = struct |
| 369 |
type a = { a : (int[@compare.ignore]) * string } [@@deriving_inline hash] |
| 370 |
|
| 371 |
let _ = fun (_ : a) -> () |
| 372 |
|
| 373 |
let (hash_fold_a : Ppx_hash_lib.Std.Hash.state -> a -> Ppx_hash_lib.Std.Hash.state) = |
| 374 |
fun hsv arg -> |
| 375 |
let hsv = hsv in |
| 376 |
let e0, e1 = arg.a in |
| 377 |
let hsv = |
| 378 |
let _ = e0 in |
| 379 |
hsv |
| 380 |
in |
| 381 |
let hsv = hash_fold_string hsv e1 in |
| 382 |
hsv |
| 383 |
;; |
| 384 |
|
| 385 |
let _ = hash_fold_a |
| 386 |
|
| 387 |
let (hash_a : a -> Ppx_hash_lib.Std.Hash.hash_value) = |
| 388 |
let func arg = |
| 389 |
Ppx_hash_lib.Std.Hash.get_hash_value |
| 390 |
(let hsv = Ppx_hash_lib.Std.Hash.create () in |
| 391 |
hash_fold_a hsv arg) |
| 392 |
in |
| 393 |
fun x -> func x |
| 394 |
;; |
| 395 |
|
| 396 |
let _ = hash_a |
| 397 |
|
| 398 |
[@@@deriving.end] |
| 399 |
|
| 400 |
type b = { b : (int[@hash.ignore]) * string } [@@deriving_inline hash] |
| 401 |
|
| 402 |
let _ = fun (_ : b) -> () |
| 403 |
|
| 404 |
let (hash_fold_b : Ppx_hash_lib.Std.Hash.state -> b -> Ppx_hash_lib.Std.Hash.state) = |
| 405 |
fun hsv arg -> |
| 406 |
let hsv = hsv in |
| 407 |
let e0, e1 = arg.b in |
| 408 |
let hsv = |
| 409 |
let _ = e0 in |
| 410 |
hsv |
| 411 |
in |
| 412 |
let hsv = hash_fold_string hsv e1 in |
| 413 |
hsv |
| 414 |
;; |
| 415 |
|
| 416 |
let _ = hash_fold_b |
| 417 |
|
| 418 |
let (hash_b : b -> Ppx_hash_lib.Std.Hash.hash_value) = |
| 419 |
let func arg = |
| 420 |
Ppx_hash_lib.Std.Hash.get_hash_value |
| 421 |
(let hsv = Ppx_hash_lib.Std.Hash.create () in |
| 422 |
hash_fold_b hsv arg) |
| 423 |
in |
| 424 |
fun x -> func x |
| 425 |
;; |
| 426 |
|
| 427 |
let _ = hash_b |
| 428 |
|
| 429 |
[@@@deriving.end] |
| 430 |
end |
| 431 |
|
| 432 |
module Type_extension = struct |
| 433 |
let _ = ([%hash_fold: int list] : [%hash_fold: int list]) |
| 434 |
let _ = ([%hash: int list] : [%hash: int list]) |
| 435 |
end |
| 436 |
|
| 437 |
module Recursion_with_aliases = struct |
| 438 |
type a = A of c |
| 439 |
and b = a |
| 440 |
and c = b [@@deriving hash] |
| 441 |
end |
| 442 |
|
| 443 |
module Nested_tuples = struct |
| 444 |
type a = int * (string * bool) [@@deriving_inline hash] |
| 445 |
|
| 446 |
let _ = fun (_ : a) -> () |
| 447 |
|
| 448 |
let (hash_fold_a : Ppx_hash_lib.Std.Hash.state -> a -> Ppx_hash_lib.Std.Hash.state) = |
| 449 |
fun hsv arg -> |
| 450 |
let e0, e1 = arg in |
| 451 |
let hsv = hash_fold_int hsv e0 in |
| 452 |
let hsv = |
| 453 |
let e0, e1 = e1 in |
| 454 |
let hsv = hash_fold_string hsv e0 in |
| 455 |
let hsv = hash_fold_bool hsv e1 in |
| 456 |
hsv |
| 457 |
in |
| 458 |
hsv |
| 459 |
;; |
| 460 |
|
| 461 |
let _ = hash_fold_a |
| 462 |
|
| 463 |
let (hash_a : a -> Ppx_hash_lib.Std.Hash.hash_value) = |
| 464 |
let func arg = |
| 465 |
Ppx_hash_lib.Std.Hash.get_hash_value |
| 466 |
(let hsv = Ppx_hash_lib.Std.Hash.create () in |
| 467 |
hash_fold_a hsv arg) |
| 468 |
in |
| 469 |
fun x -> func x |
| 470 |
;; |
| 471 |
|
| 472 |
let _ = hash_a |
| 473 |
|
| 474 |
[@@@deriving.end] |
| 475 |
end |
| 476 |
|
| 477 |
module Wildcard : sig |
| 478 |
type _ transparent = int [@@deriving hash] |
| 479 |
type _ opaque [@@deriving hash] |
| 480 |
end = struct |
| 481 |
type _ transparent = int [@@deriving hash] |
| 482 |
type 'a opaque = 'a option [@@deriving hash] |
| 483 |
end |