forked from janestreet/base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
178 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
_build | ||
*.install | ||
*.merlin | ||
_opam | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#+TITLE: Base_internalhash_types | ||
|
||
This micro-library allows hash states, seeds, and values to be type-equal | ||
between ~Base~ and ~Base_boot~. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(** [state] is defined as a subtype of [int] using the [private] keyword. This makes it an | ||
opaque type for most purposes, and tells the compiler that the type is immediate. *) | ||
type state = private int | ||
type seed = int | ||
type hash_value = int | ||
|
||
external create_seeded : seed -> state = "%identity" [@@noalloc] | ||
external fold_int64 : state -> int64 -> state = "Base_internalhash_fold_int64" [@@noalloc] | ||
external fold_int : state -> int -> state = "Base_internalhash_fold_int" [@@noalloc] | ||
external fold_float : state -> float -> state = "Base_internalhash_fold_float" [@@noalloc] | ||
external fold_string : state -> string -> state = "Base_internalhash_fold_string" [@@noalloc] | ||
external get_hash_value : state -> hash_value = "Base_internalhash_get_hash_value" [@@noalloc] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(library (name base_internalhash_types) | ||
(public_name base.base_internalhash_types) (libraries) | ||
(preprocess no_preprocessing) (js_of_ocaml (javascript_files runtime.js)) | ||
(c_names internalhash_stubs) (install_c_headers internalhash)) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//Provides: Base_internalhash_fold_int64 | ||
//Requires: caml_hash_mix_int64 | ||
var Base_internalhash_fold_int64 = caml_hash_mix_int64; | ||
//Provides: Base_internalhash_fold_int | ||
//Requires: caml_hash_mix_int | ||
var Base_internalhash_fold_int = caml_hash_mix_int; | ||
//Provides: Base_internalhash_fold_float | ||
//Requires: caml_hash_mix_float | ||
var Base_internalhash_fold_float = caml_hash_mix_float; | ||
//Provides: Base_internalhash_fold_string | ||
//Requires: caml_hash_mix_string | ||
var Base_internalhash_fold_string = caml_hash_mix_string; | ||
//Provides: Base_internalhash_get_hash_value | ||
//Requires: caml_hash_mix_final | ||
function Base_internalhash_get_hash_value(seed) { | ||
var h = caml_hash_mix_final(seed); | ||
return h & 0x3FFFFFFF; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(library (name base_internalhash_types_test) | ||
(libraries base base_boot expect_test_helpers_kernel | ||
replace_caml_modify_for_testing stdio) | ||
(preprocess (pps ppx_jane))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include Stdio | ||
include Expect_test_helpers_kernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
open! Base | ||
open! Import | ||
|
||
let%expect_test "[Base.Hash.state] is still immediate" = | ||
require_no_allocation [%here] (fun () -> | ||
ignore (Sys.opaque_identity (Base.Hash.create ()))); | ||
[%expect {| |}] | ||
|
||
let%expect_test "[Base_boot.Hash.state] is still immediate" = | ||
require_no_allocation [%here] (fun () -> | ||
ignore (Sys.opaque_identity (Base_boot.Hash.create ()))); | ||
[%expect {| |}] | ||
|
||
type t = { mutable state : Base.Hash.state; mutable list : unit list } | ||
|
||
let%expect_test _ = | ||
let count_caml_modify f = | ||
Replace_caml_modify_for_testing.reset (); | ||
f (); | ||
print_s [%sexp (Replace_caml_modify_for_testing.count () : int)]; | ||
in | ||
let t = { state = Base.Hash.create ~seed:1 (); list = [] } in | ||
let list = [ (); () ] (* not an immediate type, requires caml_modify *) in | ||
count_caml_modify (fun () -> t.list <- list); | ||
[%expect {| 1 |}]; | ||
let state = Base.Hash.create ~seed:2 () (* immediate, I hope *) in | ||
count_caml_modify (fun () -> t.state <- state); | ||
[%expect {| 0 |}]; | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(*_ This signature is deliberately empty. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
open! Base | ||
open! Import | ||
|
||
let%expect_test "[Base.Hash.state] unifies with [Base_boot.Hash.state]" = | ||
let _f (state : Base.Hash.state) : Base_boot.Hash.state = state in | ||
[%expect {| |}] | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(*_ This signature is deliberately empty. *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters