Skip to content

Commit 01857ea

Browse files
v0.18~preview.130.33+516
1 parent aec61ab commit 01857ea

File tree

125 files changed

+2547
-1614
lines changed

Some content is hidden

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

125 files changed

+2547
-1614
lines changed

composition_infix/src/composition_infix.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
- [ a |> (f >> g) = a |> f |> g ]
44
- [ (f << g) a = f (g a) ] *)
55

6-
val ( >> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
7-
val ( << ) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c
6+
val ( >> ) : 'a 'b 'c. ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
7+
val ( << ) : 'a 'b 'c. ('b -> 'c) -> ('a -> 'b) -> 'a -> 'c

md5/src/md5_lib.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type t = string
44
let empty = Digest.string ""
55
let make s = if s = empty then empty else s
66
let make_local s = if s = empty then empty else s
7+
let compare__local = compare
78
let compare = compare
89
let length = 16
910
let to_binary s = s
@@ -16,6 +17,7 @@ let of_binary_exn s =
1617

1718
let unsafe_of_binary = make
1819
let unsafe_of_binary_local = make_local
20+
let unsafe_of_binary__local = make_local
1921

2022
external globalize : t -> t = "caml_obj_dup"
2123

md5/src/md5_lib.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
type t
22

33
val compare : t -> t -> int
4+
val compare__local : t -> t -> int
45

56
(** [length = 16] is the size of the digest in bytes. *)
67
val length : int
@@ -13,6 +14,7 @@ val of_binary_exn : string -> t
1314
val unsafe_of_binary : string -> t
1415

1516
val unsafe_of_binary_local : string -> t
17+
val unsafe_of_binary__local : string -> t
1618
val globalize : t -> t
1719
val to_hex : t -> string
1820
val of_hex_exn : string -> t

src/array.ml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ include Array_intf.Definitions
33
include Array0
44

55
type 'a t = 'a array
6-
[@@deriving compare ~localize, globalize, sexp ~localize, sexp_grammar]
76

8-
[@@@warning "-incompatible-with-upstream"]
7+
[%%rederive.portable
8+
type nonrec 'a t = 'a array
9+
[@@deriving compare ~localize, globalize, sexp ~localize, sexp_grammar]]
910

1011
(* This module implements a new in-place, constant heap sorting algorithm to replace the
1112
one used by the standard libraries. Its only purpose is to be faster (hopefully
@@ -415,6 +416,21 @@ let foldi t ~init ~f =
415416
!acc
416417
;;
417418

419+
let%template foldi_right t ~init ~f =
420+
(let rec aux t ~idx ~acc ~f =
421+
(if idx < 0
422+
then acc
423+
else (
424+
(* [unsafe_get] is safe, since [idx >= 0 && idx < Array.length t] *)
425+
let acc = f idx (unsafe_get t idx) acc in
426+
aux t ~idx:(idx - 1) ~acc ~f))
427+
[@exclave_if_stack a]
428+
in
429+
aux t ~idx:(length t - 1) ~acc:init ~f [@nontail])
430+
[@exclave_if_stack a]
431+
[@@alloc a @ m = (stack_local, heap_global)]
432+
;;
433+
418434
let folding_mapi t ~init ~f =
419435
let acc = ref init in
420436
mapi t ~f:(fun i x ->

src/array0.ml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,40 @@ module Sys = Sys0
1414
let invalid_argf = Printf.invalid_argf
1515

1616
module Array = struct
17-
external create : int -> 'a -> 'a array = "caml_make_vect"
18-
external create_local : int -> 'a -> 'a array = "caml_make_vect"
17+
[%%template
18+
external create : len:int -> 'a -> 'a array = "caml_make_vect"
19+
[@@alloc __ = (heap, stack)]]
20+
21+
let create_local = create
22+
let magic_create_uninitialized ~len = create ~len (Stdlib.Obj.magic 0)
23+
1924
external create_float_uninitialized : int -> float array = "caml_make_float_vect"
20-
external get : ('a array[@local_opt]) -> (int[@local_opt]) -> 'a = "%array_safe_get"
21-
external length : ('a array[@local_opt]) -> int = "%array_length"
25+
26+
external%template get
27+
: 'a.
28+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a
29+
= "%array_safe_get"
30+
[@@layout_poly] [@@mode m = (uncontended, shared)]
31+
32+
external length : 'a. ('a array[@local_opt]) -> int = "%array_length" [@@layout_poly]
2233

2334
external set
24-
: ('a array[@local_opt])
25-
-> (int[@local_opt])
26-
-> 'a
27-
-> unit
35+
: 'a.
36+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a -> unit
2837
= "%array_safe_set"
38+
[@@layout_poly]
2939

30-
external unsafe_get
31-
: ('a array[@local_opt])
32-
-> (int[@local_opt])
33-
-> 'a
40+
external%template unsafe_get
41+
: 'a.
42+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a
3443
= "%array_unsafe_get"
44+
[@@mode m = (uncontended, shared)] [@@layout_poly]
3545

3646
external unsafe_set
37-
: ('a array[@local_opt])
38-
-> (int[@local_opt])
39-
-> 'a
40-
-> unit
47+
: 'a.
48+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a -> unit
4149
= "%array_unsafe_set"
50+
[@@layout_poly]
4251

4352
external unsafe_blit
4453
: src:('a array[@local_opt])
@@ -58,16 +67,6 @@ include Array
5867

5968
let max_length = Sys.max_array_length
6069

61-
let create ~len x =
62-
try create len x with
63-
| Invalid_argument _ -> invalid_argf "Array.create ~len:%d: invalid length" len ()
64-
;;
65-
66-
let create_local ~len x =
67-
try create_local len x with
68-
| Invalid_argument _ -> invalid_argf "Array.create_local ~len:%d: invalid length" len ()
69-
;;
70-
7170
let create_float_uninitialized ~len =
7271
try create_float_uninitialized len with
7372
| Invalid_argument _ ->
@@ -126,12 +125,13 @@ let fold t ~init ~(f : _ -> _ -> _) =
126125
!r
127126
;;
128127

129-
let fold_right t ~(f : _ -> _ -> _) ~init =
128+
let%template fold_right t ~(f : _ -> _ -> _) ~init =
130129
let r = ref init in
131130
for i = length t - 1 downto 0 do
132-
r := f (unsafe_get t i) !r
131+
r := f ((unsafe_get [@mode m]) t i) !r
133132
done;
134133
!r
134+
[@@mode m = (uncontended, shared)]
135135
;;
136136

137137
let iter t ~(f : _ -> _) =

src/array_intf.ml

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
open! Import
44

5-
[@@@warning "-incompatible-with-upstream"]
6-
75
module Definitions = struct
86
module type Public = sig
97
type 'a t
10-
[@@deriving
11-
compare ~localize, equal ~localize, globalize, sexp ~localize, sexp_grammar]
8+
9+
[%%rederive:
10+
type nonrec 'a t = 'a t
11+
[@@deriving
12+
compare ~localize, equal ~localize, globalize, sexp ~localize, sexp_grammar]]
1213

1314
include Binary_searchable.S1 with type 'a t := 'a t
1415
include Indexed_container.S1_with_creators with type 'a t := 'a t
@@ -18,55 +19,63 @@ module Definitions = struct
1819
[max_length/2] on 32-bit machines and [max_length] on 64-bit machines. *)
1920
val max_length : int
2021

21-
(*_ Declared as externals so that the compiler skips the caml_apply_X wrapping even when
22-
compiling without cross library inlining. *)
22+
(*_ Declared as externals so that the compiler skips the caml_apply_X wrapping even
23+
when compiling without cross library inlining. *)
2324

24-
external length : ('a t[@local_opt]) -> int = "%array_length"
25+
external length : 'a. ('a array[@local_opt]) -> int = "%array_length" [@@layout_poly]
2526

2627
(** [Array.get a n] returns the element number [n] of array [a]. The first element has
2728
number 0. The last element has number [Array.length a - 1]. You can also write
2829
[a.(n)] instead of [Array.get a n].
2930
3031
Raise [Invalid_argument "index out of bounds"] if [n] is outside the range 0 to
3132
[(Array.length a - 1)]. *)
32-
external get : ('a t[@local_opt]) -> (int[@local_opt]) -> 'a = "%array_safe_get"
33+
external%template get
34+
: 'a.
35+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a
36+
= "%array_safe_get"
37+
[@@layout_poly] [@@mode m = (uncontended, shared)]
3338

3439
(** [Array.set a n x] modifies array [a] in place, replacing element number [n] with
3540
[x]. You can also write [a.(n) <- x] instead of [Array.set a n x].
3641
3742
Raise [Invalid_argument "index out of bounds"] if [n] is outside the range 0 to
3843
[Array.length a - 1]. *)
3944
external set
40-
: ('a t[@local_opt])
41-
-> (int[@local_opt])
42-
-> 'a
43-
-> unit
45+
: 'a.
46+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a -> unit
4447
= "%array_safe_set"
48+
[@@layout_poly]
4549

4650
(** Unsafe version of [get]. Can cause arbitrary behavior when used for an
4751
out-of-bounds array access. *)
48-
external unsafe_get
49-
: ('a t[@local_opt])
50-
-> (int[@local_opt])
51-
-> 'a
52+
external%template unsafe_get
53+
: 'a.
54+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a
5255
= "%array_unsafe_get"
56+
[@@layout_poly] [@@mode m = (uncontended, shared)]
5357

5458
(** Unsafe version of [set]. Can cause arbitrary behavior when used for an
5559
out-of-bounds array access. *)
5660
external unsafe_set
57-
: ('a t[@local_opt])
58-
-> (int[@local_opt])
59-
-> 'a
60-
-> unit
61+
: 'a.
62+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a -> unit
6163
= "%array_unsafe_set"
64+
[@@layout_poly]
6265

63-
(** [create ~len x] creates an array of length [len] with the value [x] populated in
64-
each element. *)
65-
val create : len:int -> 'a -> 'a t
66+
[%%template:
67+
val create : len:int -> 'a -> 'a array
68+
[@@ocaml.doc
69+
" [create ~len x] creates an array of length [len] with the value [x] populated in\n\
70+
\ each element. "]
71+
[@@alloc __ = (heap, stack)]]
6672

67-
(** [create_local ~len x] is like [create]. It allocates the array on the local stack.
68-
The array's elements are still global. *)
69-
val create_local : len:int -> 'a -> 'a t
73+
val create_local : len:int -> 'a -> 'a array
74+
75+
val magic_create_uninitialized : len:int -> 'a array
76+
[@@ocaml.doc
77+
" [magic_create_uninitialized ~len] creates an array of length [len]. All elements\n\
78+
\ are magically populated as a tagged [0]. "]
7079

7180
(** [create_float_uninitialized ~len] creates a float array of length [len] with
7281
uninitialized elements -- that is, they may contain arbitrary, nondeterministic
@@ -116,6 +125,9 @@ module Definitions = struct
116125
types. The unsafe versions do not bound-check the arguments. *)
117126
include Blit.S1 with type 'a t := 'a t
118127

128+
val%template foldi_right : 'a t -> init:'acc -> f:(int -> 'a -> 'acc -> 'acc) -> 'acc
129+
[@@alloc a @ m = (stack_local, heap_global)]
130+
119131
(** [folding_map] is a version of [map] that threads an accumulator through calls to
120132
[f]. *)
121133
val folding_map : 'a t -> init:'acc -> f:('acc -> 'a -> 'acc * 'b) -> 'b t
@@ -131,7 +143,8 @@ module Definitions = struct
131143
(** [Array.fold_right f a ~init] computes
132144
[f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...))], where [n] is the length of the
133145
array [a]. *)
134-
val fold_right : 'a t -> f:('a -> 'acc -> 'acc) -> init:'acc -> 'acc
146+
val%template fold_right : 'a t -> f:('a -> 'acc -> 'acc) -> init:'acc -> 'acc
147+
[@@mode m = (uncontended, shared)]
135148

136149
(** All sort functions in this module sort in increasing order by default. *)
137150

src/atomic.ml

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)