2
2
3
3
open ! Import
4
4
5
- [@@@ warning " -incompatible-with-upstream" ]
6
-
7
5
module Definitions = struct
8
6
module type Public = sig
9
7
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 ]]
12
13
13
14
include Binary_searchable. S1 with type 'a t := 'a t
14
15
include Indexed_container. S1_with_creators with type 'a t := 'a t
@@ -18,55 +19,63 @@ module Definitions = struct
18
19
[max_length/2] on 32-bit machines and [max_length] on 64-bit machines. *)
19
20
val max_length : int
20
21
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. *)
23
24
24
- external length : ('a t [@ local_opt]) -> int = " %array_length"
25
+ external length : 'a . ('a array [@ local_opt]) -> int = " %array_length" [ @@ layout_poly]
25
26
26
27
(* * [Array.get a n] returns the element number [n] of array [a]. The first element has
27
28
number 0. The last element has number [Array.length a - 1]. You can also write
28
29
[a.(n)] instead of [Array.get a n].
29
30
30
31
Raise [Invalid_argument "index out of bounds"] if [n] is outside the range 0 to
31
32
[(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)]
33
38
34
39
(* * [Array.set a n x] modifies array [a] in place, replacing element number [n] with
35
40
[x]. You can also write [a.(n) <- x] instead of [Array.set a n x].
36
41
37
42
Raise [Invalid_argument "index out of bounds"] if [n] is outside the range 0 to
38
43
[Array.length a - 1]. *)
39
44
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
44
47
= " %array_safe_set"
48
+ [@@ layout_poly]
45
49
46
50
(* * Unsafe version of [get]. Can cause arbitrary behavior when used for an
47
51
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
52
55
= " %array_unsafe_get"
56
+ [@@ layout_poly] [@@ mode m = (uncontended, shared)]
53
57
54
58
(* * Unsafe version of [set]. Can cause arbitrary behavior when used for an
55
59
out-of-bounds array access. *)
56
60
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
61
63
= " %array_unsafe_set"
64
+ [@@ layout_poly]
62
65
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 )]]
66
72
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]. " ]
70
79
71
80
(* * [create_float_uninitialized ~len] creates a float array of length [len] with
72
81
uninitialized elements -- that is, they may contain arbitrary, nondeterministic
@@ -116,6 +125,9 @@ module Definitions = struct
116
125
types. The unsafe versions do not bound-check the arguments. *)
117
126
include Blit. S1 with type 'a t := 'a t
118
127
128
+ val% template foldi_right : 'a t -> init:'acc -> f:(int -> 'a -> 'acc -> 'acc) -> 'acc
129
+ [@@ alloc a @ m = (stack_local, heap_global)]
130
+
119
131
(* * [folding_map] is a version of [map] that threads an accumulator through calls to
120
132
[f]. *)
121
133
val folding_map : 'a t -> init :'acc -> f :('acc -> 'a -> 'acc * 'b ) -> 'b t
@@ -131,7 +143,8 @@ module Definitions = struct
131
143
(* * [Array.fold_right f a ~init] computes
132
144
[f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...))], where [n] is the length of the
133
145
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)]
135
148
136
149
(* * All sort functions in this module sort in increasing order by default. *)
137
150
0 commit comments