Skip to content

Commit afca10e

Browse files
committed
Avoid include of modules
1 parent 06e7bd0 commit afca10e

15 files changed

+32
-34
lines changed

lib/cmd.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ let duplicate kind name x _ =
1515
(name x |> replace_non_breaking_spaces))
1616

1717
let print_diff base next =
18-
List.zip_by
18+
List_ext.zip_by
1919
~duplicate:(duplicate "benchmark" Benchmark.name)
2020
String.compare Benchmark.name base next
2121
|> List.iter @@ fun ((base : Benchmark.t), (next : Benchmark.t)) ->
2222
Printf.printf "%s:\n" base.name;
2323
let zipped =
24-
List.zip_by
24+
List_ext.zip_by
2525
~duplicate:(duplicate "metric" Metric.name)
2626
String.compare Metric.name base.metrics next.metrics
2727
in
@@ -159,7 +159,7 @@ let run ~benchmarks ?(budgetf = 0.025) ?(filters = []) ?(debug = false)
159159
match base_results with
160160
| [] -> Fun.id
161161
| results ->
162-
let (module S) = Set.make String.compare in
162+
let (module S) = Set_ext.make String.compare in
163163
let names = results |> List.map Benchmark.name |> S.of_list in
164164
List.filter (fun (name, _) -> S.mem name names)
165165
end

lib/countdown.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ let non_atomic_set t count =
3838

3939
let rec get t count i =
4040
if i < Array.length t && Array.unsafe_get t i != Array.unsafe_get t 0 then
41-
get t (count + Int.max 0 (Atomic.get (Array.unsafe_get t i))) (i + 1)
41+
get t (count + Int_ext.max 0 (Atomic.get (Array.unsafe_get t i))) (i + 1)
4242
else count
4343

44-
let[@inline] get t = get t (Int.max 0 (Atomic.get (Array.unsafe_get t 0))) 1
44+
let[@inline] get t = get t (Int_ext.max 0 (Atomic.get (Array.unsafe_get t 0))) 1
4545

4646
let rec alloc t ~batch i =
4747
if i < Array.length t then
4848
let c = Array.unsafe_get t i in
4949
if 0 < Atomic.get c then
5050
let n = Atomic.fetch_and_add c (-batch) in
51-
if 0 < n then Int.min n batch else alloc t ~batch (i + 1)
51+
if 0 < n then Int_ext.min n batch else alloc t ~batch (i + 1)
5252
else alloc t ~batch (i + 1)
5353
else 0
5454

5555
let[@inline] alloc t ~domain_index ~batch =
5656
let c = Array.unsafe_get t domain_index in
5757
if 0 < Atomic.get c then
5858
let n = Atomic.fetch_and_add c (-batch) in
59-
if 0 < n then Int.min n batch else alloc t ~batch 0
59+
if 0 < n then Int_ext.min n batch else alloc t ~batch 0
6060
else alloc t ~batch 0

lib/data.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Option.Syntax
1+
open Option_ext.Syntax
22

33
module Trend = struct
44
type t = [ `Lower_is_better | `Higher_is_better ]

lib/dune

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ let () =
1111
(enabled_if
1212
(< %{ocaml_version} 4.13.0))
1313
(action
14-
(copy int.ocaml_4_12.ml int.ml)))
14+
(copy int_ext.ocaml_lt_4_13.ml int_ext.ml)))
15+
16+
(rule
17+
(enabled_if
18+
(>= %{ocaml_version} 4.13.0))
19+
(action
20+
(copy int_ext.ocaml_ge_4_13.ml int_ext.ml)))
1521

1622
(library
1723
(public_name multicore-bench)

lib/int.ocaml_4_12.ml

-4
This file was deleted.

lib/int_ext.ocaml_ge_4_13.ml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let min = Int.min
2+
let max = Int.max

lib/int_ext.ocaml_lt_4_13.ml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let min (x : int) (y : int) = if x < y then x else y
2+
let max (x : int) (y : int) = if x < y then y else x

lib/json.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Option.Syntax
1+
open Option_ext.Syntax
22

33
type t = Yojson.Safe.t
44

lib/list.ml renamed to lib/list_ext.ml

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
include Stdlib.List
2-
31
let default_duplicate _ _ = invalid_arg "duplicate key"
42
let default_missing _ _ = None
53

64
let zip_by (type k) ?(duplicate = default_duplicate)
75
?(missing = default_missing) (compare : k -> _) key_of xs ys =
8-
let (module M) = Map.make compare in
6+
let (module M) = Map_ext.make compare in
97
let to_map xs =
108
xs
11-
|> fold_left
9+
|> List.fold_left
1210
(fun m x ->
1311
m
1412
|> M.update (key_of x) @@ function
@@ -24,4 +22,4 @@ let zip_by (type k) ?(duplicate = default_duplicate)
2422
| None, Some y -> missing `L y
2523
| None, None -> None)
2624
(to_map xs) (to_map ys)
27-
|> M.bindings |> map snd
25+
|> M.bindings |> List.map snd
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include Stdlib.Set
2-
31
let make (type t) (compare : t -> _) =
42
let (module Elt) = Ordered.make compare in
5-
(module Make (Elt) : Stdlib.Set.S with type elt = t)
3+
(module Map.Make (Elt) : Map.S with type key = t)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include Stdlib.Option
2-
31
let pair x y = match (x, y) with Some x, Some y -> Some (x, y) | _ -> None
42

53
module Syntax = struct
@@ -10,13 +8,13 @@ module Syntax = struct
108
match r x with None -> None | Some r -> Some Infix_pair.(l :: r)
119
end
1210

13-
let ( let* ) = bind
14-
let ( >>= ) = bind
11+
let ( let* ) = Option.bind
12+
let ( >>= ) = Option.bind
1513
let ( >=> ) f g x = f x >>= g
16-
let ( let+ ) x f = map f x
14+
let ( let+ ) x f = Option.map f x
1715
let ( >>+ ) = ( let+ )
1816
let ( >+> ) f g x = f x >>+ g
19-
let pure = some
17+
let pure = Option.some
2018
let ( and* ) = pair
2119
let ( and+ ) = pair
2220
end

lib/ordered.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ let make (type t) (compare : t -> _) =
33
type nonrec t = t
44

55
let compare = compare
6-
end : Stdlib.Set.OrderedType
6+
end : Set.OrderedType
77
with type t = t)
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include Stdlib.Map
2-
31
let make (type t) (compare : t -> _) =
42
let (module Elt) = Ordered.make compare in
5-
(module Make (Elt) : Stdlib.Map.S with type key = t)
3+
(module Set.Make (Elt) : Set.S with type elt = t)

lib/times.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let record (type a) ~budgetf ~n_domains ?(ensure_multi_domain = true)
6565
wrap;
6666
results =
6767
Array.init n_domains (fun _ ->
68-
Float.Array.create (Int.max n_runs_min n_runs_max));
68+
Float.Array.create (Int_ext.max n_runs_min n_runs_max));
6969
budget_start = Mtime_clock.elapsed ();
7070
before;
7171
init;

lib/util.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let rec alloc ?(batch = 1000) counter =
88
let n = Atomic.get counter in
99
if n = 0 then 0
1010
else
11-
let batch = Int.min n batch in
11+
let batch = Int_ext.min n batch in
1212
if Atomic.compare_and_set counter n (n - batch) then batch
1313
else alloc ~batch counter
1414

0 commit comments

Comments
 (0)